def _validateArgFunction(argument, value, valFunction): """ Perform the validation function as in the argument definition """ if valFunction: try: if not valFunction(value): raise WMSpecFactoryException("Argument %s, value: %s doesn't pass the validation function." % (argument, value)) except Exception as ex: # Some validation functions (e.g. Lexicon) will raise errors instead of returning False logging.error(str(ex)) raise WMSpecFactoryException("Validation failed: %s value: %s" % (argument, value)) return
def validateInputDatasSetAndParentFlag(arguments): inputdataset = arguments.get("InputDataset", None) if strToBool(arguments.get("IncludeParents", False)): if inputdataset == None: msg = "IncludeParent flag is True but there is no inputdataset" raise WMSpecFactoryException(msg) else: dbsURL = arguments.get("DbsUrl", None) if dbsURL != None: #import DBS3Reader here, since Runtime code import this module and worker node doesn't have dbs3 client from WMCore.Services.DBS.DBS3Reader import DBS3Reader result = DBS3Reader(dbsURL).listDatasetParents(inputdataset) if len(result) == 0: msg = "IncludeParent flag is True but inputdataset %s doesn't have parents" % (inputdataset) raise WMSpecFactoryException(msg) else: _validateInputDataset(arguments) return
def _validateArgumentDict(argument, argValue, argumentDefinition): """ Validate arguments that carry a dict value type """ validNull = argumentDefinition["null"] if not validNull and None in argValue.values(): raise WMSpecFactoryException("Argument %s can't be None" % argument) elif all(val is None for val in argValue.values()): return argValue for val in argValue.values(): try: # sigh.. LumiList has a peculiar type validation if argument == 'LumiList': val = argumentDefinition["type"](argValue) break val = argumentDefinition["type"](val) except Exception: raise WMSpecFactoryException("Argument: %s, value: %s type is incorrect in schema." % (argument, val)) _validateArgFunction(argument, argValue, argumentDefinition["validate"]) return argValue
def _validateInputDataset(arguments): inputdataset = arguments.get("InputDataset", None) dbsURL = arguments.get("DbsUrl", None) if inputdataset != None and dbsURL != None: #import DBS3Reader here, since Runtime code import this module and worker node doesn't have dbs3 client from WMCore.Services.DBS.DBS3Reader import DBS3Reader from WMCore.Services.DBS.DBSErrors import DBSReaderError try: DBS3Reader(dbsURL).checkDatasetPath(inputdataset) except DBSReaderError as ex: # we need to Wrap the exception to WMSpecFactoryException to be caught in reqmgr validation raise WMSpecFactoryException(str(ex)) return