Modifying the wait logic for newly created images to avoid tracebacks

Fixes #4619
This commit is contained in:
James Cammarata 2014-02-26 13:31:17 -06:00
parent a37a6983be
commit d6b912c429

View file

@ -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):