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
This commit is contained in:
parent
4083c76675
commit
c3fa1b6db8
@ -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
|
||||
|
@ -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') %
|
||||
|
@ -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({})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user