Skip to content

Commit

Permalink
Merge pull request ansible-collections#564 from tremble/issue/466
Browse files Browse the repository at this point in the history
Route53 retry/waiter tweaks

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
ansible-zuul[bot] authored May 21, 2021
2 parents 637019e + 287ca66 commit a82cc87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelogs/564-route53-retries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bugfixes:
- route53 - fix typo in waiter configuration that prevented management of the delays (https://github.com/ansible-collections/community.aws/pull/564).
minor_changes:
- route53 - add retries on ``PriorRequestNotComplete`` errors (https://github.com/ansible-collections/community.aws/pull/564).
- route53 - update retry ``max_delay`` setting so that it can be set above 60 seconds (https://github.com/ansible-collections/community.aws/pull/564).
- route53 - add rate-limiting retries while waiting for changes to propagate (https://github.com/ansible-collections/community.aws/pull/564).
17 changes: 11 additions & 6 deletions plugins/modules/route53.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_message
from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter

MAX_AWS_RETRIES = 10 # How many retries to perform when an API call is failing
WAIT_RETRY = 5 # how many seconds to wait between propagation status polls
Expand Down Expand Up @@ -574,12 +575,16 @@ def main():
if (weight_in is None and region_in is None and failover_in is None) and identifier_in is not None:
module.fail_json(msg="You have specified identifier which makes sense only if you specify one of: weight, region or failover.")

retry_decorator = AWSRetry.jittered_backoff(
retries=MAX_AWS_RETRIES,
delay=retry_interval_in,
catch_extra_error_codes=['PriorRequestNotComplete'],
max_delay=max(60, retry_interval_in),
)

# connect to the route53 endpoint
try:
route53 = module.client(
'route53',
retry_decorator=AWSRetry.jittered_backoff(retries=MAX_AWS_RETRIES, delay=retry_interval_in)
)
route53 = module.client('route53', retry_decorator=retry_decorator)
except botocore.exceptions.HTTPClientError as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')

Expand Down Expand Up @@ -663,12 +668,12 @@ def main():
)

if wait_in:
waiter = route53.get_waiter('resource_record_sets_changed')
waiter = get_waiter(route53, 'resource_record_sets_changed')
waiter.wait(
Id=change_resource_record_sets['ChangeInfo']['Id'],
WaiterConfig=dict(
Delay=WAIT_RETRY,
MaxAttemps=wait_timeout_in // WAIT_RETRY,
MaxAttempts=wait_timeout_in // WAIT_RETRY,
)
)
except is_boto3_error_message('but it already exists'):
Expand Down

0 comments on commit a82cc87

Please sign in to comment.