Modifying the wait logic for newly created images to avoid tracebacks

Fixes #4619
reviewable/pr18780/r1
James Cammarata 11 years ago
parent 1762557ff4
commit f3ef528dfa

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

Loading…
Cancel
Save