SoftwareDeployments move signal reason into resource plugin

Move the determination of the signal reason string inside the resource
plugin so we don't need the resource-specific details handling in the
base-class.

Change-Id: I1eec87c2063a1958eba2ad32d43474c2ed435117
Related-Bug: #1340894
This commit is contained in:
Steven Hardy 2014-07-14 16:26:45 +01:00
parent 4655e9f468
commit 762656f7fd
4 changed files with 13 additions and 25 deletions

View File

@ -985,13 +985,6 @@ 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'
if not callable(getattr(self, 'handle_signal', None)):

View File

@ -440,6 +440,9 @@ class SoftwareDeployment(signal_responder.SignalResponder):
status_reasons[self.STATUS_CODE] = _(
'Deployment exited with non-zero status code: %s'
) % details.get(self.STATUS_CODE)
event_reason = 'deployment failed (%s)' % status_code
else:
event_reason = 'deployment succeeded'
for output in sc.outputs or []:
out_key = output['name']
@ -448,6 +451,7 @@ class SoftwareDeployment(signal_responder.SignalResponder):
if output.get('error_output', False):
status = self.FAILED
status_reasons[out_key] = details[out_key]
event_reason = 'deployment failed'
for out_key in self.ATTRIBUTES:
ov[out_key] = details.get(out_key)
@ -461,6 +465,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
status = self.COMPLETE
status_reason = _('Outputs received')
sd.update(output_values=ov, status=status, status_reason=status_reason)
# Return a string describing the outcome of handling the signal data
return event_reason
def FnGetAtt(self, key, *path):
'''

View File

@ -263,16 +263,6 @@ 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')
@ -284,15 +274,11 @@ 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, sds_details, sdf_details):
none_details):
rsrc.signal(details=test_d)
self.m.VerifyAll()

View File

@ -463,7 +463,8 @@ class SoftwareDeploymentTest(HeatTestCase):
'foo': 'bar',
'deploy_status_code': 0
}
self.deployment.handle_signal(details)
ret = self.deployment.handle_signal(details)
self.assertEqual('deployment succeeded', ret)
args = sd.update.call_args[1]
self.assertEqual({
'output_values': {
@ -493,7 +494,8 @@ class SoftwareDeploymentTest(HeatTestCase):
'foo': 'bar',
'deploy_status_code': '0'
}
self.deployment.handle_signal(details)
ret = self.deployment.handle_signal(details)
self.assertEqual('deployment succeeded', ret)
args = sd.update.call_args[1]
self.assertEqual({
'output_values': {
@ -520,7 +522,8 @@ class SoftwareDeploymentTest(HeatTestCase):
self.deployments.get.return_value = sd
self.software_configs.get.return_value = sc
details = {'failed': 'no enough memory found.'}
self.deployment.handle_signal(details)
ret = self.deployment.handle_signal(details)
self.assertEqual('deployment failed', ret)
args = sd.update.call_args[1]
self.assertEqual({
'output_values': {