Handle error in templates with incorrect resources
This patch adds additional validation resources section for hot templates, it allows determine of the real problem in template and give the user an adequate message. Change-Id: Iff5e1b541b00a82dfce524f00ff1d20f50ae92da Closes-Bug: #1365949
This commit is contained in:
parent
dab36df3db
commit
752c0112ad
@ -13,6 +13,7 @@
|
||||
import collections
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.engine.cfn import functions as cfn_funcs
|
||||
from heat.engine.cfn import template as cfn_template
|
||||
@ -128,10 +129,12 @@ class HOTemplate20130523(template.Template):
|
||||
'update_policy': 'UpdatePolicy'}
|
||||
|
||||
cfn_resources = {}
|
||||
|
||||
for resource_name, attrs in six.iteritems(resources):
|
||||
cfn_resource = {}
|
||||
|
||||
if isinstance(attrs, six.string_types):
|
||||
message = _('"resources" must contain a map of resource maps.')
|
||||
raise exception.StackValidationFailed(message=message)
|
||||
for attr, attr_value in six.iteritems(attrs):
|
||||
cfn_attr = self._translate(attr, HOT_TO_CFN_ATTRS,
|
||||
_('"%s" is not a valid keyword '
|
||||
|
@ -204,6 +204,24 @@ class HOTemplateTest(HeatTestCase):
|
||||
'inside a resource definition\'',
|
||||
six.text_type(err))
|
||||
|
||||
def test_translate_resources_resources_without_name(self):
|
||||
hot_tpl = template_format.parse('''
|
||||
heat_template_version: 2013-05-23
|
||||
resources:
|
||||
type: AWS::EC2::Instance
|
||||
properties:
|
||||
property1: value1
|
||||
metadata:
|
||||
foo: bar
|
||||
depends_on: dummy
|
||||
deletion_policy: dummy
|
||||
''')
|
||||
tmpl = parser.Template(hot_tpl)
|
||||
error = self.assertRaises(exception.StackValidationFailed,
|
||||
tmpl.__getitem__, tmpl.RESOURCES)
|
||||
self.assertEqual('"resources" must contain a map of resource maps.',
|
||||
six.text_type(error))
|
||||
|
||||
def test_translate_resources_bad_metadata(self):
|
||||
"""Test translation of resources including invalid keyword."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user