From 9468e87e417f3b0d2fde5979fc4eb5b5027a4970 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 2 Apr 2015 09:14:39 +1000 Subject: [PATCH] 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 --- heat/engine/resource.py | 4 ++-- heat/tests/test_resource.py | 4 ++++ heat_integrationtests/functional/test_autoscaling.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 03a3065b9..e1174dfa6 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -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) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 746293135..7185c575d 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -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') diff --git a/heat_integrationtests/functional/test_autoscaling.py b/heat_integrationtests/functional/test_autoscaling.py index cbb0fec23..c1d6d3058 100644 --- a/heat_integrationtests/functional/test_autoscaling.py +++ b/heat_integrationtests/functional/test_autoscaling.py @@ -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.