From afd538664f5041df1070e5e8b42b5bab979dc9f7 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 13 Aug 2014 13:29:42 +1200 Subject: [PATCH] Use new template for resource update reparse If the stack-update is switching from pre-HOT to HOT then the update will fail because the functions are resolved using the pre-HOT template. This change uses the new template for the reparse instead of the old one. It fixes the issue observed but any other effects are unknown. Change-Id: I2f749375ccd7ca917387ef96856b1fc248c8567b Closes-Bug: #1356097 --- heat/engine/update.py | 4 +++- heat/tests/test_parser.py | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/heat/engine/update.py b/heat/engine/update.py index 335b66870..08afe83e4 100644 --- a/heat/engine/update.py +++ b/heat/engine/update.py @@ -144,8 +144,10 @@ class StackUpdate(object): # Note the new resource snippet is resolved in the context # of the existing stack (which is the stack being updated) + # but with the template of the new stack (in case the update + # is switching template implementations) new_snippet = new_res.t.reparse(self.existing_stack, - self.existing_stack.t) + self.new_stack.t) return existing_res.update(new_snippet, existing_snippet, prev_resource=prev_res) diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 613ce5f9c..0e4c0f27a 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -2967,6 +2967,50 @@ class StackTest(HeatTestCase): self.assertEqual(resource_id, self.stack['AResource'].id) + def test_update_template_format_version(self): + tmpl = { + 'HeatTemplateFormatVersion': '2012-12-12', + 'Parameters': { + 'AParam': {'Type': 'String', 'Default': 'abc'}}, + 'Resources': { + 'AResource': { + 'Type': 'ResourceWithPropsType', + 'Properties': {'Foo': {'Ref': 'AParam'}} + }, + } + } + + self.stack = parser.Stack(self.ctx, 'update_test_stack', + template.Template(tmpl)) + self.stack.store() + self.stack.create() + self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), + self.stack.state) + self.assertEqual('abc', self.stack['AResource'].properties['Foo']) + + tmpl2 = { + 'heat_template_version': '2013-05-23', + 'parameters': { + 'AParam': {'type': 'string', 'default': 'foo'}}, + 'resources': { + 'AResource': { + 'type': 'ResourceWithPropsType', + 'properties': {'Foo': {'get_param': 'AParam'}} + } + } + } + + updated_stack = parser.Stack(self.ctx, 'updated_stack', + template.Template(tmpl2)) + + self.m.ReplayAll() + + self.stack.update(updated_stack) + self.assertEqual((parser.Stack.UPDATE, parser.Stack.COMPLETE), + self.stack.state) + self.assertEqual('foo', self.stack['AResource'].properties['Foo']) + self.m.VerifyAll() + def test_stack_create_timeout(self): self.m.StubOutWithMock(scheduler.DependencyTaskGroup, '__call__') self.m.StubOutWithMock(scheduler, 'wallclock')