diff --git a/heat/engine/environment.py b/heat/engine/environment.py index abd115837e..8e618bef00 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -439,7 +439,7 @@ class ResourceRegistry(object): return _as_dict(self._registry) - def get_types(self, support_status): + def get_types(self, cnxt=None, support_status=None): '''Return a list of valid resource types.''' def is_resource(key): @@ -451,8 +451,16 @@ class ResourceRegistry(object): cls.get_class().support_status.status == support_status.encode()) + def is_available(cls): + if cnxt is None: + return True + + return cls.get_class().is_service_available(cnxt) + return [name for name, cls in six.iteritems(self._registry) - if is_resource(name) and status_matches(cls)] + if (is_resource(name) and + status_matches(cls) and + is_available(cls))] class Environment(object): @@ -532,8 +540,8 @@ class Environment(object): def get_class(self, resource_type, resource_name=None): return self.registry.get_class(resource_type, resource_name) - def get_types(self, support_status=None): - return self.registry.get_types(support_status) + def get_types(self, cnxt=None, support_status=None): + return self.registry.get_types(cnxt, support_status) def get_resource_info(self, resource_type, resource_name=None, registry_type=None): diff --git a/heat/engine/service.py b/heat/engine/service.py index cbb97a1125..22295e6629 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -1023,7 +1023,7 @@ class EngineService(service.Service): :param cnxt: RPC context. """ - return resources.global_env().get_types(support_status) + return resources.global_env().get_types(cnxt, support_status) def list_template_versions(self, cnxt): mgr = templatem._get_template_extension_manager() diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 7f68ef73d0..4c50682c7a 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -2171,13 +2171,18 @@ class StackServiceTest(common.HeatTestCase): self.assertIn('WordPress', s['description']) self.assertIn('parameters', s) - def test_list_resource_types(self): + @mock.patch.object(res.Resource, 'is_service_available') + def test_list_resource_types(self, mock_is_service_available): + mock_is_service_available.return_value = True resources = self.eng.list_resource_types(self.ctx) self.assertIsInstance(resources, list) self.assertIn('AWS::EC2::Instance', resources) self.assertIn('AWS::RDS::DBInstance', resources) - def test_list_resource_types_deprecated(self): + @mock.patch.object(res.Resource, 'is_service_available') + def test_list_resource_types_deprecated(self, + mock_is_service_available): + mock_is_service_available.return_value = True resources = self.eng.list_resource_types(self.ctx, "DEPRECATED") self.assertEqual(set(['OS::Neutron::RouterGateway', 'OS::Heat::HARestarter', @@ -2185,7 +2190,10 @@ class StackServiceTest(common.HeatTestCase): 'OS::Heat::StructuredDeployments']), set(resources)) - def test_list_resource_types_supported(self): + @mock.patch.object(res.Resource, 'is_service_available') + def test_list_resource_types_supported(self, + mock_is_service_available): + mock_is_service_available.return_value = True resources = self.eng.list_resource_types(self.ctx, "SUPPORTED") self.assertNotIn(['OS::Neutron::RouterGateway'], resources) self.assertIn('AWS::EC2::Instance', resources) @@ -2212,6 +2220,15 @@ class StackServiceTest(common.HeatTestCase): {'version': 'c.d', 'type': 'hot'}] self.assertEqual(expected, templates) + @mock.patch.object(res.Resource, 'is_service_available') + def test_list_resource_types_unavailable( + self, + mock_is_service_available): + mock_is_service_available.return_value = False + resources = self.eng.list_resource_types(self.ctx) + # Check for an known resource, not listed + self.assertNotIn('OS::Nova::Server', resources) + def test_resource_schema(self): type_name = 'ResourceWithPropsType' expected = {