diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 269ab21f7..f7e4641e2 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -53,7 +53,6 @@ class UpdateReplace(Exception): ''' Raised when resource update requires replacement ''' - _message = _("The Resource %s requires replacement.") def __init__(self, resource_name='Unknown', message=_("The Resource %s requires replacement.")): diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 8286fdd43..af93ab2dd 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -502,7 +502,30 @@ class ResourceTest(HeatTestCase): self.assertEqual((res.UPDATE, res.COMPLETE), res.state) self.m.VerifyAll() - def test_update_replace(self): + def test_update_replace_with_resource_name(self): + tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}} + res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack) + res.update_allowed_keys = ('Properties',) + res.update_allowed_properties = ('Foo',) + scheduler.TaskRunner(res.create)() + self.assertEqual((res.CREATE, res.COMPLETE), res.state) + + utmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'xyz'}} + self.m.StubOutWithMock(generic_rsrc.ResourceWithProps, 'handle_update') + tmpl_diff = {'Properties': {'Foo': 'xyz'}} + prop_diff = {'Foo': 'xyz'} + generic_rsrc.ResourceWithProps.handle_update( + utmpl, tmpl_diff, prop_diff).AndRaise(resource.UpdateReplace( + res.name)) + self.m.ReplayAll() + # should be re-raised so parser.Stack can handle replacement + updater = scheduler.TaskRunner(res.update, utmpl) + ex = self.assertRaises(resource.UpdateReplace, updater) + self.assertEqual('The Resource test_resource requires replacement.', + str(ex)) + self.m.VerifyAll() + + def test_update_replace_without_resource_name(self): tmpl = {'Type': 'GenericResourceType', 'Properties': {'Foo': 'abc'}} res = generic_rsrc.ResourceWithProps('test_resource', tmpl, self.stack) res.update_allowed_keys = ('Properties',) @@ -519,7 +542,9 @@ class ResourceTest(HeatTestCase): self.m.ReplayAll() # should be re-raised so parser.Stack can handle replacement updater = scheduler.TaskRunner(res.update, utmpl) - self.assertRaises(resource.UpdateReplace, updater) + ex = self.assertRaises(resource.UpdateReplace, updater) + self.assertEqual('The Resource Unknown requires replacement.', + str(ex)) self.m.VerifyAll() def test_update_fail_missing_req_prop(self):