From cb5dfdf786619ea1d04467774e07c0c4b231ed4d Mon Sep 17 00:00:00 2001
From: Thomas Herve
Date: Wed, 19 Jun 2013 09:17:48 +0200
Subject: [PATCH] Detect failed instance creation in autoscaling
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 | 7 ++++---
heat/tests/test_autoscaling.py | 25 +++++++++++++++++++++++++
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py
index 126f8caf..509c412f 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 df7d4221..a959371f 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']
--
2.45.2
|