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):
|
for i in range(wait_timeout):
|
||||||
try:
|
try:
|
||||||
img = ec2.get_image(image_id)
|
img = ec2.get_image(image_id)
|
||||||
|
|
||||||
|
if img.state == 'available':
|
||||||
break
|
break
|
||||||
except boto.exception.EC2ResponseError, e:
|
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)
|
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
|
if img.state != 'available':
|
||||||
wait_timeout = time.time() + wait_timeout
|
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.")
|
||||||
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 tags:
|
if tags:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue