From 489686cf5d162fd67635d25d8beb45cbe0e19ba8 Mon Sep 17 00:00:00 2001 From: spzala Date: Tue, 29 Sep 2015 07:38:22 -0700 Subject: [PATCH] Fix backward compatibility issue In the earlier version of TOSCA Parser the call to entry class TOSCATemplate has two arguments, file path and parameters where parameters arg is optional. A new arg has been added in parser as a flag to check if the path is file or not. The old way of calling parser (e.g. ToscaTemplate(path, '')) will not work with it. Should change the constructor signature per patch. Change-Id: Ia543bcaa6967ae68863266faef9689b1e27f0bf7 --- tosca_parser.py | 2 +- toscaparser/tests/test_toscatpl.py | 9 +++++---- toscaparser/tosca_template.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tosca_parser.py b/tosca_parser.py index b726b77c..513c1879 100644 --- a/tosca_parser.py +++ b/tosca_parser.py @@ -57,7 +57,7 @@ def main(): def parse(path, a_file=True): output = None - tosca = ToscaTemplate(path, a_file) + tosca = ToscaTemplate(path, None, a_file) version = tosca.version if tosca.version: print ("\nversion:\n" + version) diff --git a/toscaparser/tests/test_toscatpl.py b/toscaparser/tests/test_toscatpl.py index 4c610230..fe4881fa 100644 --- a/toscaparser/tests/test_toscatpl.py +++ b/toscaparser/tests/test_toscatpl.py @@ -402,7 +402,7 @@ class ToscaTemplateTest(TestCase): tosca_tpl = ('https://raw.githubusercontent.com/openstack/' 'tosca-parser/master/toscaparser/tests/data/' 'tosca_single_instance_wordpress.yaml') - tosca = ToscaTemplate(tosca_tpl, False) + tosca = ToscaTemplate(tosca_tpl, None, False) self.assertTrue(tosca.topology_template.custom_defs) def test_url_template_with_local_abspath_import(self): @@ -410,7 +410,8 @@ class ToscaTemplateTest(TestCase): 'tosca-parser/master/toscaparser/tests/data/' 'tosca_single_instance_wordpress_with_local_abspath_' 'import.yaml') - err = self.assertRaises(ImportError, ToscaTemplate, tosca_tpl, False) + err = self.assertRaises(ImportError, ToscaTemplate, tosca_tpl, + None, False) err_msg = (_("Absolute file name /toscaparser/tests/data/custom_types" "/wordpress.yaml cannot be used for a URL-based input " "%(tpl)s template.") @@ -421,7 +422,7 @@ class ToscaTemplateTest(TestCase): tosca_tpl = ('https://raw.githubusercontent.com/openstack/' 'tosca-parser/master/toscaparser/tests/data/' 'tosca_single_instance_wordpress_with_url_import.yaml') - tosca = ToscaTemplate(tosca_tpl, False) + tosca = ToscaTemplate(tosca_tpl, None, False) self.assertTrue(tosca.topology_template.custom_defs) def test_csar_parsing_wordpress(self): @@ -433,4 +434,4 @@ class ToscaTemplateTest(TestCase): def test_csar_parsing_elk_url_based(self): csar_archive = ('https://github.com/openstack/tosca-parser/raw/master/' 'toscaparser/tests/data/CSAR/csar_elk.zip') - self.assertTrue(ToscaTemplate(csar_archive, False)) + self.assertTrue(ToscaTemplate(csar_archive, None, False)) diff --git a/toscaparser/tosca_template.py b/toscaparser/tosca_template.py index d0fb740b..d01b67d7 100644 --- a/toscaparser/tosca_template.py +++ b/toscaparser/tosca_template.py @@ -48,7 +48,7 @@ class ToscaTemplate(object): VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] '''Load the template data.''' - def __init__(self, path, a_file=True, parsed_params=None): + def __init__(self, path, parsed_params=None, a_file=True): self.a_file = a_file self.path = self._get_path(path) self.tpl = YAML_LOADER(self.path, self.a_file)