def _validate_and_load_imports(self): imports_names = set() if not self.importslist: msg = _('"imports" keyname is defined without including ' 'templates.') log.error(msg) ExceptionCollector.appendException(ValidationError(message=msg)) return for import_def in self.importslist: if isinstance(import_def, dict): for import_name, import_uri in import_def.items(): if import_name in imports_names: msg = (_('Duplicate import name "%s" was found.') % import_name) log.error(msg) ExceptionCollector.appendException( ValidationError(message=msg)) imports_names.add(import_name) custom_type = self._load_import_template( import_name, import_uri) namespace_prefix = None if isinstance(import_uri, dict): namespace_prefix = import_uri.get( self.NAMESPACE_PREFIX) if custom_type: 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) if custom_type: TypeValidation(custom_type, import_def) self._update_custom_def(custom_type, None)
def handle_properties(self): tosca_props = self.get_tosca_props() self.log.debug( _("Port {0} with tosca properties: {1}").format( self.name, tosca_props)) port_props = {} for key, value in tosca_props.items(): port_props[key] = value if 'cp_type' not in port_props: port_props['cp_type'] = 'VPORT' else: if not port_props['cp_type'] in ToscaNetworkPort.VALID_TYPES: err_msg = _("Invalid port type, {0}, specified for {1}"). \ format(port_props['cp_type'], self.name) self.log.warn(err_msg) raise ValidationError(message=err_msg) if 'vdu_intf_type' not in port_props: port_props['vdu_intf_type'] = 'VIRTIO' else: if not port_props['vdu_intf_type'] in ToscaNetworkPort.VALID_TYPES: err_msg = _("Invalid port type, {0}, specified for {1}"). \ format(port_props['vdu_intf_type'], self.name) self.log.warn(err_msg) raise ValidationError(message=err_msg) self.cp_name = port_props['name'] self.properties = port_props
def _validate_tosca_meta(self, filelist): tosca = self._read_template_yaml(TOSCA_META) if tosca is None: return False self.metadata = tosca if 'Entry-Definitions' not in self.metadata: err_msg = (_('The CSAR "%s" is missing the required metadata ' '"Entry-Definitions" in ' '"TOSCA-Metadata/TOSCA.meta".') % self.path) ExceptionCollector.appendException( ValidationError(message=err_msg)) return False # validate that 'Entry-Definitions' metadata value points to an # existing file in the CSAR entry = self.metadata.get('Entry-Definitions') if entry and entry not in filelist: err_msg = (_('The "Entry-Definitions" file defined in the ' 'CSAR "%s" does not exist.') % self.path) ExceptionCollector.appendException( ValidationError(message=err_msg)) return False self.main_template_file_name = entry return True
def validate_properties(self, properties, required=None, optional=None): if not isinstance(properties, dict): err_msg = _("Properties for {0}({1}) is not right type"). \ format(self.name, self.type_) self.log.error(err_msg) raise ValidationError(message=err_msg) if required: # Check if the required properties are present if not set(required).issubset(properties.keys()): for key in required: if key not in properties: err_msg = _("Property {0} is not defined " "for {1}({2})"). \ format(key, self.name, self.type_) self.log.error(err_msg) raise ValidationError(message=err_msg) # Check for unknown properties for key in properties.keys(): if (key not in required or key not in optional): self.log.warn(_("Property {0} not supported for {1}({2}), " "will be ignored."). format(key, self.name, self.type_))
def _validate_root_level_yaml(self, filelist): root_files = [] for file in filelist: if '/' not in file: __, file_extension = os.path.splitext(file) if file_extension in ['.yaml', '.yml']: root_files.append(file) if not len(root_files) == 1: err_msg = (_('CSAR file should contain only one root level yaml' ' file. Found "%d" yaml file(s).') % len(root_files)) ExceptionCollector.appendException( ValidationError(message=err_msg)) return False template_data = self._read_template_yaml(root_files[0]) if template_data is None: return False tosca_version = template_data.get('tosca_definitions_version') if tosca_version == 'tosca_simple_yaml_1_0': err_msg = (_('"%s" is not a valid CSAR as it does not contain' ' the required file "TOSCA.meta" in the' ' folder "TOSCA-Metadata".') % self.path) ExceptionCollector.appendException( ValidationError(message=err_msg)) return False self.metadata = template_data.get('metadata') self.main_template_file_name = root_files[0] return True
def _validate_directives(self, template): msg = (_('directives of "%s" must be a list of strings') % self.name) keys = template.get("directives", []) if not isinstance(keys, list): ExceptionCollector.appendException(ValidationError(message=msg)) for key in keys: if not isinstance(key, str): ExceptionCollector.appendException( ValidationError(message=msg))
def handle_properties(self, nodes, groups): tosca_props = self.get_tosca_group_props() self.log.debug( _("{0} with tosca properties: {1}").format(self, tosca_props)) if 'name ' in tosca_props: self.properties['name'] = tosca_props['name'] if 'max_instance_count' in tosca_props: self.properties['max-instance-count'] = tosca_props[ 'max_instance_count'] if 'min_instance_count' in tosca_props: self.properties['min-instance-count'] = tosca_props[ 'min_instance_count'] self.properties['vnfd-member'] = [] def _get_node(name): for node in nodes: if node.name == name: return node if 'vnfd_members' in tosca_props: for member, count in tosca_props['vnfd_members'].items(): node = _get_node(member) if node: memb = {} memb['member-vnf-index-ref'] = node.get_member_vnf_index() memb['count'] = count self.properties['vnfd-member'].append(memb) else: err_msg = _("{0}: Did not find the member node {1} in " "resources list"). \ format(self, member) self.log.error(err_msg) raise ValidationError(message=err_msg) def _validate_action(action): for group in groups: if group.validate_primitive(action): return True return False self.properties['scaling-config-action'] = [] if 'config_actions' in tosca_props: for action, value in tosca_props['config_actions'].items(): conf = {} if _validate_action(value): conf['trigger'] = action conf['ns-service-primitive-name-ref'] = value self.properties['scaling-config-action'].append(conf) else: err_msg = _("{0}: Did not find the action {1} in " "config primitives"). \ format(self, action) self.log.error(err_msg) raise ValidationError(message=err_msg) self.log.debug(_("{0} properties: {1}").format(self, self.properties))
def get_guest_epa(specs, nfv_comput_specs): guest_epa = {} guest_epa['numa-node-policy'] = {} guest_epa['numa-node-policy']['node'] = [] if 'mem_policy' in specs: guest_epa['numa-node-policy']['mem-policy'] = specs['mem_policy'].upper() if 'node_cnt' in specs: guest_epa['numa-node-policy']['node-cnt'] = specs['node_cnt'] if 'node' in specs: for node in specs['node']: node_prop = {} if 'id' in node: node_prop['id'] = node['id'] if 'mem_size' in node: if 'MiB' in node['mem_size'] or 'MB' in node['mem_size']: node_prop['memory-mb'] = int(node['mem_size'].replace('MB','')) else: err_msg = "Specify mem_size of NUMA extension should be in MB" raise ValidationError(message=err_msg) if 'vcpus' in node: vcpu_lis =[] for vcpu in node['vcpus']: vcpu_lis.append({'id': vcpu}) node_prop['vcpu'] = vcpu_lis if 'om_numa_type' in node: numa_type = node['om_numa_type'] if 'paired-threads' == numa_type: node_prop['paired_threads'] = {} node_prop['paired_threads']['num_paired_threads'] = node['paired_threads']['num_paired_threads'] elif 'threads' == numa_type: if 'num_threads' in node: node_prop['num_threads'] = node['num_threads'] elif 'cores' == numa_type: if 'num_cores' in node: node_prop['num_cores'] = node['num_cores'] else: err_msg = "om_numa_type should be among cores, paired-threads or threads" raise ValidationError(message=err_msg) guest_epa['numa-node-policy']['node'].append(node_prop) if 'mem_page_size' in nfv_comput_specs: guest_epa['mempage-size'] = self.TOSCA_MEM_SIZE[nfv_comput_specs['mem_page_size']] if 'cpu_allocation' in nfv_comput_specs: if 'cpu_affinity' in nfv_comput_specs['cpu_allocation']: guest_epa['cpu-pinning-policy'] = nfv_comput_specs['cpu_allocation']['cpu_affinity'].upper() guest_epa['trusted-execution'] = False if 'thread_allocation' in nfv_comput_specs['cpu_allocation']: guest_epa['cpu-thread-pinning-policy'] = nfv_comput_specs['cpu_allocation']['thread_allocation'].upper() return guest_epa
def validate(self, value): self.value_msg = value if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: value = scalarunit.get_scalarunit_value(self.property_type, value) if not self._is_valid(value): err_msg = self._err_msg(value) ExceptionCollector.appendException(ValidationError(message=err_msg))
def __init__(self, importslist, path, type_definition_list=None, tpl=None, project=None): self.project = project 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) ExceptionCollector.appendException(ValidationError(message=msg)) self.path = path self.repositories = {} if tpl and tpl.get('repositories'): self.repositories = tpl.get('repositories') self.type_definition_list = [] if type_definition_list: if isinstance(type_definition_list, list): self.type_definition_list = type_definition_list else: self.type_definition_list.append(type_definition_list) self._validate_and_load_imports()
def _validate_capabilities_properties(self, capabilities): for cap, props in capabilities.items(): capabilitydef = self.get_capability(cap).definition self._common_validate_properties(capabilitydef, props[self.PROPERTIES]) # validating capability properties values for prop in self.get_capability(cap).get_properties_objects(): prop.validate() # TODO(srinivas_tadepalli): temporary work around to validate # default_instances until standardized in specification if cap == "scalable" and prop.name == "default_instances": prop_dict = props[self.PROPERTIES] min_instances = prop_dict.get("min_instances") max_instances = prop_dict.get("max_instances") default_instances = prop_dict.get("default_instances") if not (min_instances <= default_instances <= max_instances): err_msg = ('"properties" of template "%s": ' '"default_instances" value is not between ' '"min_instances" and "max_instances".' % self.name) ExceptionCollector.appendException( ValidationError(message=err_msg))
def handle_requirements(self, nodes): tosca_reqs = self.get_tosca_reqs() self.log.debug("VNF {0} requirements: {1}".format( self.name, tosca_reqs)) try: for req in tosca_reqs: if 'vdus' in req: target = req['vdus']['target'] node = self.get_node_with_name(target, nodes) if node: self._vdus.append(node) node._vnf = self # Add the VDU id to mgmt-intf if 'mgmt-interface' in self.properties: self.properties['mgmt-interface']['vdu-id'] = \ node.id if 'vdu' in self.properties['mgmt-interface']: # Older yang self.properties['mgmt-interface'].pop('vdu') else: err_msg = _("VNF {0}, VDU {1} specified not found"). \ format(self.name, target) self.log.error(err_msg) raise ValidationError(message=err_msg) except Exception as e: err_msg = _("Exception getting VDUs for VNF {0}: {1}"). \ format(self.name, e) self.log.error(err_msg) raise e self.log.debug( _("VNF {0} properties: {1}").format(self.name, self.properties))
def _validate_nodefilter_filter(self, node_filter, cap_label=''): valid = True if cap_label: name = 'capability "%s" on nodefilter on template "%s"' % ( cap_label, self.name) else: name = 'nodefilter on template "%s"' % self.name if not isinstance(node_filter, dict): ExceptionCollector.appendException( TypeMismatchError(what=name, type='dict')) return False if 'properties' in node_filter: propfilters = node_filter['properties'] if not isinstance(propfilters, list): ExceptionCollector.appendException( TypeMismatchError(what='"properties" of %s' % name, type='list')) return False for filter in propfilters: if not isinstance(filter, dict): ExceptionCollector.appendException( TypeMismatchError(what='filter in %s' % name, type='dict')) valid = False continue if len(filter) != 1: msg = _( 'Invalid %s: only one condition allow per filter condition' ) % name ExceptionCollector.appendException( ValidationError(message=msg)) valid = False continue # XXX validate filter condition return valid
def vnf(self, vnf): if self._vnf: err_msg = (_('VDU {0} already has a VNF {1} associated').format( self, self._vnf)) self.log.error(err_msg) raise ValidationError(message=err_msg) self._vnf = vnf
def handle_requirements(self, nodes, policies, vnf_type_to_vdus_map): tosca_reqs = self.get_tosca_reqs() for req in tosca_reqs: for key, value in req.items(): if 'target' in value: self._reqs[key] = value['target'] for policy in policies: if hasattr(policy, '_vnf_name') and policy._vnf_name == self.name: self._policies.append(policy) if self.vnf_type in vnf_type_to_vdus_map: for vdu_node_name in vnf_type_to_vdus_map[self.vnf_type]: node = self.get_node_with_name(vdu_node_name, nodes) if node: self._vdus.append(node) node._vnf = self # Add the VDU id to mgmt-intf if 'mgmt-interface' in self.properties: self.properties['mgmt-interface']['vdu-id'] = \ node.id if 'vdu' in self.properties['mgmt-interface']: # Older yang self.properties['mgmt-interface'].pop('vdu') else: err_msg = _("VNF {0}, VDU {1} specified not found"). \ format(self.name, target) self.log.error(err_msg) raise ValidationError(message=err_msg)
def __init__(self, name, template, entity_name, custom_def=None): self.name = name self.entity_tpl = template self.custom_def = custom_def self._validate_field(self.entity_tpl) type = self.entity_tpl.get('type') UnsupportedType.validate_type(type) if entity_name == 'node_type': self.type_definition = NodeType(type, custom_def) \ if type is not None else None if entity_name == 'relationship_type': relationship = template.get('relationship') type = None if relationship and isinstance(relationship, dict): type = relationship.get('type') elif isinstance(relationship, str): type = self.entity_tpl['relationship'] else: type = self.entity_tpl['type'] UnsupportedType.validate_type(type) self.type_definition = RelationshipType(type, None, custom_def) if entity_name == 'policy_type': if not type: msg = (_('Policy definition of "%(pname)s" must have' ' a "type" ' 'attribute.') % dict(pname=name)) ExceptionCollector.appendException(ValidationError(msg)) self.type_definition = PolicyType(type, custom_def) if entity_name == 'group_type': self.type_definition = GroupType(type, custom_def) \ if type is not None else None self._properties = None self._interfaces = None self._requirements = None self._capabilities = None
def _validate_type(self): """validate the node_type of substitution mappings.""" if self.node: node = self.topology.node_templates.get(self.node) if not node: ExceptionCollector.appendException( ValidationError(message=_( 'Unknown node "%s" declared on substitution_mappings') % self.node)) self.node_definition = node.type_definition return node_type = self.sub_mapping_def.get(self.NODE_TYPE) if not node_type: ExceptionCollector.appendException( MissingRequiredFieldError( what=_('SubstitutionMappings used in topology_template'), required=self.NODE_TYPE)) return False node_type_def = self.custom_defs.get(node_type) if not node_type_def: ExceptionCollector.appendException( InvalidNodeTypeError(what=node_type)) return False self.node_definition = NodeType(self.node_type, self.custom_defs) return True
def __init__(self, tosca_parser_template, provider, cluster_name): self.provider = provider self.provider_config = ProviderConfiguration(self.provider) self.cluster_name = cluster_name ExceptionCollector.start() for sec in self.REQUIRED_CONFIG_PARAMS: if not self.provider_config.config[self.provider_config.MAIN_SECTION].get(sec): ExceptionCollector.appendException(ProviderConfigurationParameterError( what=sec )) ExceptionCollector.stop() if ExceptionCollector.exceptionsCaught(): raise ValidationError( message='\nTranslating to provider failed: ' .join(ExceptionCollector.getExceptionsReport()) ) # toscaparser.tosca_template:ToscaTemplate self.tosca_parser_template = tosca_parser_template # toscaparser.topology_template:TopologyTemplate self.tosca_topology_template = self.full_type_definitions(self.tosca_parser_template.topology_template) import_definition_file = ImportsLoader([self.definition_file()], None, list(SERVICE_TEMPLATE_KEYS), self.tosca_topology_template.tpl) self.full_provider_defs = copy.copy(self.tosca_topology_template.custom_defs) self.provider_defs = import_definition_file.get_custom_defs() self.full_provider_defs.update(self.provider_defs) self.artifacts = [] self.used_conditions_set = set() self.extra_configuration_tool_params = dict() self.inputs = self.tosca_topology_template.inputs self.outputs = self.tosca_topology_template.outputs node_templates = self.resolve_get_property_functions(self.tosca_topology_template.nodetemplates) self.topology_template = self.translate_to_provider() self.node_templates = self.topology_template.nodetemplates self.relationship_templates = self.topology_template.relationship_templates self.template_dependencies = dict() # list of lists # After this step self.node_templates has requirements with node_filter parameter self.resolve_in_template_dependencies() self.resolve_in_template_get_functions() self.configuration_content = None self.configuration_ready = None # Create the list of ProviderResource instances self.software_component_names = [] for node in self.node_templates: if self._is_software_component(node): self.software_component_names.append(node.name) self.provider_nodes = self._provider_nodes() self.provider_nodes_by_name = self._provider_nodes_by_name() self.relationship_templates_by_name = self._relationship_templates_by_name() self.provider_node_names_by_priority = self._sort_nodes_by_priority() self.provider_nodes_queue = self.sort_nodes_by_dependency()
def validate(self): """Validate the provided CSAR file.""" self.is_validated = True # validate that the file or URL exists missing_err_msg = (_('"%s" does not exist.') % self.path) if self.a_file: if not os.path.isfile(self.path): ExceptionCollector.appendException( ValidationError(message=missing_err_msg)) return False else: self.csar = self.path else: # a URL if not UrlUtils.validate_url(self.path): ExceptionCollector.appendException( ValidationError(message=missing_err_msg)) return False else: response = requests.get(self.path) self.csar = BytesIO(response.content) # validate that it is a valid zip file if not zipfile.is_zipfile(self.csar): err_msg = (_('"%s" is not a valid zip file.') % self.path) ExceptionCollector.appendException( ValidationError(message=err_msg)) return False # validate that it contains the metadata file in the correct location self.zfile = zipfile.ZipFile(self.csar, 'r') filelist = self.zfile.namelist() if TOSCA_META in filelist: self.is_tosca_metadata = True # validate that 'Entry-Definitions' property exists in TOSCA.meta is_validated = self._validate_tosca_meta(filelist) else: self.is_tosca_metadata = False is_validated = self._validate_root_level_yaml(filelist) if is_validated: # validate that external references and imports in the main # template actually exist and are accessible main_tpl = self._read_template_yaml(self.main_template_file_name) self._validate_external_references(main_tpl) return not ExceptionCollector.exceptionsCaught()
def get_main_template_yaml(self): main_template = self.get_main_template() if main_template: data = self.zfile.read(main_template) invalid_tosca_yaml_err_msg = ( _('The file "%(template)s" in the CSAR "%(csar)s" does not ' 'contain valid TOSCA YAML content.') % {'template': main_template, 'csar': self.path}) try: tosca_yaml = yaml.load(data) if type(tosca_yaml) is not dict: ExceptionCollector.appendException( ValidationError(message=invalid_tosca_yaml_err_msg)) return tosca_yaml except Exception: ExceptionCollector.appendException( ValidationError(message=invalid_tosca_yaml_err_msg))
def __init__(self, name, template, entity_name, custom_def=None): self.name = name self.entity_tpl = template self.custom_def = custom_def self._validate_field(self.entity_tpl) type = self.entity_tpl.get('type') UnsupportedType.validate_type(type) if '__typename' not in template: self._validate_fields(template) if entity_name == 'node_type': self.type_definition = NodeType(type, custom_def) \ if type is not None else None self._validate_directives(self.entity_tpl) if entity_name == 'relationship_type': self.type_definition = RelationshipType(type, custom_def) if entity_name == 'policy_type': if not type: msg = (_('Policy definition of "%(pname)s" must have' ' a "type" ' 'attribute.') % dict(pname=name)) ExceptionCollector.appendException( ValidationError(message=msg)) self.type_definition = PolicyType(type, custom_def) if entity_name == 'group_type': self.type_definition = GroupType(type, custom_def) \ if type is not None else None if entity_name == 'artifact_type': self.type_definition = ArtifactTypeDef(type, custom_def) \ if type is not None else None self._properties = None self._interfaces = None self._requirements = None self._capabilities = None if not self.type_definition: msg = "no type found %s for %s" % (entity_name, template) ExceptionCollector.appendException(ValidationError(message=msg)) return metadata = self.type_definition.get_definition('metadata') if metadata and 'additionalProperties' in metadata: self.additionalProperties = metadata['additionalProperties'] self._properties_tpl = self._validate_properties() for prop in self.get_properties_objects(): prop.validate() self._validate_interfaces()
def _read_template_yaml(self, template): data = self.zfile.read(template) invalid_tosca_yaml_err_msg = ( _('The file "%(template)s" in the CSAR "%(csar)s" does not ' 'contain valid YAML content.') % {'template': template, 'csar': self.path}) try: tosca_yaml = yaml.safe_load(data) if type(tosca_yaml) is not dict: ExceptionCollector.appendException( ValidationError(message=invalid_tosca_yaml_err_msg)) return None return tosca_yaml except Exception: ExceptionCollector.appendException( ValidationError(message=invalid_tosca_yaml_err_msg)) return None
def artifacts(self): if self._artifacts is None: artifacts = {} required_artifacts = {} for parent_type in reversed(self.types): if not parent_type.defs or not parent_type.defs.get( self.ARTIFACTS): continue for name, value in parent_type.defs[self.ARTIFACTS].items(): if isinstance( value, dict) and "file" not in value and "type" in value: # this is not a full artifact definition so treat this as # specifying that an artifact of a certain type is required required_artifacts[name] = value["type"] else: artifacts[name] = Artifact(name, value, self.custom_def, parent_type._source) # node templates can't be imported so we don't need to track their source artifacts_tpl = self.entity_tpl.get(self.ARTIFACTS) if artifacts_tpl: artifacts.update({ name: Artifact(name, value, self.custom_def) for name, value in artifacts_tpl.items() }) for name, typename in required_artifacts.items(): artifact = artifacts.get(name) if not artifact: ExceptionCollector.appendException( ValidationError( message= 'required artifact "%s" of type "%s" not defined on node "%s"' % (name, typename, self.name))) elif not artifact.is_derived_from(typename): ExceptionCollector.appendException( ValidationError( message= 'artifact "%s" on node "%s" must be derived from type "%s"' % (name, self.name, typename))) self._artifacts = artifacts return self._artifacts
def _validate_keys(self): if len(self.activity_tpl) != 1: ExceptionCollector.appendException( ValidationError(message="Invalid Activity")) for key in self.activity_tpl.keys(): if key not in SECTIONS: ExceptionCollector.appendException( UnknownFieldError(what='Activity', field=key))
def _validate_steps(self): steps = set() for step in self.steps.values(): steps.update(step.on_success + step.on_failure) missing = steps.difference(self.steps) if missing: msg = "Workflow %s referencing missing step(s): %s", (self.name, missing) ExceptionCollector.appendException(ValidationError(message=msg))
def _validate_and_load_imports(self): imports_names = set() if not self.importslist: msg = _('"imports" keyname is defined without including ' "templates.") log.error(msg) ExceptionCollector.appendException(ValidationError(message=msg)) return for import_def in self.importslist: if isinstance(import_def, dict): if len(import_def) == 1 and "file" not in import_def: # old style {name: uri} import_name, import_uri = list(import_def.items())[0] if import_name in imports_names: msg = _('Duplicate import name "%s" was found.') % import_name log.error(msg) ExceptionCollector.appendException(ValidationError(message=msg)) imports_names.add(import_name) else: # new style {"file": uri} import_name = None import_uri = import_def else: # import_def is just the uri string import_name = None import_uri = import_def full_file_name, imported_tpl = self._load_import_template( import_name, import_uri ) if full_file_name is None: return namespace_prefix = None if isinstance(import_uri, dict): namespace_prefix = import_uri.get(self.NAMESPACE_PREFIX) if imported_tpl: TypeValidation(imported_tpl, import_def) self._update_custom_def(imported_tpl, namespace_prefix, full_file_name) nested_imports = imported_tpl.get("imports") if nested_imports: self.nested_imports.update({full_file_name: nested_imports}) # XXX should save prefix too self._update_nested_tosca_tpls(full_file_name, imported_tpl)
def _validate_instancekeys(self): template = self.entity_tpl msg = (_( 'keys definition of "%s" must be a list of containing strings or lists' ) % self.name) keys = self.type_definition.get_value( self.INSTANCE_KEYS, template, parent=True) or [] if not isinstance(keys, list): ExceptionCollector.appendException(ValidationError(message=msg)) for key in keys: if isinstance(key, list): for item in key: if not isinstance(item, str): compoundKeyMsg = _( "individual keys in compound keys must be strings") ExceptionCollector.appendException( ValidationError(message=compoundKeyMsg)) elif not isinstance(key, str): ExceptionCollector.appendException( ValidationError(message=msg))
def verify_template(self): if ExceptionCollector.exceptionsCaught(): if self.input_path: raise ValidationError( message=(_('\nThe input "%(path)s" failed validation with ' 'the following error(s): \n\n\t') % {'path': self.input_path}) + '\n\t'.join(ExceptionCollector.getExceptionsReport())) else: raise ValidationError( message=_('\nThe pre-parsed input failed validation with ' 'the following error(s): \n\n\t') + '\n\t'.join(ExceptionCollector.getExceptionsReport())) else: if self.input_path: msg = (_('The input "%(path)s" successfully passed ' 'validation.') % {'path': self.input_path}) else: msg = _('The pre-parsed input successfully passed validation.') log.info(msg)
def verify_template(self): if self.no_required_paras_check: ExceptionCollector.removeException(MissingRequiredParameterError) ExceptionCollector.removeException(MissingRequiredInputError) ExceptionCollector.removeException(MissingRequiredOutputError) if ExceptionCollector.exceptionsCaught(): if self.input_path: exceptions = ValidationError( message=(_('\nThe input "%(path)s" failed validation with ' 'the following error(s): \n\n\t') % { 'path': self.input_path }) + '\n\t'.join(ExceptionCollector.getExceptionsReport())) else: exceptions = ValidationError( message=_('\nThe pre-parsed input failed validation with ' 'the following error(s): \n\n\t') + '\n\t'.join(ExceptionCollector.getExceptionsReport())) if not self.debug_mode: raise exceptions else: if self.sub_mapped_node_template: msg = _('======== nested service template ======== ') else: msg = _('======== main service template ======== ') print(msg) print(exceptions.message) log.error(msg) log.error(exceptions.message) else: if self.input_path: msg = (_('The input "%(path)s" successfully passed ' 'validation.') % { 'path': self.input_path }) else: msg = _('The pre-parsed input successfully passed validation.') log.info(msg)
def validate_inline_artifact(self, inline_artifact): if isinstance(inline_artifact, dict): if "file" not in inline_artifact: ExceptionCollector.appendException( MissingRequiredFieldError(what="inline artifact in " + self._msg, required="file")) for key in inline_artifact: if key not in INLINE_ARTIFACT_DEF_RESERVED_WORDS: what = ("inline artifact in " + self._msg + " contains invalid field " + key) ExceptionCollector.appendException( ValidationError(message=what))