Merge "Make template validation uniform"
This commit is contained in:
@@ -80,8 +80,9 @@ parameters
|
|||||||
|
|
||||||
resources
|
resources
|
||||||
This section contains the declaration of the single resources of the
|
This section contains the declaration of the single resources of the
|
||||||
template. This section is mandatory and at least one resource must be
|
template. This section with at least one resource should be defined in any
|
||||||
defined in any HOT template.
|
HOT template, or the template would not really do anything when being
|
||||||
|
instantiated.
|
||||||
|
|
||||||
outputs
|
outputs
|
||||||
This section allows for specifying output parameters available to users once
|
This section allows for specifying output parameters available to users once
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ class EngineService(service.Service):
|
|||||||
|
|
||||||
# validate overall template
|
# validate overall template
|
||||||
try:
|
try:
|
||||||
tmpl.validate(allow_empty=False)
|
tmpl.validate()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
return {'Error': six.text_type(ex)}
|
return {'Error': six.text_type(ex)}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ import functools
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.db import api as db_api
|
from heat.db import api as db_api
|
||||||
from heat.engine import plugin_manager
|
from heat.engine import plugin_manager
|
||||||
|
from heat.openstack.common import log as logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
__all__ = ['Template']
|
__all__ = ['Template']
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ class Template(collections.Mapping):
|
|||||||
def parse(self, stack, snippet):
|
def parse(self, stack, snippet):
|
||||||
return parse(self.functions(), stack, snippet)
|
return parse(self.functions(), stack, snippet)
|
||||||
|
|
||||||
def validate(self, allow_empty=True):
|
def validate(self):
|
||||||
'''Validate the template.
|
'''Validate the template.
|
||||||
|
|
||||||
Validates the top-level sections of the template as well as syntax
|
Validates the top-level sections of the template as well as syntax
|
||||||
@@ -180,7 +182,6 @@ class Template(collections.Mapping):
|
|||||||
code parts that are responsible for working with the respective
|
code parts that are responsible for working with the respective
|
||||||
sections (e.g. parameters are check by parameters schema class).
|
sections (e.g. parameters are check by parameters schema class).
|
||||||
|
|
||||||
:param allow_empty: whether to allow an empty resources section
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# check top-level sections
|
# check top-level sections
|
||||||
@@ -190,11 +191,10 @@ class Template(collections.Mapping):
|
|||||||
|
|
||||||
# check resources
|
# check resources
|
||||||
tmpl_resources = self[self.RESOURCES]
|
tmpl_resources = self[self.RESOURCES]
|
||||||
|
if not tmpl_resources:
|
||||||
if not allow_empty and not tmpl_resources:
|
logger.warn(_('Template does not contain any resources, so '
|
||||||
message = _('The template is invalid. A Resources section with at '
|
'the template would not really do anything when '
|
||||||
'least one resource must be defined.')
|
'being instantiated.'))
|
||||||
raise exception.StackValidationFailed(message=message)
|
|
||||||
|
|
||||||
for res in tmpl_resources.values():
|
for res in tmpl_resources.values():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1076,9 +1076,8 @@ class validateTest(HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'The template is invalid. '
|
expected = {'Description': 'No description', 'Parameters': {}}
|
||||||
'A Resources section with at least one resource '
|
self.assertEqual(expected, res)
|
||||||
'must be defined.'}, res)
|
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_type(self):
|
def test_validate_template_with_invalid_resource_type(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
|
|||||||
Reference in New Issue
Block a user