From 978b867fda2faa44b58db105ed021d78466931e3 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 2 Aug 2022 13:45:48 +0200 Subject: [PATCH] Remove deprecated @AWSRetry.backoff usage --- changelogs/fragments/946-retries.yml | 3 +++ plugins/module_utils/acm.py | 14 +++++++------- plugins/module_utils/waf.py | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 changelogs/fragments/946-retries.yml diff --git a/changelogs/fragments/946-retries.yml b/changelogs/fragments/946-retries.yml new file mode 100644 index 00000000000..c226157197b --- /dev/null +++ b/changelogs/fragments/946-retries.yml @@ -0,0 +1,3 @@ +minor_changes: +- module_utils/acm - Move to jittered backoff (https://github.com/ansible-collections/amazon.aws/pull/946). +- module_utils/waf - Move to jittered backoff (https://github.com/ansible-collections/amazon.aws/pull/946). diff --git a/plugins/module_utils/acm.py b/plugins/module_utils/acm.py index e0934deade4..9e384115d5e 100644 --- a/plugins/module_utils/acm.py +++ b/plugins/module_utils/acm.py @@ -51,7 +51,7 @@ def __init__(self, module): self.module = module self.client = module.client('acm') - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException']) def delete_certificate_with_backoff(self, client, arn): client.delete_certificate(CertificateArn=arn) @@ -63,7 +63,7 @@ def delete_certificate(self, client, module, arn): module.fail_json_aws(e, msg="Couldn't delete certificate %s" % arn) module.debug("Successfully deleted certificate %s" % arn) - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException']) def list_certificates_with_backoff(self, client, statuses=None): paginator = client.get_paginator('list_certificates') kwargs = dict() @@ -71,18 +71,18 @@ def list_certificates_with_backoff(self, client, statuses=None): kwargs['CertificateStatuses'] = statuses return paginator.paginate(**kwargs).build_full_result()['CertificateSummaryList'] - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['ResourceNotFoundException', 'RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException', 'ResourceNotFoundException']) def get_certificate_with_backoff(self, client, certificate_arn): response = client.get_certificate(CertificateArn=certificate_arn) # strip out response metadata return {'Certificate': response['Certificate'], 'CertificateChain': response['CertificateChain']} - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['ResourceNotFoundException', 'RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException', 'ResourceNotFoundException']) def describe_certificate_with_backoff(self, client, certificate_arn): return client.describe_certificate(CertificateArn=certificate_arn)['Certificate'] - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['ResourceNotFoundException', 'RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException', 'ResourceNotFoundException']) def list_certificate_tags_with_backoff(self, client, certificate_arn): return client.list_tags_for_certificate(CertificateArn=certificate_arn)['Tags'] @@ -161,7 +161,7 @@ def get_domain_of_cert(self, client, module, arn): module.fail_json_aws(e, msg="Couldn't obtain certificate data for arn %s" % arn) return cert_data['DomainName'] - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException']) def import_certificate_with_backoff(self, client, certificate, private_key, certificate_chain, arn): if certificate_chain: if arn: @@ -185,7 +185,7 @@ def import_certificate_with_backoff(self, client, certificate, private_key, cert # Tags are a normal Ansible style dict # {'Key':'Value'} - @AWSRetry.backoff(tries=5, delay=5, backoff=2.0, catch_extra_error_codes=['ResourceNotFoundException', 'RequestInProgressException']) + @AWSRetry.jittered_backoff(delay=5, catch_extra_error_codes=['RequestInProgressException', 'ResourceNotFoundException']) def tag_certificate_with_backoff(self, client, arn, tags): aws_tags = ansible_dict_to_boto3_tag_list(tags) client.add_tags_to_certificate(CertificateArn=arn, Tags=aws_tags) diff --git a/plugins/module_utils/waf.py b/plugins/module_utils/waf.py index 3ecc645c460..fe4c306f4f6 100644 --- a/plugins/module_utils/waf.py +++ b/plugins/module_utils/waf.py @@ -89,32 +89,32 @@ } -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_rule_with_backoff(client, rule_id): return client.get_rule(RuleId=rule_id)['Rule'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_byte_match_set_with_backoff(client, byte_match_set_id): return client.get_byte_match_set(ByteMatchSetId=byte_match_set_id)['ByteMatchSet'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_ip_set_with_backoff(client, ip_set_id): return client.get_ip_set(IPSetId=ip_set_id)['IPSet'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_size_constraint_set_with_backoff(client, size_constraint_set_id): return client.get_size_constraint_set(SizeConstraintSetId=size_constraint_set_id)['SizeConstraintSet'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_sql_injection_match_set_with_backoff(client, sql_injection_match_set_id): return client.get_sql_injection_match_set(SqlInjectionMatchSetId=sql_injection_match_set_id)['SqlInjectionMatchSet'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_xss_match_set_with_backoff(client, xss_match_set_id): return client.get_xss_match_set(XssMatchSetId=xss_match_set_id)['XssMatchSet'] @@ -141,7 +141,7 @@ def get_rule(client, module, rule_id): return rule -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def get_web_acl_with_backoff(client, web_acl_id): return client.get_web_acl(WebACLId=web_acl_id)['WebACL'] @@ -161,13 +161,13 @@ def get_web_acl(client, module, web_acl_id): return camel_dict_to_snake_dict(web_acl) -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def list_rules_with_backoff(client): paginator = client.get_paginator('list_rules') return paginator.paginate().build_full_result()['Rules'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def list_regional_rules_with_backoff(client): resp = client.list_rules() rules = [] @@ -177,13 +177,13 @@ def list_regional_rules_with_backoff(client): return rules -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def list_web_acls_with_backoff(client): paginator = client.get_paginator('list_web_acls') return paginator.paginate().build_full_result()['WebACLs'] -@AWSRetry.backoff(tries=5, delay=5, backoff=2.0) +@AWSRetry.jittered_backoff(delay=5) def list_regional_web_acls_with_backoff(client): resp = client.list_web_acls() acls = [] @@ -211,7 +211,7 @@ def get_change_token(client, module): module.fail_json_aws(e, msg="Couldn't obtain change token") -@AWSRetry.backoff(tries=10, delay=2, backoff=2.0, catch_extra_error_codes=['WAFStaleDataException']) +@AWSRetry.jittered_backoff(backoff=2, catch_extra_error_codes=['WAFStaleDataException']) def run_func_with_change_token_backoff(client, module, params, func, wait=False): params['ChangeToken'] = get_change_token(client, module) result = func(**params)