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
tpl=None):
self.importslist = importslist
self.custom_defs = {}
+ self.nested_tosca_tpls = []
if not path and not tpl:
msg = _('Input tosca template is not provided.')
log.warning(msg)
def get_custom_defs(self):
return self.custom_defs
+ def get_nested_tosca_tpls(self):
+ return self.nested_tosca_tpls
+
def _validate_and_load_imports(self):
imports_names = set()
ValidationError(message=msg))
imports_names.add(import_name)
- custom_type = self._load_import_template(import_name,
- import_uri)
+ full_file_name, custom_type = self._load_import_template(
+ import_name, import_uri)
namespace_prefix = None
if isinstance(import_uri, dict):
namespace_prefix = import_uri.get(
TypeValidation(custom_type, import_def)
self._update_custom_def(custom_type, namespace_prefix)
else: # old style of imports
- custom_type = self._load_import_template(None,
- import_def)
+ full_file_name, custom_type = self._load_import_template(
+ None, import_def)
if custom_type:
TypeValidation(
custom_type, import_def)
self._update_custom_def(custom_type, None)
+ self._update_nested_tosca_tpls(full_file_name, custom_type)
+
def _update_custom_def(self, custom_type, namespace_prefix):
outer_custom_types = {}
for type_def in self.type_definition_list:
outer_custom_types = custom_type.get(type_def)
if outer_custom_types:
if type_def == "imports":
+ for i in self.custom_defs.get('imports', []):
+ if i not in outer_custom_types:
+ outer_custom_types.append(i)
self.custom_defs.update({'imports': outer_custom_types})
else:
if namespace_prefix:
else:
self.custom_defs.update(outer_custom_types)
+ 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_tosca_tpls.append(topo_tpl)
+
def _validate_import_keys(self, import_name, import_uri_def):
if self.FILE not in import_uri_def.keys():
log.warning(_('Missing keyname "file" in import "%(name)s".')
| 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
% {'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 YAML_LOADER(file_name, False)
+ return file_name, YAML_LOADER(file_name, False)
elif not repository:
import_template = None
if self.path:
% {'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
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):
% {'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.') %
ExceptionCollector.appendException(
ImportError(_('Import "%s" is not valid.') %
import_uri_def))
- return
- return YAML_LOADER(import_template, a_file)
+ 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:
% {'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 YAML_LOADER(full_url, False)
+ return full_url, YAML_LOADER(full_url, False)
else:
msg = (_('repository url "%(n_uri)s" is not valid in import '
'definition "%(tpl)s".')