def validateTask(self, taskConf, taskArgumentDefinition): """ _validateTask_ Validate the task information against the given argument description """ try: validateArgumentsCreate(taskConf, taskArgumentDefinition, checkInputDset=False) # Validate GPU-related spec parameters StdBase.validateGPUSettings(taskConf) except WMSpecFactoryException: # just re-raise it to keep the error message clear raise except Exception as ex: self.raiseValidationException(str(ex))
def testValidateGPUSettings(self): """ Test the 'validateGPUSettings' StdBase method. """ with self.assertRaises(WMSpecFactoryException): StdBase.validateGPUSettings({"RequiresGPU": "optional"}) with self.assertRaises(WMSpecFactoryException): StdBase.validateGPUSettings({"RequiresGPU": "required"}) with self.assertRaises(WMSpecFactoryException): StdBase.validateGPUSettings({ "RequiresGPU": "optional", "GPUParams": json.dumps("") }) with self.assertRaises(WMSpecFactoryException): StdBase.validateGPUSettings({ "RequiresGPU": "required", "GPUParams": json.dumps(None) }) # now input that passes the validation self.assertTrue( StdBase.validateGPUSettings({"RequiresGPU": "forbidden"})) self.assertTrue( StdBase.validateGPUSettings({ "RequiresGPU": "optional", "GPUParams": json.dumps("blah") })) self.assertTrue( StdBase.validateGPUSettings({ "RequiresGPU": "required", "GPUParams": json.dumps({"Key1": "value1"}) }))
def validateSchema(self, schema): """ _validateSchema_ Go over each task and make sure it matches validation parameters derived from Dave's requirements. They are: * cannot have more than 10 tasks * output from the last task *must* be saved * task must be described as a python dictionary type * transient output modules must be an input for further task(s) * and the usual Task arguments validation, as defined in the spec """ numTasks = schema['TaskChain'] if numTasks > 10: msg = "Workflow exceeds the maximum allowed number of tasks. " msg += "Limited to up to 10 tasks, found %s tasks." % numTasks self.raiseValidationException(msg) lastTask = "Task%s" % schema['TaskChain'] if not strToBool(schema[lastTask].get('KeepOutput', True)): msg = "Dropping the output (KeepOutput=False) of the last task is prohibited.\n" msg += "You probably want to remove that task completely and try again." self.raiseValidationException(msg=msg) transientMapping = {} for i in range(1, numTasks + 1): taskNumber = "Task%s" % i if taskNumber not in schema: msg = "Task '%s' not present in the request schema." % taskNumber self.raiseValidationException(msg=msg) task = schema[taskNumber] # We can't handle non-dictionary tasks if not isinstance(task, dict): msg = "Task '%s' not defined as a dictionary. " % taskNumber msg += "It could be an indicator of JSON error.\n" self.raiseValidationException(msg=msg) # Generic task parameter validation self.validateTask( task, self.getChainCreateArgs(i == 1, i == 1 and 'InputDataset' not in task)) # Validate the existence of the configCache if task["ConfigCacheID"]: self.validateConfigCacheExists( configID=task['ConfigCacheID'], configCacheUrl=schema["ConfigCacheUrl"], couchDBName=schema["CouchDBName"], getOutputModules=False) # Validate the chaining of transient output modules, need to make a copy of the lists transientMapping[task['TaskName']] = [ x for x in task.get('TransientOutputModules', []) ] if i > 1: inputTransientModules = transientMapping[task['InputTask']] if task['InputFromOutputModule'] in inputTransientModules: inputTransientModules.remove(task['InputFromOutputModule']) try: StdBase.validateGPUSettings(schema) except Exception as ex: self.raiseValidationException(str(ex)) for task in transientMapping: if transientMapping[task]: msg = "A transient module is not processed by a subsequent task.\n" msg += "This is a malformed task chain workload" self.raiseValidationException(msg)