Support check for remote stack

Support check action for OS::Heat::Stack.

Change-Id: I46dcc4c624e15b4451ebf2d751c6da06fcf931e4
Blueprint: support-actions-for-remote-stack
This commit is contained in:
huangtianhua 2015-06-05 15:52:20 +08:00
parent eaaa717fed
commit 33b873906a
2 changed files with 36 additions and 0 deletions

View File

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

View File

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