當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。