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
This commit is contained in:
tengqm 2014-04-03 04:44:40 +08:00 committed by Steve Baker
parent 03dd894de4
commit 930cb3c3e7
2 changed files with 23 additions and 2 deletions

View File

@ -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'

View File

@ -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()