From 05a8399cbf230991b94898432c893decb8a6a276 Mon Sep 17 00:00:00 2001 From: Sergey Kraynev Date: Tue, 8 Apr 2014 03:37:43 -0400 Subject: [PATCH] Remove unused variable for UpdateReplace exception Base class Exception have not attribute "_message" and variable "message" has default value in init method, so attribute "_message" could be removed. Change-Id: I304e13d1923ef043f04f03477b94f88cea4bc52f --- heat/engine/resource.py | 1 - heat/tests/test_resource.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 1bd62785b..ec644b575 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -56,7 +56,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 7a7c026c1..6359789a7 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):