From fad56730e8e602f802ea67d91fd876f0de32479e Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Wed, 9 Oct 2013 12:48:07 -0500 Subject: [PATCH] Add in a retry loop for route53 requests The route53 api doesn't allow multiple overlapping requests, so if it is still processing a previous request when the next comes in will return an error. Fixes #4085 --- cloud/route53 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cloud/route53 b/cloud/route53 index 38db85deb68..e5f23c1a3e7 100644 --- a/cloud/route53 +++ b/cloud/route53 @@ -120,6 +120,7 @@ EXAMPLES = ''' ''' import sys +import time try: import boto @@ -129,6 +130,20 @@ except ImportError: print "failed=True msg='boto required for this module'" sys.exit(1) +def commit(changes): + """Commit changes, but retry PriorRequestNotComplete errors.""" + retry = 10 + while True: + try: + retry -= 1 + return changes.commit() + except boto.route53.exception.DNSServerError, e: + code = e.body.split("")[1] + code = code.split("")[0] + if code != 'PriorRequestNotComplete' or retry < 0: + raise e + time.sleep(500) + def main(): module = AnsibleModule( argument_spec = dict( @@ -240,7 +255,7 @@ def main(): change.add_value(v) try: - result = changes.commit() + result = commit(changes) except boto.route53.exception.DNSServerError, e: txt = e.body.split("")[1] txt = txt.split("")[0]