Merge "Fix the signal details string"
This commit is contained in:
@@ -706,6 +706,23 @@ class Resource(object):
|
||||
to implement the signal, the base-class raise an exception if no
|
||||
handler is implemented.
|
||||
'''
|
||||
def get_string_details():
|
||||
if details is None:
|
||||
return 'No signal details provided'
|
||||
if isinstance(details, basestring):
|
||||
return details
|
||||
if isinstance(details, dict):
|
||||
if all(k in details for k in ('previous', 'current',
|
||||
'reason')):
|
||||
# this is from Ceilometer.
|
||||
auto = '%(previous)s to %(current)s (%(reason)s)' % details
|
||||
return 'alarm state changed from %s' % auto
|
||||
elif 'state' in details:
|
||||
# this is from watchrule
|
||||
return 'alarm state changed to %(state)s' % details
|
||||
|
||||
return 'Unknown'
|
||||
|
||||
try:
|
||||
if self.action in (self.SUSPEND, self.DELETE):
|
||||
msg = 'Cannot signal resource during %s' % self.action
|
||||
@@ -715,7 +732,7 @@ class Resource(object):
|
||||
msg = 'Resource %s is not able to receive a signal' % str(self)
|
||||
raise Exception(msg)
|
||||
|
||||
self._add_event('signal', self.status, details)
|
||||
self._add_event('signal', self.status, get_string_details())
|
||||
self.handle_signal(details)
|
||||
except Exception as ex:
|
||||
logger.exception('signal %s : %s' % (str(self), str(ex)))
|
||||
|
||||
@@ -170,6 +170,50 @@ class SignalTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@utils.stack_delete_after
|
||||
def test_signal_different_reason_types(self):
|
||||
self.stack = self.create_stack()
|
||||
self.stack.create()
|
||||
|
||||
rsrc = self.stack['signal_handler']
|
||||
self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
|
||||
self.assertTrue(rsrc.requires_deferred_auth)
|
||||
|
||||
ceilo_details = {'current': 'foo', 'reason': 'apples',
|
||||
'previous': 'SUCCESS'}
|
||||
ceilo_expected = 'alarm state changed from SUCCESS to foo (apples)'
|
||||
|
||||
watch_details = {'state': 'go_for_it'}
|
||||
watch_expected = 'alarm state changed to go_for_it'
|
||||
|
||||
str_details = 'a string details'
|
||||
str_expected = str_details
|
||||
|
||||
none_details = None
|
||||
none_expected = 'No signal details provided'
|
||||
|
||||
# to confirm we get a string reason
|
||||
self.m.StubOutWithMock(generic_resource.SignalResource,
|
||||
'_add_event')
|
||||
generic_resource.SignalResource._add_event(
|
||||
'signal', 'COMPLETE', ceilo_expected).AndReturn(None)
|
||||
generic_resource.SignalResource._add_event(
|
||||
'signal', 'COMPLETE', watch_expected).AndReturn(None)
|
||||
generic_resource.SignalResource._add_event(
|
||||
'signal', 'COMPLETE', str_expected).AndReturn(None)
|
||||
generic_resource.SignalResource._add_event(
|
||||
'signal', 'COMPLETE', none_expected).AndReturn(None)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
for test_d in (ceilo_details, watch_details,
|
||||
str_details, none_details):
|
||||
rsrc.signal(details=test_d)
|
||||
|
||||
self.m.VerifyAll()
|
||||
# so we don't have to stub out deletion events.
|
||||
self.m.UnsetStubs()
|
||||
|
||||
@utils.stack_delete_after
|
||||
def test_signal_wrong_resource(self):
|
||||
# assert that we get the correct exception when calling a
|
||||
|
||||
Reference in New Issue
Block a user