Merge "Add env storing for loaded environments"

This commit is contained in:
Jenkins 2015-04-23 14:07:24 +00:00 committed by Gerrit Code Review
commit 15f813b01f
3 changed files with 34 additions and 1 deletions

View File

@ -385,7 +385,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):

View File

@ -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') %

View File

@ -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):