Skip to content

Commit

Permalink
Bulk update AWSRetry.backoff to AWSRetry.jittered_backoff (ansible-co…
Browse files Browse the repository at this point in the history
…llections#764)

Bulk update AWSRetry.backoff to AWSRetry.jittered_backoff

SUMMARY
CloudRetry.backoff has been deprecated in favour of CloudRetry{exponential,jittered}_backoff
bulk update AWSRetry.backoff usage.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/aws_config_delivery_channel.py
plugins/modules/aws_direct_connect_confirm_connection.py
plugins/modules/aws_direct_connect_connection.py
plugins/modules/aws_direct_connect_link_aggregation_group.py
plugins/modules/aws_direct_connect_virtual_interface.py
plugins/modules/aws_inspector_target.py
plugins/modules/aws_kms.py
plugins/modules/aws_kms_info.py
plugins/modules/cloudformation_stack_set.py
plugins/modules/dms_endpoint.py
plugins/modules/dms_replication_subnet_group.py
plugins/modules/ec2_asg.py
plugins/modules/ec2_elb_info.py
plugins/modules/ecs_service_info.py
plugins/modules/iam_managed_policy.py
plugins/modules/iam_saml_federation.py
plugins/modules/rds.py
ADDITIONAL INFORMATION

Reviewed-by: None <None>
Reviewed-by: None <None>
  • Loading branch information
tremble authored Oct 18, 2021
1 parent eaf24d0 commit e2f3dc6
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion aws_config_delivery_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

# this waits for an IAM role to become fully available, at the cost of
# taking a long time to fail when the IAM role/policy really is invalid
retry_unavailable_iam_on_put_delivery = AWSRetry.backoff(
retry_unavailable_iam_on_put_delivery = AWSRetry.jittered_backoff(
catch_extra_error_codes=['InsufficientDeliveryPolicyException'],
)

Expand Down
4 changes: 2 additions & 2 deletions aws_direct_connect_confirm_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
from ansible_collections.amazon.aws.plugins.module_utils.direct_connect import DirectConnectError
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry

retry_params = {"tries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]}
retry_params = {"retries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]}


@AWSRetry.backoff(**retry_params)
@AWSRetry.jittered_backoff(**retry_params)
def describe_connections(client, params):
return client.describe_connections(**params)

Expand Down
10 changes: 5 additions & 5 deletions aws_direct_connect_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
from ansible_collections.amazon.aws.plugins.module_utils.direct_connect import disassociate_connection_and_lag
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry

retry_params = {"tries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]}
retry_params = {"retries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]}


def connection_status(client, connection_id):
Expand All @@ -179,7 +179,7 @@ def connection_exists(client, connection_id=None, connection_name=None, verify=T
if connection_id:
params['connectionId'] = connection_id
try:
response = AWSRetry.backoff(**retry_params)(client.describe_connections)(**params)
response = AWSRetry.jittered_backoff(**retry_params)(client.describe_connections)(**params)
except (BotoCoreError, ClientError) as e:
if connection_id:
msg = "Failed to describe DirectConnect ID {0}".format(connection_id)
Expand Down Expand Up @@ -227,7 +227,7 @@ def create_connection(client, location, bandwidth, name, lag_id):
params['lagId'] = lag_id

try:
connection = AWSRetry.backoff(**retry_params)(client.create_connection)(**params)
connection = AWSRetry.jittered_backoff(**retry_params)(client.create_connection)(**params)
except (BotoCoreError, ClientError) as e:
raise DirectConnectError(msg="Failed to create DirectConnect connection {0}".format(name),
last_traceback=traceback.format_exc(),
Expand All @@ -242,7 +242,7 @@ def changed_properties(current_status, location, bandwidth):
return current_bandwidth != bandwidth or current_location != location


@AWSRetry.backoff(**retry_params)
@AWSRetry.jittered_backoff(**retry_params)
def update_associations(client, latest_state, connection_id, lag_id):
changed = False
if 'lagId' in latest_state and lag_id != latest_state['lagId']:
Expand Down Expand Up @@ -277,7 +277,7 @@ def ensure_present(client, connection_id, connection_name, location, bandwidth,
return False, connection_id


@AWSRetry.backoff(**retry_params)
@AWSRetry.jittered_backoff(**retry_params)
def ensure_absent(client, connection_id):
changed = False
if connection_id:
Expand Down
2 changes: 1 addition & 1 deletion aws_direct_connect_link_aggregation_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def delete_lag(client, lag_id):
exception=e)


@AWSRetry.backoff(tries=5, delay=2, backoff=2.0, catch_extra_error_codes=['DirectConnectClientException'])
@AWSRetry.jittered_backoff(retries=5, delay=2, backoff=2.0, catch_extra_error_codes=['DirectConnectClientException'])
def _update_lag(client, lag_id, lag_name, min_links):
params = {}
if min_links:
Expand Down
2 changes: 1 addition & 1 deletion aws_direct_connect_virtual_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def try_except_ClientError(failure_msg):
def wrapper(f):
def run_func(*args, **kwargs):
try:
result = AWSRetry.backoff(tries=8, delay=5, catch_extra_error_codes=['DirectConnectClientException'])(f)(*args, **kwargs)
result = AWSRetry.jittered_backoff(retries=8, delay=5, catch_extra_error_codes=['DirectConnectClientException'])(f)(*args, **kwargs)
except (ClientError, BotoCoreError) as e:
raise DirectConnectError(failure_msg, traceback.format_exc(), e)
return result
Expand Down
2 changes: 1 addition & 1 deletion aws_inspector_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
pass # caught by AnsibleAWSModule


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def main():
argument_spec = dict(
name=dict(required=True),
Expand Down
16 changes: 8 additions & 8 deletions aws_kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,19 +434,19 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_policies


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_iam_roles_with_backoff(connection):
paginator = connection.get_paginator('list_roles')
return paginator.paginate().build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_keys_with_backoff(connection):
paginator = connection.get_paginator('list_keys')
return paginator.paginate().build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_aliases_with_backoff(connection):
paginator = connection.get_paginator('list_aliases')
return paginator.paginate().build_full_result()
Expand All @@ -465,30 +465,30 @@ def get_kms_aliases_lookup(connection):
return _aliases


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_tags_with_backoff(connection, key_id, **kwargs):
return connection.list_resource_tags(KeyId=key_id, **kwargs)


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_grants_with_backoff(connection, key_id):
params = dict(KeyId=key_id)
paginator = connection.get_paginator('list_grants')
return paginator.paginate(**params).build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_metadata_with_backoff(connection, key_id):
return connection.describe_key(KeyId=key_id)


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def list_key_policies_with_backoff(connection, key_id):
paginator = connection.get_paginator('list_key_policies')
return paginator.paginate(KeyId=key_id).build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_key_policy_with_backoff(connection, key_id, policy_name):
return connection.get_key_policy(KeyId=key_id, PolicyName=policy_name)

Expand Down
16 changes: 8 additions & 8 deletions aws_kms_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@
_aliases = dict()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_keys_with_backoff(connection):
paginator = connection.get_paginator('list_keys')
return paginator.paginate().build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_aliases_with_backoff(connection):
paginator = connection.get_paginator('list_aliases')
return paginator.paginate().build_full_result()
Expand All @@ -286,12 +286,12 @@ def get_kms_aliases_lookup(connection):
return _aliases


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_tags_with_backoff(connection, key_id, **kwargs):
return connection.list_resource_tags(KeyId=key_id, **kwargs)


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_grants_with_backoff(connection, key_id, **kwargs):
params = dict(KeyId=key_id)
if kwargs.get('tokens'):
Expand All @@ -300,23 +300,23 @@ def get_kms_grants_with_backoff(connection, key_id, **kwargs):
return paginator.paginate(**params).build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_kms_metadata_with_backoff(connection, key_id):
return connection.describe_key(KeyId=key_id)


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def list_key_policies_with_backoff(connection, key_id):
paginator = connection.get_paginator('list_key_policies')
return paginator.paginate(KeyId=key_id).build_full_result()


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_key_policy_with_backoff(connection, key_id, policy_name):
return connection.get_key_policy(KeyId=key_id, PolicyName=policy_name)


@AWSRetry.backoff(tries=5, delay=5, backoff=2.0)
@AWSRetry.jittered_backoff(retries=5, delay=5, backoff=2.0)
def get_enable_key_rotation_with_backoff(connection, key_id):
try:
current_rotation_status = connection.get_key_rotation_status(KeyId=key_id)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation_stack_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def compare_stack_instances(cfn, stack_set_name, accounts, regions):
return (desired_stack_instances - existing_stack_instances), existing_stack_instances, (existing_stack_instances - desired_stack_instances)


@AWSRetry.backoff(tries=3, delay=4)
@AWSRetry.jittered_backoff(retries=3, delay=4)
def stack_set_facts(cfn, stack_set_name):
try:
ss = cfn.describe_stack_set(StackSetName=stack_set_name)['StackSet']
Expand Down
12 changes: 6 additions & 6 deletions dms_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry

backoff_params = dict(tries=5, delay=1, backoff=1.5)
backoff_params = dict(retries=5, delay=1, backoff=1.5)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def describe_endpoints(connection, endpoint_identifier):
""" checks if the endpoint exists """
try:
Expand All @@ -189,7 +189,7 @@ def describe_endpoints(connection, endpoint_identifier):
return {'Endpoints': []}


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def dms_delete_endpoint(client, **params):
"""deletes the DMS endpoint based on the EndpointArn"""
if module.params.get('wait'):
Expand All @@ -198,19 +198,19 @@ def dms_delete_endpoint(client, **params):
return client.delete_endpoint(**params)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def dms_create_endpoint(client, **params):
""" creates the DMS endpoint"""
return client.create_endpoint(**params)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def dms_modify_endpoint(client, **params):
""" updates the endpoint"""
return client.modify_endpoint(**params)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def get_endpoint_deleted_waiter(client):
return client.get_waiter('endpoint_deleted')

Expand Down
10 changes: 5 additions & 5 deletions dms_replication_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry

backoff_params = dict(tries=5, delay=1, backoff=1.5)
backoff_params = dict(retries=5, delay=1, backoff=1.5)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def describe_subnet_group(connection, subnet_group):
"""checks if instance exists"""
try:
Expand All @@ -80,18 +80,18 @@ def describe_subnet_group(connection, subnet_group):
return {'ReplicationSubnetGroups': []}


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def replication_subnet_group_create(connection, **params):
""" creates the replication subnet group """
return connection.create_replication_subnet_group(**params)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def replication_subnet_group_modify(connection, **modify_params):
return connection.modify_replication_subnet_group(**modify_params)


@AWSRetry.backoff(**backoff_params)
@AWSRetry.jittered_backoff(**backoff_params)
def replication_subnet_group_delete(module, connection):
subnetid = module.params.get('identifier')
delete_parameters = dict(ReplicationSubnetGroupIdentifier=subnetid)
Expand Down
Loading

0 comments on commit e2f3dc6

Please sign in to comment.