Browse Source

Create replacement resources with correct requires

When we create a replacement resource, do so with the correct requires list
that it will ultimately have, instead of a copy of the old resource's
requires.

This will happen anyway when Resource.create_convergence() is actually
called (which is on the other end of an RPC message, so it may not actually
happen if another transition starts), but this makes it consistent from the
start.

Change-Id: Idf75a55be8d75e55c893ec1fb6ee3704f46bdc4f
changes/70/486270/10
Zane Bitter 5 years ago
parent
commit
ebfe225e41
  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

@ -110,11 +110,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")
@ -145,7 +145,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

@ -346,7 +346,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

@ -715,13 +715,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