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)
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
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
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):