Merge "Improve error response in cfn Outputs validation"
This commit is contained in:
commit
250035317a
@ -483,18 +483,19 @@ class Stack(collections.Mapping):
|
||||
|
||||
for val in self.outputs.values():
|
||||
try:
|
||||
if isinstance(val, six.string_types):
|
||||
message = _('"Outputs" must contain '
|
||||
'a map of output maps, '
|
||||
'find a string "%s".') % val
|
||||
if not val or not val.get('Value'):
|
||||
message = _('Each Output must contain '
|
||||
'a Value key.')
|
||||
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', ''))
|
||||
function.validate(val.get('Value'))
|
||||
except AttributeError:
|
||||
message = _('Output validation error: '
|
||||
'Outputs must contain Output. '
|
||||
'Found a [%s] instead') % type(val)
|
||||
raise StackValidationFailed(message=message)
|
||||
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)
|
||||
|
||||
def requires_deferred_auth(self):
|
||||
|
@ -188,16 +188,13 @@ class Template(collections.Mapping):
|
||||
# check resources
|
||||
for res in self[self.RESOURCES].values():
|
||||
try:
|
||||
if not res.get('Type'):
|
||||
message = _('Every Resource object must '
|
||||
'contain a Type member.')
|
||||
if not res or not res.get('Type'):
|
||||
message = _('Each Resource must contain '
|
||||
'a Type key.')
|
||||
raise exception.StackValidationFailed(message=message)
|
||||
except AttributeError:
|
||||
type_res = type(res)
|
||||
if isinstance(res, unicode):
|
||||
type_res = "string"
|
||||
message = _('Resources must contain Resource. '
|
||||
'Found a [%s] instead') % type_res
|
||||
'Found a [%s] instead') % type(res)
|
||||
raise exception.StackValidationFailed(message=message)
|
||||
|
||||
|
||||
|
@ -4280,10 +4280,10 @@ class StackTest(common.HeatTestCase):
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
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))
|
||||
|
||||
def test_incorrect_outputs_cfn_wrong_data(self):
|
||||
def test_incorrect_outputs_cfn_string_data(self):
|
||||
tmpl = template_format.parse("""
|
||||
HeatTemplateFormatVersion: '2012-12-12'
|
||||
Resources:
|
||||
@ -4301,9 +4301,31 @@ class StackTest(common.HeatTestCase):
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
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))
|
||||
|
||||
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):
|
||||
tmpl = {'heat_template_version': '2013-05-23',
|
||||
'resources': {
|
||||
|
@ -1020,7 +1020,7 @@ class validateTest(common.HeatTestCase):
|
||||
engine = service.EngineService('a', 't')
|
||||
res = dict(engine.validate_template(None, t, {}))
|
||||
self.assertEqual({'Error': 'Resources must contain Resource. '
|
||||
'Found a [string] instead'},
|
||||
'Found a [%s] instead' % six.text_type},
|
||||
res)
|
||||
|
||||
def test_invalid_section_cfn(self):
|
||||
|
Loading…
Reference in New Issue
Block a user