Fix an issue where by a call to ec2.get_image wasn't wrapped in a try/except, and would occasionally throw an exception in the wild. Also greatly simplifies two of the ugliest known loops to man down into a single loop. (#2554)
This commit is contained in:
parent
c64b7a71fb
commit
bfa0a94c27
1 changed files with 10 additions and 16 deletions
|
@ -251,23 +251,17 @@ def create_image(module, ec2):
|
|||
for i in range(wait_timeout):
|
||||
try:
|
||||
img = ec2.get_image(image_id)
|
||||
|
||||
if img.state == 'available':
|
||||
break
|
||||
except boto.exception.EC2ResponseError, e:
|
||||
if 'InvalidAMIID.NotFound' in e.error_code and wait:
|
||||
if ('InvalidAMIID.NotFound' not in e.error_code and 'InvalidAMIID.Unavailable' not in e.error_code) and wait and i == wait_timeout - 1:
|
||||
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help. %s: %s" % (e.error_code, e.error_message))
|
||||
finally:
|
||||
time.sleep(1)
|
||||
else:
|
||||
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")
|
||||
|
||||
# wait here until the image is created
|
||||
wait_timeout = time.time() + wait_timeout
|
||||
while wait and wait_timeout > time.time() and (img is None or img.state != 'available'):
|
||||
img = ec2.get_image(image_id)
|
||||
time.sleep(3)
|
||||
if wait and wait_timeout <= time.time():
|
||||
# waiting took too long
|
||||
module.fail_json(msg = "timed out waiting for image to be created")
|
||||
if img.state != 'available':
|
||||
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.")
|
||||
|
||||
if tags:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue