当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.WaiterError方法代码示例

本文整理汇总了Python中botocore.exceptions.WaiterError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.WaiterError方法的具体用法?Python exceptions.WaiterError怎么用?Python exceptions.WaiterError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在botocore.exceptions的用法示例。


在下文中一共展示了exceptions.WaiterError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: retry

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def retry(function, *args, **kwargs):
    """ Retries a function up to max_retries, waiting `timeout` seconds between tries.
        This function is designed to retry both boto3 and fabric calls.  In the
        case of boto3, it is necessary because sometimes aws calls return too
        early and a resource needed by the next call is not yet available. """
    max_retries = kwargs.pop("max_retries", 10)
    timeout = kwargs.pop("timeout", 3)
    for i in range(max_retries):
        print (".", sys.stdout.flush())
        try:
            return function(*args, **kwargs)
        except (ClientError, NetworkError, WaiterError) as e:
            logger.debug("retrying %s, (~%s seconds elapsed)" % (function, i * 3))
            sleep(timeout)
    logger.error("hit max retries on %s" % function)
    raise e

#####################################################################################################################
#################################################### MAIN ###########################################################
##################################################################################################################### 
开发者ID:harvard,项目名称:cloudJHub,代码行数:22,代码来源:launch.py

示例2: retry

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def retry(function, *args, **kwargs):
    """ Retries a function up to max_retries, waiting `timeout` seconds between tries.
        This function is designed to retry both boto3 and fabric calls.  In the
        case of boto3, it is necessary because sometimes aws calls return too
        early and a resource needed by the next call is not yet available. """
    max_retries = kwargs.pop("max_retries", 10)
    timeout = kwargs.pop("timeout", 1)
    for attempt in range(max_retries):
        try:
            ret = yield thread_pool.submit(function, *args, **kwargs)
            return ret
        except (ClientError, WaiterError, NetworkError, RemoteCmdExecutionError, EOFError, SSHException, ChannelException) as e:
            #EOFError can occur in fabric
            logger.error("Failure in %s with args %s and kwargs %s" % (function.__name__, args, kwargs))
            logger.info("retrying %s, (~%s seconds elapsed)" % (function.__name__, attempt * 3))
            yield gen.sleep(timeout)
    else:
        logger.error("Failure in %s with args %s and kwargs %s" % (function.__name__, args, kwargs))
        yield gen.sleep(0.1) #this line exists to allow the logger time to print
        return ("RETRY_FAILED")

#########################################################################################################
######################################################################################################### 
开发者ID:harvard,项目名称:cloudJHub,代码行数:25,代码来源:spawner.py

示例3: retry

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def retry(function, *args, **kwargs):
    """ Retries a function up to max_retries, waiting `timeout` seconds between tries.
        This function is designed to retry both boto3 and fabric calls.  In the
        case of boto3, it is necessary because sometimes aws calls return too
        early and a resource needed by the next call is not yet available. """
    max_retries = kwargs.pop("max_retries", 20)
    timeout = kwargs.pop("timeout", 0.25)
    for attempt in range(max_retries):
        try:
            ret = yield thread_pool.submit(function, *args, **kwargs)
            return ret
        except (ClientError, WaiterError) as e:
            app_log.warn("encountered %s, waiting for %s seconds before retrying..." % (type(e), timeout) )
            yield sleep(timeout)
    else:
         print("Failure in %s with args %s and kwargs %s" % (function.__name__, args, kwargs))
         #raise e 
开发者ID:harvard,项目名称:cloudJHub,代码行数:19,代码来源:cull_idle_servers.py

示例4: _wait_for_stack

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def _wait_for_stack(self, stack_id, waiter_name, success_msg):
        waiter = self.cfn_client.get_waiter(waiter_name)
        LOG.debug("Waiting for stack '%s'", stack_id)
        try:
            waiter.wait(
                StackName=stack_id, WaiterConfig={"Delay": 5, "MaxAttempts": 200}
            )
        except WaiterError as e:
            LOG.debug("Waiter failed for stack '%s'", stack_id, exc_info=e)
            LOG.critical(
                "Failed to create or update the '%s' stack. "
                "This stack is in your account, so you may be able to self-help by "
                "looking at '%s'. Otherwise, please reach out to CloudFormation.",
                stack_id,
                stack_id,
            )
            raise UploadError(
                "Failed to create or update the '{}' stack".format(stack_id)
            ) from e

        LOG.info(success_msg) 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:23,代码来源:upload.py

示例5: test__wait_for_registration_waiter_fails

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test__wait_for_registration_waiter_fails(project):
    mock_cfn_client = MagicMock(
        spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
    )
    mock_cfn_client.describe_type_registration.return_value = (
        DESCRIBE_TYPE_FAILED_RETURN
    )
    mock_waiter = MagicMock(spec=["wait"])
    mock_waiter.wait.side_effect = WaiterError(
        "TypeRegistrationComplete",
        "Waiter encountered a terminal failure state",
        DESCRIBE_TYPE_FAILED_RETURN,
    )
    mock_cfn_client.get_waiter.return_value = mock_waiter

    with pytest.raises(DownstreamError):
        project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, True)

    mock_cfn_client.describe_type_registration.assert_called_once_with(
        RegistrationToken=REGISTRATION_TOKEN
    )
    mock_cfn_client.set_type_default_version.assert_not_called()
    mock_waiter.wait.assert_called_once_with(RegistrationToken=REGISTRATION_TOKEN) 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:25,代码来源:test_project.py

示例6: test__wait_for_registration_waiter_fails_describe_fails

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test__wait_for_registration_waiter_fails_describe_fails(project):
    mock_cfn_client = MagicMock(
        spec=["describe_type_registration", "set_type_default_version", "get_waiter"]
    )
    mock_cfn_client.describe_type_registration.side_effect = ClientError(
        BLANK_CLIENT_ERROR, "DescribeTypeRegistration"
    )
    mock_waiter = MagicMock(spec=["wait"])
    mock_waiter.wait.side_effect = WaiterError(
        "TypeRegistrationComplete",
        "Waiter encountered a terminal failure state",
        DESCRIBE_TYPE_FAILED_RETURN,
    )

    mock_cfn_client.get_waiter.return_value = mock_waiter

    with pytest.raises(DownstreamError):
        project._wait_for_registration(mock_cfn_client, REGISTRATION_TOKEN, False)

    mock_cfn_client.describe_type_registration.assert_called_once_with(
        RegistrationToken=REGISTRATION_TOKEN
    )
    mock_cfn_client.set_type_default_version.assert_not_called()
    mock_waiter.wait.assert_called_once_with(RegistrationToken=REGISTRATION_TOKEN) 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:26,代码来源:test_project.py

示例7: retry_on_rate_limiting

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def retry_on_rate_limiting(e: Exception):
    """ Returns 'True' if a rate limiting error occurs and raises the exception otherwise
    """
    if isinstance(e, ClientError):
        error_code = e.response['Error']['Code']
    elif isinstance(e, WaiterError):
        error_code = e.last_response['Error']['Code']
    else:
        raise e
    if error_code in ['Throttling', 'RequestLimitExceeded']:
        log.warning('AWS API Limiting error: {}'.format(error_code))
        return True
    raise e 
开发者ID:dcos,项目名称:dcos-launch,代码行数:15,代码来源:aws.py

示例8: key_exists

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def key_exists(self, bucket_name, key_name, min_successes=3):
        try:
            self.wait_until_key_exists(
                    bucket_name, key_name, min_successes=min_successes)
            return True
        except (ClientError, WaiterError):
            return False 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:9,代码来源:testutils.py

示例9: key_not_exists

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def key_not_exists(self, bucket_name, key_name, min_successes=3):
        try:
            self.wait_until_key_not_exists(
                    bucket_name, key_name, min_successes=min_successes)
            return True
        except (ClientError, WaiterError):
            return False 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:9,代码来源:testutils.py

示例10: validate_and_find_master_dns

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def validate_and_find_master_dns(session, parsed_globals, cluster_id):
    """
    Utility method for ssh, socks, put and get command.
    Check if the cluster to be connected to is
     terminated or being terminated.
    Check if the cluster is running.
    Find master instance public dns of a given cluster.
    Return the latest created master instance public dns name.
    Throw MasterDNSNotAvailableError or ClusterTerminatedError.
    """
    cluster_state = emrutils.get_cluster_state(
        session, parsed_globals, cluster_id)

    if cluster_state in constants.TERMINATED_STATES:
        raise exceptions.ClusterTerminatedError

    emr = emrutils.get_client(session, parsed_globals)

    try:
        cluster_running_waiter = emr.get_waiter('cluster_running')
        if cluster_state in constants.STARTING_STATES:
            print("Waiting for the cluster to start.")
        cluster_running_waiter.wait(ClusterId=cluster_id)
    except WaiterError:
        raise exceptions.MasterDNSNotAvailableError

    return emrutils.find_master_dns(
        session=session, cluster_id=cluster_id,
        parsed_globals=parsed_globals) 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:31,代码来源:sshutils.py

示例11: create_or_update_stack

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def create_or_update_stack(self, managed_policy_arns: list, output: AbstractOutputWriter):
        """Creates or updates an instance profile.
        It was moved to a separate stack because creating of an instance profile resource takes 2 minutes.
        """
        # check that policies exist
        iam = boto3.client('iam', region_name=self._region)
        for policy_arn in managed_policy_arns:
            # if the policy doesn't exist, an error will be raised
            iam.get_policy(PolicyArn=policy_arn)

        template = prepare_instance_profile_template(managed_policy_arns)

        stack = Stack.get_by_name(self._cf, self._stack_name)
        try:
            if stack:
                # update the stack and wait until it will be updated
                self._update_stack(template, output)
            else:
                # create the stack and wait until it will be created
                self._create_stack(template, output)

            stack = Stack.get_by_name(self._cf, self._stack_name)
        except WaiterError:
            stack = None

        if not stack or stack.status not in ['CREATE_COMPLETE', 'UPDATE_COMPLETE']:
            raise ValueError('Stack "%s" was not created.\n'
                             'Please, see CloudFormation logs for the details.' % self._stack_name)

        profile_arn = [row['OutputValue'] for row in stack.outputs if row['OutputKey'] == 'ProfileArn'][0]

        return profile_arn 
开发者ID:apls777,项目名称:spotty,代码行数:34,代码来源:instance_profile_stack.py

示例12: test_prints_error_message_for_failed_submit_and_exits

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test_prints_error_message_for_failed_submit_and_exits(capsys, logger):
    cf_client_mock = Mock()
    change_set = ChangeSet(STACK, cf_client_mock)

    error = WaiterError('name', 'reason', {'StatusReason': 'StatusReason'})
    cf_client_mock.get_waiter.return_value.wait.side_effect = error

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        change_set.create(template=TEMPLATE, change_set_type=CHANGE_SET_TYPE)
    logger.info.assert_called_with('StatusReason')
    assert pytest_wrapped_e.value.code == 1 
开发者ID:theserverlessway,项目名称:formica,代码行数:13,代码来源:test_change_set.py

示例13: test_prints_error_message_and_does_not_fail_without_StatusReason

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test_prints_error_message_and_does_not_fail_without_StatusReason(capsys, logger):
    cf_client_mock = Mock()
    change_set = ChangeSet(STACK, cf_client_mock)

    error = WaiterError('name', 'reason', {})
    cf_client_mock.get_waiter.return_value.wait.side_effect = error

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        change_set.create(template=TEMPLATE, change_set_type=CHANGE_SET_TYPE)
    logger.info.assert_called()
    assert pytest_wrapped_e.value.code == 1 
开发者ID:theserverlessway,项目名称:formica,代码行数:13,代码来源:test_change_set.py

示例14: test_prints_error_message_but_exits_successfully_for_no_changes

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test_prints_error_message_but_exits_successfully_for_no_changes(capsys, logger, mocker):
    cf_client_mock = Mock()
    change_set = ChangeSet(STACK, cf_client_mock)
    status_reason = "The submitted information didn't contain changes. " \
                    "Submit different information to create a change set."

    error = WaiterError('name', 'reason', {'StatusReason': status_reason})
    cf_client_mock.get_waiter.return_value.wait.side_effect = error

    change_set.create(template=TEMPLATE, change_set_type=CHANGE_SET_TYPE)
    logger.info.assert_called_with(status_reason) 
开发者ID:theserverlessway,项目名称:formica,代码行数:13,代码来源:test_change_set.py

示例15: test__wait_for_stack_failure

# 需要导入模块: from botocore import exceptions [as 别名]
# 或者: from botocore.exceptions import WaiterError [as 别名]
def test__wait_for_stack_failure(uploader):
    e = WaiterError(
        name="StackCreateComplete",
        reason="Waiter encountered a terminal failure state",
        last_response=None,
    )
    mock_waiter = uploader.cfn_client.get_waiter.return_value
    mock_waiter.wait.side_effect = e

    with pytest.raises(UploadError) as excinfo:
        uploader._wait_for_stack("stack-foo", "StackCreateComplete", "success-msg")

    mock_waiter.wait.assert_called_once_with(StackName="stack-foo", WaiterConfig=ANY)
    assert excinfo.value.__cause__ is e 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli,代码行数:16,代码来源:test_upload.py


注:本文中的botocore.exceptions.WaiterError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。