Create an event when signalling fails

- otherwise it is hard to know that signalling happened and failed
- remove the LOG.exception() - doesn't seem like a programming error.
- don't change the resource action/state
- this makes a functional test much more reliable

Change-Id: I84c73b06bade4dfcadba240eb3dddac698194acf
Partial-bug: #1334333
This commit is contained in:
Angus Salkeld 2015-04-02 09:14:39 +10:00
parent 1eae9e6019
commit 9468e87e41
3 changed files with 12 additions and 2 deletions

View File

@ -1108,8 +1108,8 @@ class Resource(object):
handler is implemented.
'''
if self.action in (self.SUSPEND, self.DELETE):
LOG.exception(_LE('Cannot signal resource '
'during %s'), self.action)
self._add_event(self.action, self.status,
'Cannot signal resource during %s' % self.action)
ex = Exception(_('Cannot signal resource during %s') % self.action)
raise exception.ResourceFailure(ex, self)

View File

@ -131,10 +131,14 @@ class ResourceTest(common.HeatTestCase):
for action in actions:
for status in res.STATUSES:
res.state_set(action, status)
ev = self.patchobject(res, '_add_event')
ex = self.assertRaises(exception.ResourceFailure,
res.signal)
self.assertEqual('Exception: Cannot signal resource during '
'%s' % action, six.text_type(ex))
ev.assert_called_with(
action, status,
'Cannot signal resource during %s' % action)
def test_resource_str_repr_stack_id_resource_id(self):
tmpl = rsrc_defn.ResourceDefinition('test_res_str_repr', 'Foo')

View File

@ -742,6 +742,12 @@ outputs:
# Send a signal and confirm nothing happened.
self.client.resources.signal(stack_identifier, 'ScaleUpPolicy')
ev = self.wait_for_event_with_reason(
stack_identifier,
reason='Cannot signal resource during SUSPEND',
rsrc_name='ScaleUpPolicy')
self.assertEqual('SUSPEND_COMPLETE', ev[0].resource_status)
# still SUSPEND_COMPLETE (not gone to UPDATE_COMPLETE)
self._wait_for_stack_status(nested_ident, 'SUSPEND_COMPLETE')
# still 2 instances.