Validate that resource type is a string

Raises a proper validation error when a non-string resource type is passed.

Change-Id: I1c84ee2bb1c7ff78802119e3321998b9d6487b2f
Closes-Bug: #1298548
This commit is contained in:
Thomas Herve 2014-03-27 19:47:57 +01:00
parent 29827230aa
commit 426fb774b8
2 changed files with 12 additions and 0 deletions

View File

@ -288,6 +288,9 @@ class ResourceRegistry(object):
msg = _('Non-empty resource type is required '
'for resource "%s"') % resource_name
raise exception.StackValidationFailed(message=msg)
elif not isinstance(resource_type, basestring):
msg = _('Resource "%s" type is not a string') % resource_name
raise exception.StackValidationFailed(message=msg)
info = self.get_resource_info(resource_type,
resource_name=resource_name)

View File

@ -84,6 +84,15 @@ class ResourceTest(HeatTestCase):
snippet, self.stack)
self.assertIn(_('Resource "%s" has no type') % resource_name, str(ex))
def test_resource_wrong_type(self):
snippet = {'Type': {}}
resource_name = 'aresource'
ex = self.assertRaises(exception.StackValidationFailed,
resource.Resource, resource_name,
snippet, self.stack)
self.assertIn(_('Resource "%s" type is not a string') % resource_name,
str(ex))
def test_resource_missed_type(self):
snippet = {'not-a-Type': 'GenericResourceType'}
resource_name = 'aresource'