diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 44fc998da3..4576578e2f 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -901,8 +901,12 @@ class Resource(object): str(self)) raise Exception(msg) - self._add_event('signal', self.status, get_string_details()) - self.handle_signal(details) + signal_result = self.handle_signal(details) + if signal_result: + reason_string = "Signal: %s" % signal_result + else: + reason_string = get_string_details() + self._add_event('signal', self.status, reason_string) except Exception as ex: LOG.exception(_('signal %(name)s : %(msg)s') % {'name': str(self), 'msg': ex}) diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py index e5acea4435..68122a665a 100644 --- a/heat/tests/test_signal.py +++ b/heat/tests/test_signal.py @@ -297,6 +297,30 @@ class SignalTest(HeatTestCase): self.m.VerifyAll() + def test_signal_plugin_reason(self): + # Ensure if handle_signal returns data, we use it as the reason + self.stack = self.create_stack() + self.stack.create() + + rsrc = self.stack['signal_handler'] + self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) + + self.m.StubOutWithMock(generic_resource.SignalResource, + 'handle_signal') + signal_details = {'status': 'COMPLETE'} + ret_expected = "Received COMPLETE signal" + generic_resource.SignalResource.handle_signal( + signal_details).AndReturn(ret_expected) + + self.m.StubOutWithMock(generic_resource.SignalResource, + '_add_event') + generic_resource.SignalResource._add_event( + 'signal', 'COMPLETE', 'Signal: %s' % ret_expected).AndReturn(None) + self.m.ReplayAll() + + rsrc.signal(details=signal_details) + self.m.VerifyAll() + def test_signal_wrong_resource(self): # assert that we get the correct exception when calling a # resource.signal() that does not have a handle_signal()