From d6b912c429e3c902621995470844bd88cafaf2c8 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 26 Feb 2014 13:31:17 -0600 Subject: [PATCH] Modifying the wait logic for newly created images to avoid tracebacks Fixes #4619 --- library/cloud/ec2_ami | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library/cloud/ec2_ami b/library/cloud/ec2_ami index ae2eca4fa4e..866f2caf767 100644 --- a/library/cloud/ec2_ami +++ b/library/cloud/ec2_ami @@ -199,17 +199,17 @@ def create_image(module, ec2): # Wait until the image is recognized. EC2 API has eventual consistency, # such that a successful CreateImage API call doesn't guarantee the success # of subsequent DescribeImages API call using the new image id returned. - for i in range(30): + for i in range(wait_timeout): try: img = ec2.get_image(image_id) break except boto.exception.EC2ResponseError, e: - if e.error_code == 'InvalidAMIID.NotFound': + if 'InvalidAMIID.NotFound' in e.error_code and wait: time.sleep(1) else: - raise + module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.") else: - module.fail_json(msg = "timed out waiting for image to be recognized") + module.fail_json(msg="timed out waiting for image to be recognized") # wait here until the image is created wait_timeout = time.time() + wait_timeout @@ -221,7 +221,6 @@ def create_image(module, ec2): module.fail_json(msg = "timed out waiting for image to be created") module.exit_json(msg="AMI creation operation complete", image_id=image_id, state=img.state, changed=True) - sys.exit(0) def deregister_image(module, ec2):