From: Steven Hardy Date: Thu, 27 Jun 2013 15:20:56 +0000 (+0100) Subject: autoscaling : Fix issue when scaling to zero instances X-Git-Tag: 2014.1~419^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e1aa8e791be34a144a404fe87d869ad9f9a3311e;p=openstack-build%2Fheat-build.git autoscaling : Fix issue when scaling to zero instances As noted in https://review.openstack.org/#/c/34564, we lack coverage of the scenario when MinSize is 0 and we scale down to zero instances then try to do a delete. We do the wrong thing here, by creating a GroupedInstance object with name '', and this would also result in an incorrect update to the LoadBalancer. Fix is to reset the resource_id to None. Fixes bug #1195364 Change-Id: Ie3a52badf35f7e660de9a8f38635d2a09463123a --- diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index f19204dc..1b04c753 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -199,7 +199,8 @@ class InstanceGroup(resource.Resource): inst = self._make_instance(victim) inst.destroy() inst_list.remove(victim) - self.resource_id_set(','.join(inst_list)) + # If we shrink to zero, set resource_id back to None + self.resource_id_set(','.join(inst_list) or None) self._lb_reload() diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index a959371f..eb849cac 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -153,6 +153,52 @@ class AutoScalingTest(HeatTestCase): for x in range(nmeta): Metadata.__set__(mox.IgnoreArg(), expected).AndReturn(None) + def test_scaling_delete_empty(self): + t = template_format.parse(as_template) + properties = t['Resources']['WebServerGroup']['Properties'] + properties['MinSize'] = '0' + properties['MaxSize'] = '0' + stack = parse_stack(t) + + now = timeutils.utcnow() + self.m.ReplayAll() + rsrc = self.create_scaling_group(t, stack, 'WebServerGroup') + self.assertEqual(None, rsrc.resource_id) + + rsrc.delete() + self.m.VerifyAll() + + def test_scaling_adjust_down_empty(self): + t = template_format.parse(as_template) + properties = t['Resources']['WebServerGroup']['Properties'] + properties['MinSize'] = '1' + properties['MaxSize'] = '1' + stack = parse_stack(t) + + self._stub_lb_reload(['WebServerGroup-0']) + now = timeutils.utcnow() + self._stub_meta_expected(now, 'ExactCapacity : 1') + self._stub_create(1) + self.m.ReplayAll() + rsrc = self.create_scaling_group(t, stack, 'WebServerGroup') + self.assertEqual('WebServerGroup-0', rsrc.resource_id) + + # Reduce the min size to 0, should complete without adjusting + update_snippet = copy.deepcopy(rsrc.parsed_template()) + update_snippet['Properties']['MinSize'] = '0' + self.assertEqual(None, rsrc.update(update_snippet)) + self.assertEqual('WebServerGroup-0', rsrc.resource_id) + + # trigger adjustment to reduce to 0, resource_id should be None + self._stub_lb_reload([]) + self._stub_meta_expected(now, 'ChangeInCapacity : -1') + self.m.ReplayAll() + rsrc.adjust(-1) + self.assertEqual(None, rsrc.resource_id) + + rsrc.delete() + self.m.VerifyAll() + def test_scaling_group_update_replace(self): t = template_format.parse(as_template) stack = parse_stack(t)