diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 337c3e550..6f7fd3579 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -205,6 +205,9 @@ class RemoteStack(resource.Resource): return defn.freeze(properties=props) + def handle_check(self): + self.heat().actions.check(stack_id=self.resource_id) + def _needs_update(self, after, before, after_props, before_props, prev_resource): # Always issue an update to the remote stack and let the individual @@ -280,6 +283,9 @@ class RemoteStack(resource.Resource): def check_snapshot_complete(self, *args): return self._check_action_complete(action=self.SNAPSHOT) + def check_check_complete(self, *args): + return self._check_action_complete(action=self.CHECK) + def _resolve_attribute(self, name): try: stack = self.heat().stacks.get(stack_id=self.resource_id) diff --git a/heat/tests/test_remote_stack.py b/heat/tests/test_remote_stack.py index f238bea20..0ad7323b6 100644 --- a/heat/tests/test_remote_stack.py +++ b/heat/tests/test_remote_stack.py @@ -457,6 +457,36 @@ class RemoteStackTest(tests_common.HeatTestCase): self.assertEqual((parent.RESTORE, parent.COMPLETE), parent.state) + def test_check(self): + stacks = [get_stack(stack_status='CHECK_IN_PROGRESS'), + get_stack(stack_status='CHECK_COMPLETE')] + + rsrc = self.create_remote_stack() + + self.heat.stacks.get = mock.MagicMock(side_effect=stacks) + self.heat.actions.check = mock.MagicMock() + scheduler.TaskRunner(rsrc.check)() + + self.assertEqual((rsrc.CHECK, rsrc.COMPLETE), rsrc.state) + self.heat.actions.check.assert_called_with(stack_id=rsrc.resource_id) + + def test_check_failed(self): + returns = [get_stack(stack_status='CHECK_IN_PROGRESS'), + get_stack(stack_status='CHECK_FAILED', + stack_status_reason='Remote stack check failed')] + + rsrc = self.create_remote_stack() + + self.heat.stacks.get = mock.MagicMock(side_effect=returns) + self.heat.actions.resume = mock.MagicMock() + error = self.assertRaises(exception.ResourceFailure, + scheduler.TaskRunner(rsrc.check)) + error_msg = ('ResourceInError: Went to status CHECK_FAILED due to ' + '"Remote stack check failed"') + self.assertEqual(error_msg, six.text_type(error)) + self.assertEqual((rsrc.CHECK, rsrc.FAILED), rsrc.state) + self.heat.actions.check.assert_called_with(stack_id=rsrc.resource_id) + def test_resume(self): stacks = [get_stack(stack_status='RESUME_IN_PROGRESS'), get_stack(stack_status='RESUME_COMPLETE')]