Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk update AWSRetry.backoff to AWSRetry.jittered_backoff #764

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions changelogs/fragments/764-awsretry-backoff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
minor_changes:
- aws_config_delivery_channel - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_direct_connect_confirm_connection - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_direct_connect_connection - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_direct_connect_link_aggregation_group - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_direct_connect_virtual_interface - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_inspector_target - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_kms - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- aws_kms_info - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- cloudformation_stack_set - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- dms_endpoint - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- dms_replication_subnet_group - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- ec2_asg - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- ec2_elb_info - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- ecs_service_info - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- iam_managed_policy - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- iam_saml_federation - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
- rds - replaced use of deprecated backoff decorator (https://github.com/ansible-collections/community.aws/pull/764).
2 changes: 1 addition & 1 deletion plugins/modules/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 plugins/modules/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 plugins/modules/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
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 plugins/modules/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 plugins/modules/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 plugins/modules/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 plugins/modules/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 plugins/modules/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 plugins/modules/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 plugins/modules/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