Merge "Fix error raising in cfn with wrong output section"

This commit is contained in:
Jenkins
2014-10-31 11:23:46 +00:00
committed by Gerrit Code Review
2 changed files with 51 additions and 2 deletions

View File

@@ -476,9 +476,17 @@ class Stack(collections.Mapping):
raise StackValidationFailed(message=result)
for val in self.outputs.values():
snippet = val.get('Value', '')
try:
function.validate(snippet)
if isinstance(val, six.string_types):
message = _('"Outputs" must contain '
'a map of output maps, '
'find a string "%s".') % val
raise StackValidationFailed(message=message)
if not val or not val.get('Value', ''):
msg = _('Every Output object must '
'contain a Value member.')
raise StackValidationFailed(message=msg)
function.validate(val.get('Value', ''))
except Exception as ex:
reason = 'Output validation error: %s' % six.text_type(ex)
raise StackValidationFailed(message=reason)

View File

@@ -4263,6 +4263,47 @@ class StackTest(common.HeatTestCase):
'(AResource Bar) is incorrect.',
six.text_type(ex))
def test_incorrect_outputs_cfn_empty_output(self):
tmpl = template_format.parse("""
HeatTemplateFormatVersion: '2012-12-12'
Resources:
AResource:
Type: ResourceWithPropsType
Properties:
Foo: abc
Outputs:
Resource_attr:
""")
self.stack = parser.Stack(self.ctx, 'stack_with_correct_outputs',
template.Template(tmpl))
ex = self.assertRaises(exception.StackValidationFailed,
self.stack.validate)
self.assertIn('Every Output object must contain a Value member.',
six.text_type(ex))
def test_incorrect_outputs_cfn_wrong_data(self):
tmpl = template_format.parse("""
HeatTemplateFormatVersion: '2012-12-12'
Resources:
AResource:
Type: ResourceWithPropsType
Properties:
Foo: abc
Outputs:
Resource_attr:
This is wrong data
""")
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 a map of output maps',
six.text_type(ex))
def test_incorrect_outputs_hot_get_attr(self):
tmpl = {'heat_template_version': '2013-05-23',
'resources': {