Add env storing for loaded environments
If env loaded from outer file, there is probability that this outer file will be deleted. So, if template uses some resource with resource registry env, we need to store this env in db. Change-Id: Ib0c191db2dccac6d467a9961062424bc1f924c24 Closes-bug: #1429141
This commit is contained in:
parent
42b1347b3b
commit
d8fe35eee5
@ -383,7 +383,16 @@ class ResourceRegistry(object):
|
||||
for info in sorted(matches):
|
||||
match = info.get_resource_info(resource_type,
|
||||
resource_name)
|
||||
if ((registry_type is None or isinstance(match, registry_type))):
|
||||
if registry_type is None or isinstance(match, registry_type):
|
||||
# NOTE(prazumovsky): if resource_type defined in outer env
|
||||
# there is a risk to lose it due to h-eng restarting, so
|
||||
# store it to local env (exclude ClassResourceInfo because it
|
||||
# loads from resources; TemplateResourceInfo handles by
|
||||
# template_resource module).
|
||||
if (match and not match.user_resource and
|
||||
not isinstance(info, (TemplateResourceInfo,
|
||||
ClassResourceInfo))):
|
||||
self._register_info([resource_type], info)
|
||||
return match
|
||||
|
||||
def get_class(self, resource_type, resource_name=None):
|
||||
|
@ -60,6 +60,7 @@ class TemplateResource(stack_resource.StackResource):
|
||||
'.template are supported'))
|
||||
else:
|
||||
self.template_name = tri.template_name
|
||||
self.resource_type = tri.name
|
||||
if tri.user_resource:
|
||||
self.allowed_schemes = ('http', 'https')
|
||||
else:
|
||||
@ -178,6 +179,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)
|
||||
return t_data
|
||||
if reported_excp is None:
|
||||
reported_excp = ValueError(_('Unknown error retrieving %s') %
|
||||
|
@ -263,6 +263,27 @@ class EnvironmentDuplicateTest(common.HeatTestCase):
|
||||
env.get_resource_info('OS::Test::Dummy',
|
||||
'my_fip'))
|
||||
|
||||
def test_env_register_while_get_resource_info(self):
|
||||
env_test = {u'resource_registry': {
|
||||
u'OS::Test::Dummy': self.resource_type}}
|
||||
env = environment.Environment()
|
||||
env.load(env_test)
|
||||
env.get_resource_info('OS::Test::Dummy')
|
||||
self.assertEqual({'OS::Test::Dummy': self.resource_type,
|
||||
'resources': {}},
|
||||
env.user_env_as_dict().get(
|
||||
environment_format.RESOURCE_REGISTRY))
|
||||
|
||||
env_test = {u'resource_registry': {
|
||||
u'resources': {u'test': {u'OS::Test::Dummy': self.resource_type}}}}
|
||||
env.load(env_test)
|
||||
env.get_resource_info('OS::Test::Dummy')
|
||||
self.assertEqual({u'OS::Test::Dummy': self.resource_type,
|
||||
'resources': {u'test': {u'OS::Test::Dummy':
|
||||
self.resource_type}}},
|
||||
env.user_env_as_dict().get(
|
||||
environment_format.RESOURCE_REGISTRY))
|
||||
|
||||
|
||||
class GlobalEnvLoadingTest(common.HeatTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user