Make template_format.parse usable by environments
(environments don't want template sections) blueprint environments Change-Id: I68ac0b8fb0889d245ace4d0ea8d298460c4c1b1a
This commit is contained in:
parent
ac315ce361
commit
c28f12d94f
|
@ -56,14 +56,15 @@ class InstantiationData(object):
|
|||
self.data = data
|
||||
|
||||
@staticmethod
|
||||
def format_parse(data, data_type):
|
||||
def format_parse(data, data_type, add_template_sections=True):
|
||||
"""
|
||||
Parse the supplied data as JSON or YAML, raising the appropriate
|
||||
exception if it is in the wrong format.
|
||||
"""
|
||||
|
||||
try:
|
||||
return template_format.parse(data)
|
||||
return template_format.parse(data,
|
||||
add_template_sections)
|
||||
except ValueError:
|
||||
err_reason = _("%s not in valid format") % data_type
|
||||
raise exc.HTTPBadRequest(err_reason)
|
||||
|
|
|
@ -29,7 +29,7 @@ yaml.Loader.add_constructor(u'tag:yaml.org,2002:str', _construct_yaml_str)
|
|||
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:str', _construct_yaml_str)
|
||||
|
||||
|
||||
def parse(tmpl_str):
|
||||
def parse(tmpl_str, add_template_sections=True):
|
||||
'''
|
||||
Takes a string and returns a dict containing the parsed structure.
|
||||
This includes determination of whether the string is using the
|
||||
|
@ -45,8 +45,9 @@ def parse(tmpl_str):
|
|||
else:
|
||||
if tpl is None:
|
||||
tpl = {}
|
||||
default_for_missing(tpl, u'HeatTemplateFormatVersion',
|
||||
HEAT_VERSIONS)
|
||||
if add_template_sections:
|
||||
default_for_missing(tpl, u'HeatTemplateFormatVersion',
|
||||
HEAT_VERSIONS)
|
||||
return tpl
|
||||
|
||||
|
||||
|
|
|
@ -91,6 +91,24 @@ Outputs: {}
|
|||
self.assertEqual(tpl1, tpl2)
|
||||
|
||||
|
||||
class YamlEnvironmentTest(HeatTestCase):
|
||||
|
||||
def test_no_template_sections(self):
|
||||
env = '''
|
||||
parameters: {}
|
||||
resource_registry: {}
|
||||
'''
|
||||
parsed_env = template_format.parse(env, add_template_sections=False)
|
||||
|
||||
self.assertEqual('parameters' in parsed_env, True)
|
||||
self.assertEqual('resource_registry' in parsed_env, True)
|
||||
|
||||
self.assertEqual('Parameters' in parsed_env, False)
|
||||
self.assertEqual('Mappings' in parsed_env, False)
|
||||
self.assertEqual('Resources' in parsed_env, False)
|
||||
self.assertEqual('Outputs' in parsed_env, False)
|
||||
|
||||
|
||||
class JsonYamlResolvedCompareTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue