diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 126f8cafa3..509c412fc1 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -162,16 +162,17 @@ class InstanceGroup(resource.Resource): def create_instance(index): name = '%s-%d' % (self.name, index) inst = self._make_instance(name) - inst_list.append(name) - self.resource_id_set(','.join(inst_list)) logger.debug('Creating %s instance %d' % (str(self), index)) try: yield inst.create() - except exception.ResourceFailure as ex: + except exception.ResourceFailure: if raise_on_error: raise + else: + inst_list.append(name) + self.resource_id_set(','.join(inst_list)) if new_capacity > capacity: # grow diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index df7d4221a0..a959371f56 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -18,6 +18,7 @@ import copy import mox from heat.common import template_format +from heat.common import exception from heat.engine.resources import autoscaling as asc from heat.engine.resources import loadbalancer from heat.engine.resources import instance @@ -173,6 +174,30 @@ class AutoScalingTest(HeatTestCase): rsrc.delete() self.m.VerifyAll() + def test_scaling_group_create_error(self): + t = template_format.parse(as_template) + stack = parse_stack(t) + + self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep') + + self.m.StubOutWithMock(instance.Instance, 'handle_create') + self.m.StubOutWithMock(instance.Instance, 'check_create_complete') + exc = exception.ResourceFailure(Exception()) + instance.Instance.handle_create().AndRaise(exc) + + self.m.ReplayAll() + rsrc = asc.AutoScalingGroup('WebServerGroup', + t['Resources']['WebServerGroup'], + stack) + self.assertEqual(None, rsrc.validate()) + self.assertRaises(exception.ResourceFailure, + scheduler.TaskRunner(rsrc.create)) + self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state) + + self.assertEqual(None, rsrc.resource_id) + + self.m.VerifyAll() + def test_scaling_group_update_ok_maxsize(self): t = template_format.parse(as_template) properties = t['Resources']['WebServerGroup']['Properties']