From a330b1d346054f9a510891a6de20e010b15f46a3 Mon Sep 17 00:00:00 2001 From: Marco Rucci Date: Sun, 15 May 2016 21:17:59 +0200 Subject: [PATCH] ELBs can now be deleted before their autoscaling groups. Also, fix name clash in autoscaling tests. --- moto/autoscaling/models.py | 18 +++++++++--------- tests/test_autoscaling/test_autoscaling.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index e4c6f108..d54c39d7 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -197,17 +197,10 @@ class FakeAutoScalingGroup(object): backend.delete_autoscaling_group(resource_name) except KeyError: pass - except LoadBalancerNotFoundError: - # sometimes the ELB gets modified before the ASG, so just skip over desired capacity - backend.autoscaling_groups.pop(resource_name, None) def delete(self, region_name): backend = autoscaling_backends[region_name] - try: - backend.delete_autoscaling_group(self.name) - except LoadBalancerNotFoundError: - # sometimes the ELB gets deleted before the ASG, so just skip over desired capacity - backend.autoscaling_groups.pop(self.name, None) + backend.delete_autoscaling_group(self.name) @property def physical_resource_id(self): @@ -435,7 +428,14 @@ class AutoScalingBackend(BaseBackend): def update_attached_elbs(self, group_name): group = self.autoscaling_groups[group_name] group_instance_ids = set(state.instance.id for state in group.instance_states) - for elb in self.elb_backend.describe_load_balancers(names=group.load_balancers): + + try: + elbs = self.elb_backend.describe_load_balancers(names=group.load_balancers) + except LoadBalancerNotFoundError: + # ELBs can be deleted before their autoscaling group + return + + for elb in elbs: elb_instace_ids = set(elb.instance_ids) self.elb_backend.register_instances(elb.name, group_instance_ids - elb_instace_ids) self.elb_backend.deregister_instances(elb.name, elb_instace_ids - group_instance_ids) diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index e4875070..2f442c16 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -386,7 +386,7 @@ Boto3 @mock_autoscaling -def test_create_autoscaling_group(): +def test_create_autoscaling_group_boto3(): client = boto3.client('autoscaling', region_name='us-east-1') _ = client.create_launch_configuration( LaunchConfigurationName='test_launch_configuration' @@ -402,7 +402,7 @@ def test_create_autoscaling_group(): @mock_autoscaling -def test_describe_autoscaling_groups(): +def test_describe_autoscaling_groups_boto3(): client = boto3.client('autoscaling', region_name='us-east-1') _ = client.create_launch_configuration( LaunchConfigurationName='test_launch_configuration'