From c3fa1b6db8d1abcdb9f15de064e0e2b1f6be15b6 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 7 Jul 2015 09:53:36 +1000 Subject: [PATCH] Keep the path when re-registering the template resource Since Ib0c191db2dccac6d467a9961062424bc1f924c24 we re-register a template resource in case the global environment is changed. This is fine but the path to the resource is not maintained. This patch fixes that by passing the path through to the registration function. Change-Id: I7a8ec66d0f12a12bb4e44d2eb7efd182d758fea1 --- heat/engine/environment.py | 12 ++++++----- heat/engine/resources/template_resource.py | 4 +++- heat/tests/test_environment.py | 24 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 5cf6f894b..abd115837 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -193,9 +193,11 @@ class ResourceRegistry(object): def load(self, json_snippet): self._load_registry([], json_snippet) - def register_class(self, resource_type, resource_class): - ri = ResourceInfo(self, [resource_type], resource_class) - self._register_info([resource_type], ri) + def register_class(self, resource_type, resource_class, path=None): + if path is None: + path = [resource_type] + ri = ResourceInfo(self, path, resource_class) + self._register_info(path, ri) def _load_registry(self, path, registry): for k, v in iter(registry.items()): @@ -516,8 +518,8 @@ class Environment(object): env_fmt.PARAMETER_DEFAULTS: self.param_defaults, env_fmt.ENCRYPTED_PARAM_NAMES: self.encrypted_param_names} - def register_class(self, resource_type, resource_class): - self.registry.register_class(resource_type, resource_class) + def register_class(self, resource_type, resource_class, path=None): + self.registry.register_class(resource_type, resource_class, path=path) def register_constraint(self, constraint_name, constraint): self.constraints[constraint_name] = constraint diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py index 0f633cdeb..e2c721e1a 100644 --- a/heat/engine/resources/template_resource.py +++ b/heat/engine/resources/template_resource.py @@ -73,6 +73,7 @@ class TemplateResource(stack_resource.StackResource): else: self.template_name = tri.template_name self.resource_type = tri.name + self.resource_path = tri.path if tri.user_resource: self.allowed_schemes = ('http', 'https') else: @@ -192,7 +193,8 @@ class TemplateResource(stack_resource.StackResource): if t_data is not None: self.stack.t.files[self.template_name] = t_data self.stack.t.env.register_class(self.resource_type, - self.template_name) + self.template_name, + path=self.resource_path) return t_data if reported_excp is None: reported_excp = ValueError(_('Unknown error retrieving %s') % diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index d182780f7..c78ad806b 100644 --- a/heat/tests/test_environment.py +++ b/heat/tests/test_environment.py @@ -172,6 +172,30 @@ class EnvironmentTest(common.HeatTestCase): env.get_resource_info('OS::Networking::FloatingIP', 'my_fip').value) + def test_register_with_path(self): + yaml_env = ''' + resource_registry: + test::one: a.yaml + resources: + res_x: + test::two: b.yaml +''' + + env = environment.Environment(environment_format.parse(yaml_env)) + self.assertEqual('a.yaml', env.get_resource_info('test::one').value) + self.assertEqual('b.yaml', + env.get_resource_info('test::two', 'res_x').value) + + env2 = environment.Environment() + env2.register_class('test::one', + 'a.yaml', + path=['test::one']) + env2.register_class('test::two', + 'b.yaml', + path=['resources', 'res_x', 'test::two']) + + self.assertEqual(env.user_env_as_dict(), env2.user_env_as_dict()) + def test_constraints(self): env = environment.Environment({})