diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 4b7640bf5..ee9de9c38 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -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): diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py index 4e9877dff..e23df51fb 100644 --- a/heat/engine/resources/template_resource.py +++ b/heat/engine/resources/template_resource.py @@ -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') % diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index 4c08849eb..c60b4518b 100644 --- a/heat/tests/test_environment.py +++ b/heat/tests/test_environment.py @@ -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):