Browse Source

Merge "Create replacement resources with correct requires"

changes/75/568775/1
Zuul 4 years ago committed by Gerrit Code Review
parent
commit
7206d88869
  1. 6
      heat/engine/check_resource.py
  2. 4
      heat/engine/resource.py
  3. 3
      heat/tests/engine/test_check_resource.py
  4. 4
      heat/tests/test_resource.py

6
heat/engine/check_resource.py

@ -134,11 +134,11 @@ class CheckResource(object):
self._handle_failure(cnxt, stack, failure_reason)
def _handle_resource_replacement(self, cnxt,
current_traversal, new_tmpl_id,
current_traversal, new_tmpl_id, requires,
rsrc, stack, adopt_stack_data):
"""Create a replacement resource and trigger a check on it."""
try:
new_res_id = rsrc.make_replacement(new_tmpl_id)
new_res_id = rsrc.make_replacement(new_tmpl_id, requires)
except exception.UpdateInProgress:
LOG.info("No replacement created - "
"resource already locked by new traversal")
@ -170,7 +170,7 @@ class CheckResource(object):
stack, self.msg_queue)
except resource.UpdateReplace:
self._handle_resource_replacement(cnxt, current_traversal,
tmpl.id,
tmpl.id, requires,
rsrc, stack,
adopt_stack_data)
return False

4
heat/engine/resource.py

@ -378,7 +378,7 @@ class Resource(status.ResourceStatus):
curr_stack.defn = latest_stk_defn
return resource, initial_stk_defn, curr_stack
def make_replacement(self, new_tmpl_id):
def make_replacement(self, new_tmpl_id, requires):
"""Create a replacement resource in the database.
Returns the DB ID of the new resource, or None if the new resource
@ -392,7 +392,7 @@ class Resource(status.ResourceStatus):
'name': self.name,
'rsrc_prop_data_id': None,
'needed_by': self.needed_by,
'requires': self.requires,
'requires': list(requires),
'replaces': self.id,
'action': self.INIT,
'status': self.COMPLETE,

3
heat/tests/engine/test_check_resource.py

@ -368,7 +368,8 @@ class CheckWorkflowUpdateTest(common.HeatTestCase):
# lets say C is update-replaced
is_update = True
trav_id = self.stack.current_traversal
replacementC_id = resC.make_replacement(self.stack.t.id)
replacementC_id = resC.make_replacement(self.stack.t.id,
set(resC.requires))
replacementC, stack, _ = resource.Resource.load(self.ctx,
replacementC_id,
trav_id,

4
heat/tests/test_resource.py

@ -712,13 +712,15 @@ class ResourceTest(common.HeatTestCase):
res.store()
new_tmpl_id = 2
self.assertIsNotNone(res.id)
new_id = res.make_replacement(new_tmpl_id)
new_requires = {1, 2, 4}
new_id = res.make_replacement(new_tmpl_id, new_requires)
new_res = resource_objects.Resource.get_obj(res.context, new_id)
self.assertEqual(new_id, res.replaced_by)
self.assertEqual(res.id, new_res.replaces)
self.assertIsNone(new_res.physical_resource_id)
self.assertEqual(new_tmpl_id, new_res.current_template_id)
self.assertItemsEqual(list(new_requires), new_res.requires)
def test_metadata_default(self):
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')

Loading…
Cancel
Save