Merge "Detect failed instance creation in autoscaling"

This commit is contained in:
Jenkins 2013-06-19 11:44:56 +00:00 committed by Gerrit Code Review
commit ce4e39d615
2 changed files with 29 additions and 3 deletions

View 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

View 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']