summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@mirantis.com>2015-02-06 22:31:44 +1000
committerCrag Wolfe <cwolfe@redhat.com>2015-11-12 03:02:27 +0000
commit2fb32b11eb32e42058d3a06848af5ed9d09129d6 (patch)
tree486d65be65c512ed47020802d68614184b862cf7
parent788b2e3a7e68cd1190baebbb99e3149c864ee3b8 (diff)
downloadheat-2fb32b11eb32e42058d3a06848af5ed9d09129d6.tar.gz
Make sure template resource's metadata is refreshed
This copies the code snippet from instance.py, which refreshes the metadata when we get a signal on a referenced resource. Note: a functional test is coming in a later commit. Closes-bug: 1418942 Change-Id: I5980c9cf4dc355b9bfa93273bc26a768ab9abdb8 (cherry picked from commit e5ffaff0b3326bcf2840f781501b9f7bb6513ccd)
-rw-r--r--heat/engine/resources/template_resource.py7
-rw-r--r--heat/tests/test_provider_template.py34
2 files changed, 41 insertions, 0 deletions
diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py
index 2543a17fc..29f0b55b9 100644
--- a/heat/engine/resources/template_resource.py
+++ b/heat/engine/resources/template_resource.py
@@ -255,6 +255,13 @@ class TemplateResource(stack_resource.StackResource):
return self.create_with_template(self.child_template(),
self.child_params())
+ def metadata_update(self, new_metadata=None):
+ '''
+ Refresh the metadata if new_metadata is None
+ '''
+ if new_metadata is None:
+ self.metadata_set(self.t.metadata())
+
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
self._generate_schema(json_snippet)
return self.update_with_template(self.child_template(),
diff --git a/heat/tests/test_provider_template.py b/heat/tests/test_provider_template.py
index 44e578e3a..21a990a29 100644
--- a/heat/tests/test_provider_template.py
+++ b/heat/tests/test_provider_template.py
@@ -443,6 +443,40 @@ class ProviderTemplateTest(HeatTestCase):
cls = env.get_class('OS::ResourceType', 'fred')
self.assertEqual(template_resource.TemplateResource, cls)
+ def test_metadata_update_called(self):
+ provider = {
+ 'HeatTemplateFormatVersion': '2012-12-12',
+ 'Parameters': {
+ 'Foo': {'Type': 'Boolean'},
+ },
+ }
+ files = {'test_resource.template': json.dumps(provider)}
+
+ class DummyResource(object):
+ support_status = support.SupportStatus()
+ properties_schema = {"Foo":
+ properties.Schema(properties.Schema.BOOLEAN)}
+ attributes_schema = {}
+
+ env = environment.Environment()
+ resource._register_class('DummyResource', DummyResource)
+ env.load({'resource_registry':
+ {'DummyResource': 'test_resource.template'}})
+ stack = parser.Stack(utils.dummy_context(), 'test_stack',
+ parser.Template(
+ {'HeatTemplateFormatVersion': '2012-12-12'},
+ files=files), env=env,
+ stack_id=str(uuid.uuid4()))
+
+ definition = rsrc_defn.ResourceDefinition('test_t_res',
+ "DummyResource",
+ {"Foo": "False"})
+ temp_res = template_resource.TemplateResource('test_t_res',
+ definition, stack)
+ temp_res.metadata_set = mock.Mock()
+ temp_res.metadata_update()
+ temp_res.metadata_set.assert_called_once_with({})
+
def test_get_template_resource_class(self):
test_templ_name = 'file:///etc/heatr/frodo.yaml'
minimal_temp = json.dumps({'HeatTemplateFormatVersion': '2012-12-12',