From: Angus Salkeld Date: Thu, 13 Jun 2013 02:24:02 +0000 (+1000) Subject: Make template_format.parse usable by environments X-Git-Tag: 2014.1~468^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c28f12d94ffd15886910357539a4d9b7bc52cd07;p=openstack-build%2Fheat-build.git Make template_format.parse usable by environments (environments don't want template sections) blueprint environments Change-Id: I68ac0b8fb0889d245ace4d0ea8d298460c4c1b1a --- diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index dc522e4e..9dcec53e 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -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) diff --git a/heat/common/template_format.py b/heat/common/template_format.py index 76c8043e..0cdae374 100644 --- a/heat/common/template_format.py +++ b/heat/common/template_format.py @@ -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 diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index f9676bfb..f668ba80 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -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):