From ef6ec7b6520bfb50191b51e338aa8e90ebcaa495 Mon Sep 17 00:00:00 2001 From: Sergey Kraynev Date: Wed, 13 May 2015 05:13:30 -0400 Subject: [PATCH] Don't raise error if actions are mismatched Heat stack_resource has similar check for actions, but currently it does not raise error if actions are different. OS::Heat::Stack resource is similar on stack_resource so it has same issue, when resources require some time to change state/action and it should not be so strict. Change-Id: I20c2d3f8900b7393b1f551384805a35d5ef6497d Closes-Bug: #1454589 --- .../resources/openstack/heat/remote_stack.py | 33 ++++++++----------- heat/tests/test_remote_stack.py | 21 ------------ 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 25242e1ce8..9ea61cd253 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -217,28 +217,23 @@ class RemoteStack(resource.Resource): def _check_action_complete(self, action): stack = self.heat().stacks.get(stack_id=self.resource_id) - if stack.action == action: - if stack.status == self.IN_PROGRESS: - return False - elif stack.status == self.COMPLETE: - return True - elif stack.status == self.FAILED: - raise resource.ResourceInError( - resource_status=stack.stack_status, - status_reason=stack.stack_status_reason) - else: - # Note: this should never happen, so it really means that - # the resource/engine is in serious problem if it happens. - raise resource.ResourceUnknownStatus( - resource_status=stack.stack_status, - status_reason=stack.stack_status_reason) + if stack.action != action: + return False + + if stack.status == self.IN_PROGRESS: + return False + elif stack.status == self.COMPLETE: + return True + elif stack.status == self.FAILED: + raise resource.ResourceInError( + resource_status=stack.stack_status, + status_reason=stack.stack_status_reason) else: - msg = _('Resource action mismatch detected: expected=%(expected)s ' - 'actual=%(actual)s') % dict(expected=action, - actual=stack.action) + # Note: this should never happen, so it really means that + # the resource/engine is in serious problem if it happens. raise resource.ResourceUnknownStatus( resource_status=stack.stack_status, - status_reason=msg) + status_reason=stack.stack_status_reason) def check_create_complete(self, *args): return self._check_action_complete(action=self.CREATE) diff --git a/heat/tests/test_remote_stack.py b/heat/tests/test_remote_stack.py index f0168ad534..5e2045a6c3 100644 --- a/heat/tests/test_remote_stack.py +++ b/heat/tests/test_remote_stack.py @@ -593,24 +593,3 @@ class RemoteStackTest(tests_common.HeatTestCase): self.heat.stacks.get = mock.MagicMock(side_effect=side_effect) scheduler.TaskRunner(rsrc.update, update_snippet)() self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state) - - def test_stack_status_error(self): - returns = [get_stack(stack_status='DELETE_IN_PROGRESS'), - get_stack(stack_status='UPDATE_COMPLETE')] - - def side_effect_d(*args, **kwargs): - return returns.pop(0) - - rsrc = self.create_remote_stack() - - self.heat.stacks.get = mock.MagicMock(side_effect=side_effect_d) - self.heat.stacks.delete = mock.MagicMock() - remote_stack_id = rsrc.resource_id - error = self.assertRaises(exception.ResourceFailure, - scheduler.TaskRunner(rsrc.delete)) - reason = ('Resource action mismatch detected: expected=DELETE ' - 'actual=UPDATE') - error_msg = ('ResourceUnknownStatus: Resource failed - Unknown ' - 'status UPDATE_COMPLETE due to "%s"') % reason - self.assertEqual(error_msg, six.text_type(error)) - self.heat.stacks.delete.assert_called_with(stack_id=remote_stack_id)