Make the ec2 wait code a little smarter

The code to determine the number of running instances could blow up
if the response from AWS did not actually contain any data. This code
makes it a bit smarter in handling, so that it will wait for a valid
response regardless of the wait condition.

Fixes #3980
reviewable/pr18780/r1
James Cammarata 11 years ago
parent a774f686f7
commit e14d857037

@ -477,15 +477,24 @@ def create_instances(module, ec2):
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message)) module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
# wait here until the instances are up # wait here until the instances are up
res_list = res.connection.get_all_instances(instids) this_res = []
this_res = res_list[0]
num_running = 0 num_running = 0
wait_timeout = time.time() + wait_timeout wait_timeout = time.time() + wait_timeout
while wait and wait_timeout > time.time() and num_running < len(instids): while wait_timeout > time.time() and num_running < len(instids):
res_list = res.connection.get_all_instances(instids) res_list = res.connection.get_all_instances(instids)
this_res = res_list[0] if len(res_list) > 0:
num_running = len([ i for i in this_res.instances if i.state=='running' ]) this_res = res_list[0]
time.sleep(5) num_running = len([ i for i in this_res.instances if i.state=='running' ])
else:
# got a bad response of some sort, possibly due to
# stale/cached data. Wait a second and then try again
time.sleep(1)
continue
if wait and num_running < len(instids):
time.sleep(5)
else:
break
if wait and wait_timeout <= time.time(): if wait and wait_timeout <= time.time():
# waiting took too long # waiting took too long
module.fail_json(msg = "wait for instances running timeout on %s" % time.asctime()) module.fail_json(msg = "wait for instances running timeout on %s" % time.asctime())

Loading…
Cancel
Save