Make template validation uniform

There were two different behaviours during template validation and creation
stack (with template validation). In first case error was raised if
template did not have any resources. However user could create stack
without error using this such kind of template.
This patch make behaviour equal for both variant and gives ability to
create and successfully validate stack with template which does not have
resources.

Change-Id: I4dc30ccdc45e0fa7ff678b434106e056dba5f3b4
Closes-Bug: #1278090
This commit is contained in:
Sergey Kraynev 2014-04-10 10:16:00 -04:00
parent 73a9dce9ba
commit d102b1ee1c
4 changed files with 13 additions and 13 deletions

View File

@ -80,8 +80,9 @@ parameters
resources
This section contains the declaration of the single resources of the
template. This section is mandatory and at least one resource must be
defined in any HOT template.
template. This section with at least one resource should be defined in any
HOT template, or the template would not really do anything when being
instantiated.
outputs
This section allows for specifying output parameters available to users once

View File

@ -600,7 +600,7 @@ class EngineService(service.Service):
# validate overall template
try:
tmpl.validate(allow_empty=False)
tmpl.validate()
except Exception as ex:
return {'Error': six.text_type(ex)}

View File

@ -18,7 +18,9 @@ import functools
from heat.common import exception
from heat.db import api as db_api
from heat.engine import plugin_manager
from heat.openstack.common import log as logging
logger = logging.getLogger(__name__)
__all__ = ['Template']
@ -164,7 +166,7 @@ class Template(collections.Mapping):
def parse(self, stack, snippet):
return parse(self.functions(), stack, snippet)
def validate(self, allow_empty=True):
def validate(self):
'''Validate the template.
Validates the top-level sections of the template as well as syntax
@ -172,7 +174,6 @@ class Template(collections.Mapping):
code parts that are responsible for working with the respective
sections (e.g. parameters are check by parameters schema class).
:param allow_empty: whether to allow an empty resources section
'''
# check top-level sections
@ -182,11 +183,10 @@ class Template(collections.Mapping):
# check resources
tmpl_resources = self[self.RESOURCES]
if not allow_empty and not tmpl_resources:
message = _('The template is invalid. A Resources section with at '
'least one resource must be defined.')
raise exception.StackValidationFailed(message=message)
if not tmpl_resources:
logger.warn(_('Template does not contain any resources, so '
'the template would not really do anything when '
'being instantiated.'))
for res in tmpl_resources.values():
try:

View File

@ -1076,9 +1076,8 @@ class validateTest(HeatTestCase):
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, hot_tpl, {}))
self.assertEqual({'Error': 'The template is invalid. '
'A Resources section with at least one resource '
'must be defined.'}, res)
expected = {'Description': 'No description', 'Parameters': {}}
self.assertEqual(expected, res)
def test_validate_template_with_invalid_resource_type(self):
hot_tpl = template_format.parse('''