Merge "Don't raise error if actions are mismatched"

This commit is contained in:
Jenkins 2015-05-14 20:50:22 +00:00 committed by Gerrit Code Review
commit 3adbe6ad2b
2 changed files with 14 additions and 40 deletions

View File

@ -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)

View File

@ -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)