Missing template file on update fails silently

When the template file for a template/facade/provider resource is
not found in the new files list when doing a stack update, Heat
silently falls back to using the existing template (i.e. so no
change will be made).
The cause is that the update code shares the same code path for
obtaining the template as the init code. The init code needs to
have a fallback, so that loading the (parent) stack never fails,
however in the update case it is undesirable.

Change-Id: Id12b63d9f04caba8e9325aed0ee2acf51ffe0c4c
Closes-Bug: #1452520
This commit is contained in:
Rico Lin 2015-06-17 12:54:56 +08:00
parent 3b2d22c052
commit 0c83c6f5ed
2 changed files with 50 additions and 0 deletions

View File

@ -181,6 +181,8 @@ class TemplateResource(stack_resource.StackResource):
t_data = self.get_template_file(self.template_name,
self.allowed_schemes)
except exception.TemplateNotFound as err:
if self.action == self.UPDATE:
raise
reported_excp = err
if t_data is None:

View File

@ -813,6 +813,54 @@ class ProviderTemplateTest(common.HeatTestCase):
self.m.VerifyAll()
class TemplateDataTest(common.HeatTestCase):
def setUp(self):
super(TemplateDataTest, self).setUp()
files = {}
self.ctx = utils.dummy_context()
class DummyResource(object):
support_status = support.SupportStatus()
properties_schema = {"Foo":
properties.Schema(properties.Schema.STRING,
required=True)}
attributes_schema = {}
env = environment.Environment()
resource._register_class('DummyResource', DummyResource)
env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}})
self.stack = parser.Stack(self.ctx, 'test_stack',
template.Template(empty_template,
files=files,
env=env),
stack_id=str(uuid.uuid4()))
self.defn = rsrc_defn.ResourceDefinition('test_t_res',
"DummyResource",
{"Foo": "bar"})
self.res = template_resource.TemplateResource('test_t_res',
self.defn, self.stack)
def test_template_data_in_update_without_template_file(self):
self.res.action = self.res.UPDATE
self.res.nested = mock.MagicMock()
self.res.get_template_file = mock.Mock(
side_effect=exception.TemplateNotFound(
message='test_resource.template'))
self.assertRaises(exception.TemplateNotFound, self.res.template_data)
def test_template_data_in_create_without_template_file(self):
self.res.action = self.res.CREATE
self.res.nested = mock.MagicMock()
self.res.get_template_file = mock.Mock(
side_effect=exception.TemplateNotFound(
message='test_resource.template'))
self.assertEqual(self.res.template_data(), '{}')
class TemplateResourceCrudTest(common.HeatTestCase):
provider = {
'HeatTemplateFormatVersion': '2012-12-12',