diff --git a/heat/engine/environment.py b/heat/engine/environment.py index 38519fdd44..bafa674be5 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -16,6 +16,7 @@ import fnmatch import glob import itertools import os.path +import re import warnings from oslo_config import cfg @@ -438,7 +439,10 @@ class ResourceRegistry(object): return _as_dict(self._registry) - def get_types(self, cnxt=None, support_status=None): + def get_types(self, + cnxt=None, + support_status=None, + type_name=None): '''Return a list of valid resource types.''' # validate the support status @@ -478,8 +482,15 @@ class ResourceRegistry(object): enforcer = policy.ResourceEnforcer() + def name_matches(name): + try: + return type_name is None or re.match(type_name, name) + except: # noqa + return False + return [name for name, cls in six.iteritems(self._registry) if (is_resource(name) and + name_matches(name) and status_matches(cls) and is_available(cls) and is_allowed(enforcer, name) and diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index 93b0c697cd..7c620b1b06 100644 --- a/heat/tests/test_environment.py +++ b/heat/tests/test_environment.py @@ -762,6 +762,23 @@ class ResourceRegistryTest(common.HeatTestCase): self.assertIn('ResourceTypeUnSupportedLiberty', types) self.assertIn('GenericResourceType', types) + def test_list_type_with_name(self): + registry = resources.global_env().registry + types = registry.get_types(type_name='ResourceType*') + self.assertIn('ResourceTypeUnSupportedLiberty', types) + self.assertNotIn('GenericResourceType', types) + + def test_list_type_with_name_none(self): + registry = resources.global_env().registry + types = registry.get_types(type_name=None) + self.assertIn('ResourceTypeUnSupportedLiberty', types) + self.assertIn('GenericResourceType', types) + + def test_list_type_with_invalid_type_name(self): + registry = resources.global_env().registry + types = registry.get_types(type_name="r'[^\+]'") + self.assertEqual([], types) + class HookMatchTest(common.HeatTestCase):