def test_get_job_ident(): error_script = """ from DIRAC import Job """ script = """ from DIRAC import Job j=Job() j.outputsomething('output.root') """ with pytest.raises(BackendError): get_job_ident(error_script.splitlines()) assert 'j' == get_job_ident(script.splitlines()), "Didn't get the right job ident"
def test_get_job_ident(): error_script = """ from DIRAC import Job """ script = """ from DIRAC import Job j=Job() j.outputsomething('output.root') """ with pytest.raises(BackendError): get_job_ident(error_script.splitlines()) assert 'j' == get_job_ident( script.splitlines()), "Didn't get the right job ident"
def test_get_job_ident(self): error_script = """ from DIRAC import Job """ script = """ from DIRAC import Job j=Job() j.outputsomething('output.root') """ self.assertRaises(BackendError, get_job_ident, error_script.splitlines()) self.assertEqual('j', get_job_ident(script.splitlines()), "Didn't get the right job ident")
def test_get_job_ident(self): error_script = """ from DIRAC import Job """ script = """ from DIRAC import Job j=Job() j.outputsomething('output.root') """ self.assertRaises( BackendError, get_job_ident, error_script.splitlines()) self.assertEqual('j', get_job_ident(script.splitlines()), "Didn't get the right job ident")
def _resubmit(self): """Resubmit a DIRAC job""" j = self.getJobObject() parametric = False script_path = os.path.join(j.getInputWorkspace().getPath(), 'dirac-script.py') # Check old script if j.master is None and not os.path.exists(script_path): raise BackendError('Dirac', 'No "dirac-script.py" found in j.inputdir') if j.master is not None and not os.path.exists(script_path): script_path = os.path.join( j.master.getInputWorkspace().getPath(), 'dirac-script.py') if not os.path.exists(script_path): raise BackendError('Dirac', 'No "dirac-script.py" found in j.inputdir or j.master.inputdir') parametric = True # Read old script f = open(script_path, 'r') script = f.read() f.close() # Create new script - ##note instead of using get_parametric_dataset # could just use j.inputdata. if parametric is True: parametric_datasets = get_parametric_datasets(script.split('\n')) if j.master: if len(parametric_datasets) != len(j.master.subjobs): raise BackendError('Dirac', 'number of parametric datasets defined in API script doesn\'t match number of master.subjobs') if j.inputdata and len(j.inputdata) > 0: _input_files = [f for f in j.inputdata if not isType(f, DiracFile)] else: _input_files = [] if set(parametric_datasets[j.id]).symmetric_difference(set([f.namePattern for f in _input_files])): raise BackendError( 'Dirac', 'Mismatch between dirac-script and job attributes.') script = script.replace('.setParametricInputData(%s)' % str(parametric_datasets), '.setInputData(%s)' % str(parametric_datasets[j.id])) script = script.replace('%n', str(j.id)) # name start_user_settings = '# <-- user settings\n' new_script = script[ :script.find(start_user_settings) + len(start_user_settings)] job_ident = get_job_ident(script.split('\n')) for key, value in self.settings.iteritems(): if str(key).startswith('set'): _key = key[3:] else: _key = key if type(value) is str: template = '%s.set%s("%s")\n' else: template = '%s.set%s(%s)\n' new_script += template % (job_ident, str(_key), str(value)) new_script += script[script.find('# user settings -->'):] # Save new script new_script_filename = os.path.join(j.getInputWorkspace().getPath(), 'dirac-script.py') f = open(new_script_filename, 'w') f.write(new_script) f.flush() f.close() return self._common_submit(new_script_filename)