summaryrefslogtreecommitdiffstats
path: root/tosca2heat
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2017-08-29 16:42:20 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2017-09-05 13:45:28 +0800
commita9eee2ea67be0b45cec1cfe84ac760293d9473fa (patch)
tree05f0cbb2fcd9bd347aca41c72bf36e28eae97fb9 /tosca2heat
parent6eac11f48f8b664af928620bf2661987aa318725 (diff)
Fix exceptions overwritten when nested import service topology
Currently exceptions will be overwritten when import nested service topology, the patch will fix the issue. JIRA: PARSER-145 Change-Id: I531755efe55b43aef304fa972773c63613c915ff Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/shell.py21
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tosca_template.py29
2 files changed, 39 insertions, 11 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/shell.py b/tosca2heat/tosca-parser/toscaparser/shell.py
index 0256dfc..f669e27 100644
--- a/tosca2heat/tosca-parser/toscaparser/shell.py
+++ b/tosca2heat/tosca-parser/toscaparser/shell.py
@@ -12,9 +12,11 @@
import argparse
+import logging
import os
import sys
+from toscaparser.common.exception import ValidationError
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.utils.gettextutils import _
import toscaparser.utils.urlutils
@@ -38,6 +40,8 @@ e.g.
--template-file=toscaparser/tests/data/CSAR/csar_hello_world.zip
"""
+log = logging.getLogger("tosca.model")
+
class ParserShell(object):
@@ -62,17 +66,24 @@ class ParserShell(object):
path = args.template_file
nrpv = args.no_required_paras_valid
if os.path.isfile(path):
- self.parse(path, no_required_paras_valid=nrpv)
+ self.parse(path, no_req_paras_valid=nrpv)
elif toscaparser.utils.urlutils.UrlUtils.validate_url(path):
- self.parse(path, False, no_required_paras_valid=nrpv)
+ self.parse(path, False, no_req_paras_valid=nrpv)
else:
raise ValueError(_('"%(path)s" is not a valid file.')
% {'path': path})
- def parse(self, path, a_file=True, no_required_paras_valid=False):
+ def parse(self, path, a_file=True, no_req_paras_valid=False):
output = None
- tosca = ToscaTemplate(path, None, a_file,
- no_required_paras_valid=no_required_paras_valid)
+ tosca = None
+ try:
+ tosca = ToscaTemplate(path, None, a_file,
+ no_required_paras_valid=no_req_paras_valid)
+ except ValidationError as e:
+ msg = _(' ===== main service template ===== ')
+ log.error(msg)
+ log.error(e.message)
+ raise e
version = tosca.version
if tosca.version:
diff --git a/tosca2heat/tosca-parser/toscaparser/tosca_template.py b/tosca2heat/tosca-parser/toscaparser/tosca_template.py
index 3301999..4832bbb 100644
--- a/tosca2heat/tosca-parser/toscaparser/tosca_template.py
+++ b/tosca2heat/tosca-parser/toscaparser/tosca_template.py
@@ -236,12 +236,29 @@ class ToscaTemplate(object):
if self._is_sub_mapped_node(nodetemplate, tosca_tpl):
parsed_params = self._get_params_for_nested_template(
nodetemplate)
- nested_template = ToscaTemplate(
- path=fname, parsed_params=parsed_params,
- yaml_dict_tpl=tosca_tpl,
- sub_mapped_node_template=nodetemplate,
- no_required_paras_valid=self.no_required_paras_valid)
- if nested_template._has_substitution_mappings():
+
+ cache_exeptions = deepcopy(ExceptionCollector.exceptions)
+ cache_exeptions_state = \
+ deepcopy(ExceptionCollector.collecting)
+ nested_template = None
+ try:
+ nrpv = self.no_required_paras_valid
+ nested_template = ToscaTemplate(
+ path=fname, parsed_params=parsed_params,
+ sub_mapped_node_template=nodetemplate,
+ no_required_paras_valid=nrpv)
+ except ValidationError as e:
+ msg = _(' ===== nested service template ===== ')
+ log.error(msg)
+ log.error(e.message)
+ raise e
+
+ ExceptionCollector.exceptions = deepcopy(cache_exeptions)
+ ExceptionCollector.collecting = \
+ deepcopy(cache_exeptions_state)
+
+ if nested_template and \
+ nested_template._has_substitution_mappings():
# Record the nested templates in top level template
self.nested_tosca_templates_with_topology.\
append(nested_template)