From bd3f4cb839810bfc6eaf68b6751b7338388301c1 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 25 Jun 2015 12:10:01 +1000 Subject: [PATCH] convergence: Use the correct template when updating the resource self.t is the old template, as it is only changed after the successful update(). Change-Id: I611b6b30b11aef67755a88bf7546a338ea356135 --- heat/engine/resource.py | 4 +++- heat/tests/test_resource.py | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 1969d8208d..74d72dc99b 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -795,7 +795,9 @@ class Resource(object): given resource_data and existing resource's requires. ''' with self.lock(engine_id): - runner = scheduler.TaskRunner(self.update, self.t) + new_temp = template.Template.load(self.context, template_id) + new_res_def = new_temp.resource_definitions(self.stack)[self.name] + runner = scheduler.TaskRunner(self.update, new_res_def) runner() # update the resource db record (stored in unlock) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 839308ef0f..0329120dce 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -1436,16 +1436,27 @@ class ResourceTest(common.HeatTestCase): @mock.patch.object(resource.Resource, 'update') def test_update_convergence(self, mock_update): - tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo') + tmpl = rsrc_defn.ResourceDefinition('test_res', + 'ResourceWithPropsType') res = generic_rsrc.GenericResource('test_res', tmpl, self.stack) res.requires = [2] res._store() self._assert_resource_lock(res.id, None, None) - res.update_convergence('template_key', {(1, True): {}, - (1, True): {}}, 'engine-007') - mock_update.assert_called_once_with(res.t) - self.assertEqual('template_key', res.current_template_id) + new_temp = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { + 'test_res': {'Type': 'ResourceWithPropsType', + 'Properties': {'Foo': 'abc'}} + }}, env=self.env) + new_temp.store() + + res.update_convergence(new_temp.id, {(1, True): {}, + (1, True): {}}, 'engine-007') + + mock_update.assert_called_once_with( + new_temp.resource_definitions(self.stack)[res.name]) + self.assertEqual(new_temp.id, res.current_template_id) self.assertEqual([1, 2], res.requires) self._assert_resource_lock(res.id, None, 2)