From 8f8c9ab6b7493cb402c16722d5255e792740df0f Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Fri, 9 Aug 2013 20:12:23 -0500 Subject: [PATCH] Fix problem creating ResourceFailure The ResourceFailure exception is being instantiated improperly in a couple of places. This changes fixes the problem and adds tests to cover the problem cases. Change-Id: I2662a3abde1fd00d275e2190401c20166256cae0 Closes-Bug: 1210681 --- heat/engine/parser.py | 2 +- heat/engine/resources/instance.py | 4 ++-- heat/tests/test_instance.py | 32 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/heat/engine/parser.py b/heat/engine/parser.py index 4d779911a..8d29dfe4f 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -339,7 +339,7 @@ class Stack(object): else: raise exception.ResourceFailure( AttributeError(_('Resource action %s not found') % - action_l)) + action_l), r) action_task = scheduler.DependencyTaskGroup(self.dependencies, resource_action, diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index 54ee7d4b9..e4b32c7b2 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -327,12 +327,12 @@ class Instance(resource.Resource): delete(wait_time=0.2) exc = exception.Error("Build of server %s failed." % server.name) - raise exception.ResourceFailure(exc) + raise exception.ResourceFailure(exc, self) else: exc = exception.Error('%s instance[%s] status[%s]' % ('nova reported unexpected', self.name, server.status)) - raise exception.ResourceFailure(exc) + raise exception.ResourceFailure(exc, self) else: return volume_attach.step() diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index dc5255132..c43709067 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -16,6 +16,7 @@ import copy import mox +from heat.engine import clients from heat.engine import environment from heat.tests.v1_1 import fakes from heat.common import exception @@ -205,6 +206,37 @@ class InstancesTest(HeatTestCase): self.m.VerifyAll() + class FakeVolumeAttach: + def started(self): + return False + + def test_instance_create_unexpected_status(self): + return_server = self.fc.servers.list()[1] + instance = self._create_test_instance(return_server, + 'test_instance_create') + return_server.get = lambda: None + return_server.status = 'BOGUS' + self.assertRaises(exception.ResourceFailure, + instance.check_create_complete, + (return_server, self.FakeVolumeAttach())) + + def test_instance_create_error_status(self): + return_server = self.fc.servers.list()[1] + instance = self._create_test_instance(return_server, + 'test_instance_create') + return_server.status = 'ERROR' + self.m.StubOutWithMock(return_server, 'get') + return_server.get() + return_server.get().AndRaise( + clients.novaclient.exceptions.NotFound('test')) + self.m.ReplayAll() + + self.assertRaises(exception.ResourceFailure, + instance.check_create_complete, + (return_server, self.FakeVolumeAttach())) + + self.m.VerifyAll() + def test_instance_validate(self): stack_name = 'test_instance_validate_stack' (t, stack) = self._setup_test_stack(stack_name)