diff --git a/heat/engine/environment.py b/heat/engine/environment.py index bafa674be5..229806d3e3 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -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): diff --git a/heat/tests/common.py b/heat/tests/common.py index b258833584..e164289ca7 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -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, diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index febd584437..a22914eb04 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -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') diff --git a/heat/tests/test_environment.py b/heat/tests/test_environment.py index 7c620b1b06..c7d5509f3a 100644 --- a/heat/tests/test_environment.py +++ b/heat/tests/test_environment.py @@ -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):