Validate support_status while searching resource registry
Validates the resource_type's support_status when it is searched from global ResourceRegistry. This saves user from searching for invalid support status. implements blueprint heat-resource-type-search Change-Id: I620ead91b024b369e4f2d8971f1190da61cfc0b2
This commit is contained in:
parent
2dbcd9064d
commit
719a043854
@ -441,6 +441,13 @@ class ResourceRegistry(object):
|
||||
def get_types(self, cnxt=None, support_status=None):
|
||||
'''Return a list of valid resource types.'''
|
||||
|
||||
# validate the support status
|
||||
if support_status is not None and not support.is_valid_status(
|
||||
support_status):
|
||||
msg = (_('Invalid support status and should be one of %s') %
|
||||
six.text_type(support.SUPPORT_STATUSES))
|
||||
raise exception.Invalid(reason=msg)
|
||||
|
||||
def is_resource(key):
|
||||
return isinstance(self._registry[key], (ClassResourceInfo,
|
||||
TemplateResourceInfo))
|
||||
|
@ -57,3 +57,7 @@ class SupportStatus(object):
|
||||
'version': self.version,
|
||||
'previous_status': self.previous_status.to_dict()
|
||||
if self.previous_status is not None else None}
|
||||
|
||||
|
||||
def is_valid_status(status):
|
||||
return status in SUPPORT_STATUSES
|
||||
|
@ -175,6 +175,8 @@ class HeatTestCase(testscenarios.WithScenarios,
|
||||
generic_rsrc.ResourceWithRestoreType)
|
||||
resource._register_class('DynamicSchemaResource',
|
||||
generic_rsrc.DynamicSchemaResource)
|
||||
resource._register_class('ResourceTypeUnSupportedLiberty',
|
||||
generic_rsrc.ResourceTypeUnSupportedLiberty)
|
||||
|
||||
def patchobject(self, obj, attr, **kwargs):
|
||||
mockfixture = self.useFixture(mockpatch.PatchObject(obj, attr,
|
||||
|
@ -23,7 +23,7 @@ from heat.engine import resource
|
||||
from heat.engine.resources import signal_responder
|
||||
from heat.engine.resources import stack_resource
|
||||
from heat.engine.resources import stack_user
|
||||
|
||||
from heat.engine import support
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -295,3 +295,9 @@ class DynamicSchemaResource(resource.Resource):
|
||||
return "dynamic_attribute"
|
||||
else:
|
||||
raise KeyError()
|
||||
|
||||
|
||||
class ResourceTypeUnSupportedLiberty(GenericResource):
|
||||
support_status = support.SupportStatus(
|
||||
version='5.0.0',
|
||||
status=support.UNSUPPORTED)
|
||||
|
@ -25,9 +25,11 @@ from heat.engine import environment
|
||||
from heat.engine import resources
|
||||
from heat.engine.resources.aws.ec2 import instance
|
||||
from heat.engine.resources.openstack.nova import server
|
||||
from heat.engine import support
|
||||
from heat.tests import common
|
||||
from heat.tests import generic_resource
|
||||
|
||||
|
||||
cfg.CONF.import_opt('environment_dir', 'heat.common.config')
|
||||
|
||||
|
||||
@ -730,6 +732,36 @@ class ResourceRegistryTest(common.HeatTestCase):
|
||||
registry.load, {'resources': resources})
|
||||
self.assertEqual(msg, six.text_type(ex))
|
||||
|
||||
def test_list_type_validation_invalid_support_status(self):
|
||||
registry = environment.ResourceRegistry(None, {})
|
||||
|
||||
ex = self.assertRaises(exception.Invalid,
|
||||
registry.get_types,
|
||||
support_status='junk')
|
||||
msg = ('Invalid support status and should be one of %s' %
|
||||
six.text_type(support.SUPPORT_STATUSES))
|
||||
|
||||
self.assertIn(msg, ex.message)
|
||||
|
||||
def test_list_type_validation_valid_support_status(self):
|
||||
registry = environment.ResourceRegistry(None, {})
|
||||
|
||||
for status in support.SUPPORT_STATUSES:
|
||||
self.assertEqual([],
|
||||
registry.get_types(support_status=status))
|
||||
|
||||
def test_list_type_find_by_status(self):
|
||||
registry = resources.global_env().registry
|
||||
types = registry.get_types(support_status=support.UNSUPPORTED)
|
||||
self.assertIn('ResourceTypeUnSupportedLiberty', types)
|
||||
self.assertNotIn('GenericResourceType', types)
|
||||
|
||||
def test_list_type_find_by_status_none(self):
|
||||
registry = resources.global_env().registry
|
||||
types = registry.get_types(support_status=None)
|
||||
self.assertIn('ResourceTypeUnSupportedLiberty', types)
|
||||
self.assertIn('GenericResourceType', types)
|
||||
|
||||
|
||||
class HookMatchTest(common.HeatTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user