X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tosca2heat%2Ftosca-parser%2Ftoscaparser%2Fimports.py;h=b69bf4db4c6a73d5b7f590fa83a47b4a8d62dcb3;hb=69e33063b3703ae4529b556b63b3c4cc239c3d9a;hp=62748bd9b396145aef5be8bf97a7e36816946a1c;hpb=d3ec79a8d3146b88892cf6d7fdf843ccd7e3a0b0;p=parser.git diff --git a/tosca2heat/tosca-parser/toscaparser/imports.py b/tosca2heat/tosca-parser/toscaparser/imports.py index 62748bd..b69bf4d 100644 --- a/tosca2heat/tosca-parser/toscaparser/imports.py +++ b/tosca2heat/tosca-parser/toscaparser/imports.py @@ -14,6 +14,7 @@ import logging import os from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidPropertyValueError from toscaparser.common.exception import MissingRequiredFieldError from toscaparser.common.exception import UnknownFieldError from toscaparser.common.exception import ValidationError @@ -36,7 +37,7 @@ class ImportsLoader(object): tpl=None): self.importslist = importslist self.custom_defs = {} - self.nested_topo_tpls = [] + self.nested_tosca_tpls = [] if not path and not tpl: msg = _('Input tosca template is not provided.') log.warning(msg) @@ -56,8 +57,8 @@ class ImportsLoader(object): def get_custom_defs(self): return self.custom_defs - def get_nested_topo_tpls(self): - return self.nested_topo_tpls + def get_nested_tosca_tpls(self): + return self.nested_tosca_tpls def _validate_and_load_imports(self): imports_names = set() @@ -97,7 +98,7 @@ class ImportsLoader(object): custom_type, import_def) self._update_custom_def(custom_type, None) - self._update_nested_topo_tpls(full_file_name, custom_type) + self._update_nested_tosca_tpls(full_file_name, custom_type) def _update_custom_def(self, custom_type, namespace_prefix): outer_custom_types = {} @@ -118,10 +119,10 @@ class ImportsLoader(object): else: self.custom_defs.update(outer_custom_types) - def _update_nested_topo_tpls(self, full_file_name, custom_tpl): + def _update_nested_tosca_tpls(self, full_file_name, custom_tpl): if full_file_name and custom_tpl: topo_tpl = {full_file_name: custom_tpl} - self.nested_topo_tpls.append(topo_tpl) + self.nested_tosca_tpls.append(topo_tpl) def _validate_import_keys(self, import_name, import_uri_def): if self.FILE not in import_uri_def.keys(): @@ -161,12 +162,17 @@ class ImportsLoader(object): | URL | URL | OK | +----------+--------+------------------------------+ """ - short_import_notation = False if isinstance(import_uri_def, dict): self._validate_import_keys(import_name, import_uri_def) file_name = import_uri_def.get(self.FILE) repository = import_uri_def.get(self.REPOSITORY) + repos = self.repositories.keys() + if repository is not None: + if repository not in repos: + ExceptionCollector.appendException( + InvalidPropertyValueError( + what=_('Repository is not found in "%s"') % repos)) else: file_name = import_uri_def repository = None @@ -178,7 +184,7 @@ class ImportsLoader(object): % {'import_name': import_name}) log.error(msg) ExceptionCollector.appendException(ValidationError(message=msg)) - return + return None, None if toscaparser.utils.urlutils.UrlUtils.validate_url(file_name): return file_name, YAML_LOADER(file_name, False) @@ -193,7 +199,7 @@ class ImportsLoader(object): % {'name': file_name, 'template': self.path}) log.error(msg) ExceptionCollector.appendException(ImportError(msg)) - return + return None, None import_template = toscaparser.utils.urlutils.UrlUtils.\ join_url(self.path, file_name) a_file = False @@ -215,7 +221,7 @@ class ImportsLoader(object): dir_path = os.path.dirname(os.path.abspath( self.path)) if file_path[0] != '' and dir_path.endswith( - file_path[0]): + file_path[0]): import_template = dir_path + "/" +\ file_path[2] if not os.path.isfile(import_template): @@ -236,7 +242,7 @@ class ImportsLoader(object): % {'name': file_name}) log.error(msg) ExceptionCollector.appendException(ImportError(msg)) - return + return None, None if not import_template: log.error(_('Import "%(name)s" is not valid.') % @@ -244,14 +250,14 @@ class ImportsLoader(object): ExceptionCollector.appendException( ImportError(_('Import "%s" is not valid.') % import_uri_def)) - return + return None, None return import_template, YAML_LOADER(import_template, a_file) if short_import_notation: log.error(_('Import "%(name)s" is not valid.') % import_uri_def) ExceptionCollector.appendException( ImportError(_('Import "%s" is not valid.') % import_uri_def)) - return + return None, None full_url = "" if repository: @@ -269,7 +275,7 @@ class ImportsLoader(object): % {'n_uri': repository, 'tpl': import_name}) log.error(msg) ExceptionCollector.appendException(ImportError(msg)) - return + return None, None if toscaparser.utils.urlutils.UrlUtils.validate_url(full_url): return full_url, YAML_LOADER(full_url, False)