Merge "Improve error response in cfn Outputs validation"

This commit is contained in:
Jenkins 2014-11-21 03:24:56 +00:00 committed by Gerrit Code Review
commit 250035317a
4 changed files with 41 additions and 21 deletions

View File

@ -483,18 +483,19 @@ class Stack(collections.Mapping):
for val in self.outputs.values(): for val in self.outputs.values():
try: try:
if isinstance(val, six.string_types): if not val or not val.get('Value'):
message = _('"Outputs" must contain ' message = _('Each Output must contain '
'a map of output maps, ' 'a Value key.')
'find a string "%s".') % val
raise StackValidationFailed(message=message) raise StackValidationFailed(message=message)
if not val or not val.get('Value', ''): function.validate(val.get('Value'))
msg = _('Every Output object must ' except AttributeError:
'contain a Value member.') message = _('Output validation error: '
raise StackValidationFailed(message=msg) 'Outputs must contain Output. '
function.validate(val.get('Value', '')) 'Found a [%s] instead') % type(val)
raise StackValidationFailed(message=message)
except Exception as ex: except Exception as ex:
reason = 'Output validation error: %s' % six.text_type(ex) reason = _('Output validation error: '
'%s') % six.text_type(ex)
raise StackValidationFailed(message=reason) raise StackValidationFailed(message=reason)
def requires_deferred_auth(self): def requires_deferred_auth(self):

View File

@ -188,16 +188,13 @@ class Template(collections.Mapping):
# check resources # check resources
for res in self[self.RESOURCES].values(): for res in self[self.RESOURCES].values():
try: try:
if not res.get('Type'): if not res or not res.get('Type'):
message = _('Every Resource object must ' message = _('Each Resource must contain '
'contain a Type member.') 'a Type key.')
raise exception.StackValidationFailed(message=message) raise exception.StackValidationFailed(message=message)
except AttributeError: except AttributeError:
type_res = type(res)
if isinstance(res, unicode):
type_res = "string"
message = _('Resources must contain Resource. ' message = _('Resources must contain Resource. '
'Found a [%s] instead') % type_res 'Found a [%s] instead') % type(res)
raise exception.StackValidationFailed(message=message) raise exception.StackValidationFailed(message=message)

View File

@ -4280,10 +4280,10 @@ class StackTest(common.HeatTestCase):
ex = self.assertRaises(exception.StackValidationFailed, ex = self.assertRaises(exception.StackValidationFailed,
self.stack.validate) self.stack.validate)
self.assertIn('Every Output object must contain a Value member.', self.assertIn('Each Output must contain a Value key.',
six.text_type(ex)) six.text_type(ex))
def test_incorrect_outputs_cfn_wrong_data(self): def test_incorrect_outputs_cfn_string_data(self):
tmpl = template_format.parse(""" tmpl = template_format.parse("""
HeatTemplateFormatVersion: '2012-12-12' HeatTemplateFormatVersion: '2012-12-12'
Resources: Resources:
@ -4301,9 +4301,31 @@ class StackTest(common.HeatTestCase):
ex = self.assertRaises(exception.StackValidationFailed, ex = self.assertRaises(exception.StackValidationFailed,
self.stack.validate) self.stack.validate)
self.assertIn('"Outputs" must contain a map of output maps', self.assertIn('Outputs must contain Output. '
'Found a [%s] instead' % six.text_type,
six.text_type(ex)) six.text_type(ex))
def test_incorrect_outputs_cfn_list_data(self):
tmpl = template_format.parse("""
HeatTemplateFormatVersion: '2012-12-12'
Resources:
AResource:
Type: ResourceWithPropsType
Properties:
Foo: abc
Outputs:
Resource_attr:
- Data is not what it seems
""")
self.stack = parser.Stack(self.ctx, 'stack_with_correct_outputs',
template.Template(tmpl))
ex = self.assertRaises(exception.StackValidationFailed,
self.stack.validate)
self.assertIn('Outputs must contain Output. '
'Found a [%s] instead' % type([]), six.text_type(ex))
def test_incorrect_outputs_hot_get_attr(self): def test_incorrect_outputs_hot_get_attr(self):
tmpl = {'heat_template_version': '2013-05-23', tmpl = {'heat_template_version': '2013-05-23',
'resources': { 'resources': {

View File

@ -1020,7 +1020,7 @@ class validateTest(common.HeatTestCase):
engine = service.EngineService('a', 't') engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t, {})) res = dict(engine.validate_template(None, t, {}))
self.assertEqual({'Error': 'Resources must contain Resource. ' self.assertEqual({'Error': 'Resources must contain Resource. '
'Found a [string] instead'}, 'Found a [%s] instead' % six.text_type},
res) res)
def test_invalid_section_cfn(self): def test_invalid_section_cfn(self):