Merge "Convergence: Fix Resource Replacement."
This commit is contained in:
commit
7130cf3f86
@ -254,7 +254,7 @@ class Resource(object):
|
||||
resource._load_data(db_res)
|
||||
return resource, stack
|
||||
|
||||
def make_replacement(self):
|
||||
def make_replacement(self, new_tmpl_id):
|
||||
# 1. create the replacement with "replaces" = self.id
|
||||
# Don't set physical_resource_id so that a create is triggered.
|
||||
rs = {'stack_id': self.stack.id,
|
||||
@ -263,14 +263,17 @@ class Resource(object):
|
||||
'needed_by': self.needed_by,
|
||||
'requires': self.requires,
|
||||
'replaces': self.id,
|
||||
'current_template_id': self.current_template_id,
|
||||
'action': self.INIT,
|
||||
'status': self.COMPLETE,
|
||||
'current_template_id': new_tmpl_id,
|
||||
'stack_name': self.stack.name}
|
||||
new_rs = resource_objects.Resource.create(self.context, rs)
|
||||
|
||||
# 2. update the current resource to be replaced_by the one above.
|
||||
rs = resource_objects.Resource.get_obj(self.context, self.id)
|
||||
self.replaced_by = new_rs.id
|
||||
rs.update_and_save({'replaced_by': self.replaced_by})
|
||||
rs.update_and_save({'status': self.COMPLETE,
|
||||
'replaced_by': self.replaced_by})
|
||||
return new_rs.id
|
||||
|
||||
def reparse(self):
|
||||
|
@ -163,7 +163,9 @@ class WorkerService(service.Service):
|
||||
try:
|
||||
check_resource_update(rsrc, tmpl.id, data, self.engine_id)
|
||||
except resource.UpdateReplace:
|
||||
new_res_id = rsrc.make_replacement()
|
||||
new_res_id = rsrc.make_replacement(tmpl.id)
|
||||
LOG.info("Replacing resource with new id %s", new_res_id)
|
||||
data = sync_point.serialize_input_data(data)
|
||||
self._rpc_client.check_resource(cnxt,
|
||||
new_res_id,
|
||||
current_traversal,
|
||||
|
@ -382,13 +382,15 @@ class ResourceTest(common.HeatTestCase):
|
||||
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
|
||||
res = generic_rsrc.GenericResource('test_res_upd', tmpl, self.stack)
|
||||
res._store()
|
||||
new_tmpl_id = 2
|
||||
self.assertIsNotNone(res.id)
|
||||
new_id = res.make_replacement()
|
||||
new_id = res.make_replacement(new_tmpl_id)
|
||||
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.nova_instance)
|
||||
self.assertEqual(new_tmpl_id, new_res.current_template_id)
|
||||
|
||||
def test_parsed_template(self):
|
||||
join_func = cfn_funcs.Join(None,
|
||||
|
Loading…
Reference in New Issue
Block a user