]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Detect failed instance creation in autoscaling
authorThomas Herve <th@rackspace.com>
Wed, 19 Jun 2013 07:17:48 +0000 (09:17 +0200)
committerThomas Herve <th@rackspace.com>
Wed, 19 Jun 2013 07:18:52 +0000 (09:18 +0200)
Wait for instances to be created sucessfully before adding them to the
list in the Autoscaling resource.

Fixes: bug #1192125
Change-Id: Ie8676c23de5a62d3b8b2b4088b67d249ae90ceef

heat/engine/resources/autoscaling.py
heat/tests/test_autoscaling.py

index 126f8cafa304f30165bc99ef6a82606928d34dec..509c412fc14e9bac0abfd06b435852bd3b5f290b 100644 (file)
@@ -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
index df7d4221a000c12ac9858fda8b697c12b40fbaaa..a959371f56a7b0b5e49039b6b1f3e70ba974b025 100644 (file)
@@ -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']