X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2Ftemplate_format.py;h=e1662ced167be9ea139e775d573533d6ae4df72b;hb=8f91b0a5c1f47953dd1a14541b71505dbf8f869a;hp=881b7e45b8fb1e5f059442f9ce6c2064659dfe68;hpb=f68ce570fd0eefb17bfc9e1e75c57b24050db89e;p=yardstick.git diff --git a/yardstick/common/template_format.py b/yardstick/common/template_format.py index 881b7e45b..e1662ced1 100644 --- a/yardstick/common/template_format.py +++ b/yardstick/common/template_format.py @@ -12,8 +12,10 @@ # yardstick: this file is copied from python-heatclient and slightly modified -import json +from __future__ import absolute_import + import yaml +from oslo_serialization import jsonutils if hasattr(yaml, 'CSafeLoader'): yaml_loader = yaml.CSafeLoader @@ -40,13 +42,13 @@ yaml_loader.add_constructor(u'tag:yaml.org,2002:timestamp', def parse(tmpl_str): - '''Takes a string and returns a dict containing the parsed structure. + """Takes a string and returns a dict containing the parsed structure. This includes determination of whether the string is using the JSON or YAML format. - ''' + """ if tmpl_str.startswith('{'): - tpl = json.loads(tmpl_str) + tpl = jsonutils.loads(tmpl_str) else: try: tpl = yaml.load(tmpl_str, Loader=yaml_loader) @@ -56,8 +58,8 @@ def parse(tmpl_str): if tpl is None: tpl = {} # Looking for supported version keys in the loaded template - if not ('HeatTemplateFormatVersion' in tpl - or 'heat_template_version' in tpl - or 'AWSTemplateFormatVersion' in tpl): + if not ('HeatTemplateFormatVersion' in tpl or + 'heat_template_version' in tpl or + 'AWSTemplateFormatVersion' in tpl): raise ValueError("Template format version not found.") return tpl