Modifying the wait logic for newly created images to avoid tracebacks
Fixes #4619
This commit is contained in:
parent
1762557ff4
commit
f3ef528dfa
1 changed files with 4 additions and 5 deletions
|
@ -199,17 +199,17 @@ def create_image(module, ec2):
|
||||||
# Wait until the image is recognized. EC2 API has eventual consistency,
|
# Wait until the image is recognized. EC2 API has eventual consistency,
|
||||||
# such that a successful CreateImage API call doesn't guarantee the success
|
# such that a successful CreateImage API call doesn't guarantee the success
|
||||||
# of subsequent DescribeImages API call using the new image id returned.
|
# of subsequent DescribeImages API call using the new image id returned.
|
||||||
for i in range(30):
|
for i in range(wait_timeout):
|
||||||
try:
|
try:
|
||||||
img = ec2.get_image(image_id)
|
img = ec2.get_image(image_id)
|
||||||
break
|
break
|
||||||
except boto.exception.EC2ResponseError, e:
|
except boto.exception.EC2ResponseError, e:
|
||||||
if e.error_code == 'InvalidAMIID.NotFound':
|
if 'InvalidAMIID.NotFound' in e.error_code and wait:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
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:
|
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 here until the image is created
|
||||||
wait_timeout = time.time() + wait_timeout
|
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.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)
|
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):
|
def deregister_image(module, ec2):
|
||||||
|
|
Loading…
Reference in a new issue