Handle invalid depends field

Raise a proper error when something wrong is passed in a depends_on
field.

Change-Id: I9d27cc48a7f4c050fcc89ab5d07b19329d228955
Story: 2002544
Task: 22103
This commit is contained in:
Thomas Herve 2018-06-25 10:58:27 +02:00
parent 8d40e2d2b5
commit 820b5a8d84
2 changed files with 26 additions and 0 deletions

View File

@ -98,6 +98,14 @@ class CommonTemplate(template.Template):
name, data, no_parse)
if isinstance(depends, six.string_types):
depends = [depends]
elif depends:
for dep in depends:
if not isinstance(dep, six.string_types):
msg = _('Resource %(name)s %(key)s '
'must be a list of strings') % {
'name': name, 'key': self.RES_DEPENDS_ON}
raise exception.StackValidationFailed(message=msg)
yield 'depends', depends
del_policy = self._parse_resource_field(self.RES_DELETION_POLICY,

View File

@ -2105,3 +2105,21 @@ parameters:
'NoEcho': 'false',
'Type': 'String'}}}
self.assertEqual(expected, res)
def test_validate_bad_depends(self):
test_template = '''
heat_template_version: 2013-05-23
resources:
random_str:
type: OS::Heat::RandomString
depends_on: [{foo: bar}]
'''
t = template_format.parse(test_template)
res = dict(self.engine.validate_template(self.ctx, t, {}))
self.assertEqual(
{'Error': 'Resource random_str depends_on must be '
'a list of strings'},
res)