Merge "Keep the path when re-registering the template resource"
This commit is contained in:
commit
887be1716a
@ -193,9 +193,11 @@ class ResourceRegistry(object):
|
|||||||
def load(self, json_snippet):
|
def load(self, json_snippet):
|
||||||
self._load_registry([], json_snippet)
|
self._load_registry([], json_snippet)
|
||||||
|
|
||||||
def register_class(self, resource_type, resource_class):
|
def register_class(self, resource_type, resource_class, path=None):
|
||||||
ri = ResourceInfo(self, [resource_type], resource_class)
|
if path is None:
|
||||||
self._register_info([resource_type], ri)
|
path = [resource_type]
|
||||||
|
ri = ResourceInfo(self, path, resource_class)
|
||||||
|
self._register_info(path, ri)
|
||||||
|
|
||||||
def _load_registry(self, path, registry):
|
def _load_registry(self, path, registry):
|
||||||
for k, v in iter(registry.items()):
|
for k, v in iter(registry.items()):
|
||||||
@ -516,8 +518,8 @@ class Environment(object):
|
|||||||
env_fmt.PARAMETER_DEFAULTS: self.param_defaults,
|
env_fmt.PARAMETER_DEFAULTS: self.param_defaults,
|
||||||
env_fmt.ENCRYPTED_PARAM_NAMES: self.encrypted_param_names}
|
env_fmt.ENCRYPTED_PARAM_NAMES: self.encrypted_param_names}
|
||||||
|
|
||||||
def register_class(self, resource_type, resource_class):
|
def register_class(self, resource_type, resource_class, path=None):
|
||||||
self.registry.register_class(resource_type, resource_class)
|
self.registry.register_class(resource_type, resource_class, path=path)
|
||||||
|
|
||||||
def register_constraint(self, constraint_name, constraint):
|
def register_constraint(self, constraint_name, constraint):
|
||||||
self.constraints[constraint_name] = constraint
|
self.constraints[constraint_name] = constraint
|
||||||
|
@ -73,6 +73,7 @@ class TemplateResource(stack_resource.StackResource):
|
|||||||
else:
|
else:
|
||||||
self.template_name = tri.template_name
|
self.template_name = tri.template_name
|
||||||
self.resource_type = tri.name
|
self.resource_type = tri.name
|
||||||
|
self.resource_path = tri.path
|
||||||
if tri.user_resource:
|
if tri.user_resource:
|
||||||
self.allowed_schemes = ('http', 'https')
|
self.allowed_schemes = ('http', 'https')
|
||||||
else:
|
else:
|
||||||
@ -192,7 +193,8 @@ class TemplateResource(stack_resource.StackResource):
|
|||||||
if t_data is not None:
|
if t_data is not None:
|
||||||
self.stack.t.files[self.template_name] = t_data
|
self.stack.t.files[self.template_name] = t_data
|
||||||
self.stack.t.env.register_class(self.resource_type,
|
self.stack.t.env.register_class(self.resource_type,
|
||||||
self.template_name)
|
self.template_name,
|
||||||
|
path=self.resource_path)
|
||||||
return t_data
|
return t_data
|
||||||
if reported_excp is None:
|
if reported_excp is None:
|
||||||
reported_excp = ValueError(_('Unknown error retrieving %s') %
|
reported_excp = ValueError(_('Unknown error retrieving %s') %
|
||||||
|
@ -172,6 +172,30 @@ class EnvironmentTest(common.HeatTestCase):
|
|||||||
env.get_resource_info('OS::Networking::FloatingIP',
|
env.get_resource_info('OS::Networking::FloatingIP',
|
||||||
'my_fip').value)
|
'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):
|
def test_constraints(self):
|
||||||
env = environment.Environment({})
|
env = environment.Environment({})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user