Merge "StackResource/RemoteStack replacement"

This commit is contained in:
Jenkins 2016-02-27 04:32:23 +00:00 committed by Gerrit Code Review
commit 6ac4526e66
4 changed files with 42 additions and 0 deletions

View File

@ -214,6 +214,11 @@ class RemoteStack(resource.Resource):
def _needs_update(self, after, before, after_props, before_props,
prev_resource, check_init_complete=True):
# If resource is in CHECK_FAILED state, raise UpdateReplace
# to replace the failed stack.
if self.state == (self.CHECK, self.FAILED):
raise exception.UpdateReplace(self)
# Always issue an update to the remote stack and let the individual
# resources in it decide if they need updating.
return True

View File

@ -94,6 +94,11 @@ class StackResource(resource.Resource):
if self.nested() is None and self.status == self.FAILED:
raise exception.UpdateReplace(self)
# If stack resource is in CHECK_FAILED state, raise UpdateReplace
# to replace the failed stack.
if self.state == (self.CHECK, self.FAILED):
raise exception.UpdateReplace(self)
if (check_init_complete and
self.nested() is None and
self.action == self.INIT and self.status == self.COMPLETE):

View File

@ -678,3 +678,14 @@ class RemoteStackTest(tests_common.HeatTestCase):
stack = utils.parse_stack(t, cache_data=cache_data)
rsrc = stack['remote_stack']
self.assertEqual('convg_xyz', rsrc.FnGetRefId())
def test_update_in_check_failed_state(self):
rsrc = self.create_remote_stack()
rsrc.state_set(rsrc.CHECK, rsrc.FAILED)
props = copy.deepcopy(rsrc.parsed_template()['Properties'])
update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
rsrc.type(),
props)
self.assertRaises(exception.UpdateReplace,
scheduler.TaskRunner(rsrc.update, update_snippet))

View File

@ -580,6 +580,27 @@ class StackResourceTest(StackResourceBaseTest):
self.parent_resource.properties,
self.parent_resource)
def test_need_update_in_check_failed_state_for_nested_resource(self):
"""Test the resource should need replacement.
The resource in check_failed state should need update with
UpdateReplace.
"""
self.parent_resource.state_set(self.parent_resource.CHECK,
self.parent_resource.FAILED)
self.nested = mock.MagicMock()
self.nested.name = 'nested-stack'
self.parent_resource.nested = mock.MagicMock(return_value=self.nested)
self.parent_resource._nested = self.nested
self.assertRaises(exception.UpdateReplace,
self.parent_resource._needs_update,
self.parent_resource.t,
self.parent_resource.t,
self.parent_resource.properties,
self.parent_resource.properties,
self.parent_resource)
class StackResourceLimitTest(StackResourceBaseTest):
scenarios = [