Search resource type based on version

Adds the filtering support to resource type based on
the type version match.

implements blueprint heat-resource-type-search

Change-Id: Iea626c762dfd6ad53e034ebaf7cdb6e3795694d0
This commit is contained in:
Kanagaraj Manickam 2015-08-20 12:33:04 +05:30
parent c79bd02e28
commit 7153d99f6c
4 changed files with 32 additions and 2 deletions

View File

@ -442,7 +442,8 @@ class ResourceRegistry(object):
def get_types(self,
cnxt=None,
support_status=None,
type_name=None):
type_name=None,
version=None):
'''Return a list of valid resource types.'''
# validate the support status
@ -488,13 +489,18 @@ class ResourceRegistry(object):
except: # noqa
return False
def version_matches(cls):
return (version is None or
cls.get_class().support_status.version == version)
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
not_hidden_matches(cls))]
not_hidden_matches(cls) and
version_matches(cls))]
class Environment(object):

View File

@ -177,6 +177,8 @@ class HeatTestCase(testscenarios.WithScenarios,
generic_rsrc.DynamicSchemaResource)
resource._register_class('ResourceTypeUnSupportedLiberty',
generic_rsrc.ResourceTypeUnSupportedLiberty)
resource._register_class('ResourceTypeSupportedKilo',
generic_rsrc.ResourceTypeSupportedKilo)
def patchobject(self, obj, attr, **kwargs):
mockfixture = self.useFixture(mockpatch.PatchObject(obj, attr,

View File

@ -301,3 +301,8 @@ class ResourceTypeUnSupportedLiberty(GenericResource):
support_status = support.SupportStatus(
version='5.0.0',
status=support.UNSUPPORTED)
class ResourceTypeSupportedKilo(GenericResource):
support_status = support.SupportStatus(
version='2015.1')

View File

@ -779,6 +779,23 @@ class ResourceRegistryTest(common.HeatTestCase):
types = registry.get_types(type_name="r'[^\+]'")
self.assertEqual([], types)
def test_list_type_with_version(self):
registry = resources.global_env().registry
types = registry.get_types(version='5.0.0')
self.assertIn('ResourceTypeUnSupportedLiberty', types)
self.assertNotIn('ResourceTypeSupportedKilo', types)
def test_list_type_with_version_none(self):
registry = resources.global_env().registry
types = registry.get_types(version=None)
self.assertIn('ResourceTypeUnSupportedLiberty', types)
self.assertIn('ResourceTypeSupportedKilo', types)
def test_list_type_with_version_invalid(self):
registry = resources.global_env().registry
types = registry.get_types(version='invalid')
self.assertEqual([], types)
class HookMatchTest(common.HeatTestCase):