Route53 check mode (#37273)

* Adding check mode for route53.

* flake8
pull/39622/merge
Felix Fontein 7 years ago committed by Ryan Brown
parent ada2ea4387
commit cb4db82354

@ -364,7 +364,6 @@ import distutils.version
try: try:
import boto import boto
import boto.ec2 import boto.ec2
from boto import route53
from boto.route53 import Route53Connection from boto.route53 import Route53Connection
from boto.route53.record import Record, ResourceRecordSets from boto.route53.record import Record, ResourceRecordSets
from boto.route53.status import Status from boto.route53.status import Status
@ -436,6 +435,7 @@ def commit(changes, retry_interval, wait, wait_timeout):
raise TimeoutError() raise TimeoutError()
return result return result
# Shamelessly copied over from https://git.io/vgmDG # Shamelessly copied over from https://git.io/vgmDG
IGNORE_CODE = 'Throttling' IGNORE_CODE = 'Throttling'
MAX_RETRIES = 5 MAX_RETRIES = 5
@ -491,7 +491,7 @@ def main():
mutually_exclusive = [('failover', 'region', 'weight')] mutually_exclusive = [('failover', 'region', 'weight')]
module = AnsibleModule(argument_spec=argument_spec, required_together=required_together, required_if=required_if, module = AnsibleModule(argument_spec=argument_spec, required_together=required_together, required_if=required_if,
mutually_exclusive=mutually_exclusive) mutually_exclusive=mutually_exclusive, supports_check_mode=True)
if not HAS_BOTO: if not HAS_BOTO:
module.fail_json(msg='boto required for this module') module.fail_json(msg='boto required for this module')
@ -654,17 +654,18 @@ def main():
command = command_in.upper() command = command_in.upper()
changes.add_change_record(command, wanted_rset) changes.add_change_record(command, wanted_rset)
try: if not module.check_mode:
result = invoke_with_throttling_retries(commit, changes, retry_interval_in, wait_in, wait_timeout_in) try:
except boto.route53.exception.DNSServerError as e: invoke_with_throttling_retries(commit, changes, retry_interval_in, wait_in, wait_timeout_in)
txt = e.body.split("<Message>")[1] except boto.route53.exception.DNSServerError as e:
txt = txt.split("</Message>")[0] txt = e.body.split("<Message>")[1]
if "but it already exists" in txt: txt = txt.split("</Message>")[0]
module.exit_json(changed=False) if "but it already exists" in txt:
else: module.exit_json(changed=False)
module.fail_json(msg=txt) else:
except TimeoutError: module.fail_json(msg=txt)
module.fail_json(msg='Timeout waiting for changes to replicate') except TimeoutError:
module.fail_json(msg='Timeout waiting for changes to replicate')
module.exit_json(changed=True) module.exit_json(changed=True)

Loading…
Cancel
Save