Merge "Search based on the resource type name"
This commit is contained in:
commit
c79bd02e28
@ -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
|
||||
|
@ -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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user