[cloud] ec2_asg should wait for ASG to delete (#35327)

`wait_for_instances: no` means do not wait for instances to become
InService/Healthy before terminating them. It does not mean don't
wait for the ASG to delete.

Not waiting for the ASG to delete can cause problems when recreating it.
Ensure that waiting for the ASG to delete respects `wait_timeout`.
This commit is contained in:
Will Thames 2018-01-27 07:12:21 +10:00 committed by Ryan Brown
commit 2fac647955

View file

@ -1089,11 +1089,10 @@ def delete_autoscaling_group(connection):
del_notification_config(connection, group_name, notification_topic)
groups = describe_autoscaling_groups(connection, group_name)
if groups:
wait_timeout = time.time() + wait_timeout
if not wait_for_instances:
delete_asg(connection, group_name, force_delete=True)
return True
wait_timeout = time.time() + wait_timeout
else:
updated_params = dict(AutoScalingGroupName=group_name, MinSize=0, MaxSize=0, DesiredCapacity=0)
update_asg(connection, **updated_params)
instances = True
@ -1110,8 +1109,11 @@ def delete_autoscaling_group(connection):
module.fail_json(msg="Waited too long for old instances to terminate. %s" % time.asctime())
delete_asg(connection, group_name, force_delete=False)
while describe_autoscaling_groups(connection, group_name):
while describe_autoscaling_groups(connection, group_name) and wait_timeout >= time.time():
time.sleep(5)
if wait_timeout <= time.time():
# waiting took too long
module.fail_json(msg="Waited too long for ASG to delete. %s" % time.asctime())
return True
return False