From 5df976875f8dbdd0ada5a66e534547e764a30231 Mon Sep 17 00:00:00 2001 From: tengqm Date: Thu, 3 Apr 2014 04:44:40 +0800 Subject: [PATCH] Fix status reason in events for deployment signals When a signal is received and processed by a Resource, there could be an event generated automatically. For such an event, Heat is supposed to provide some useful message (including status_reason). But currently, the resource code can only process ceilometer alarms and watch rules, for signals sent for a SoftwareDeployment resource, the signal is only providing an string 'Unknown' as the status change reason. This is confusing when a user performs 'heat event-list stack'. This patch adds an additional check (guess) whether the signal comes from a SoftwareDeployment. If that is the case, fill in the status reason as 'deployment succeeded', or 'deployment failed (n)', where n is the deploy_status_code that comes with the signal. Closes-Bug: #1300679 Change-Id: Ic970a5dac923fffdcdd365983df58f4d338de849 --- heat/engine/resource.py | 7 +++++++ heat/tests/test_signal.py | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index d65f67dad9..2e3532b248 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -880,6 +880,13 @@ class Resource(object): elif 'state' in details: # this is from watchrule return 'alarm state changed to %(state)s' % details + elif 'deploy_status_code' in details: + # this is for SoftwareDeployment + if details['deploy_status_code'] == 0: + return 'deployment succeeded' + else: + return ('deployment failed ' + '(%(deploy_status_code)s)' % details) return 'Unknown' diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py index 090ab4e8bf..bc0f5c2c8b 100644 --- a/heat/tests/test_signal.py +++ b/heat/tests/test_signal.py @@ -295,6 +295,16 @@ class SignalTest(HeatTestCase): none_details = None none_expected = 'No signal details provided' + # signal from a successful deployment + sds_details = {'deploy_stdout': 'foo', 'deploy_stderr': 'bar', + 'deploy_status_code': 0} + sds_expected = 'deployment succeeded' + + # signal from a failed deployment + sdf_details = {'deploy_stdout': 'foo', 'deploy_stderr': 'bar', + 'deploy_status_code': -1} + sdf_expected = 'deployment failed (-1)' + # to confirm we get a string reason self.m.StubOutWithMock(generic_resource.SignalResource, '_add_event') @@ -306,11 +316,15 @@ class SignalTest(HeatTestCase): 'signal', 'COMPLETE', str_expected).AndReturn(None) generic_resource.SignalResource._add_event( 'signal', 'COMPLETE', none_expected).AndReturn(None) + generic_resource.SignalResource._add_event( + 'signal', 'COMPLETE', sds_expected).AndReturn(None) + generic_resource.SignalResource._add_event( + 'signal', 'COMPLETE', sdf_expected).AndReturn(None) self.m.ReplayAll() - for test_d in (ceilo_details, watch_details, - str_details, none_details): + for test_d in (ceilo_details, watch_details, str_details, + none_details, sds_details, sdf_details): rsrc.signal(details=test_d) self.m.VerifyAll()