def config_files(): """ Load the config files in a way similar to a full Ganga session """ load_config_files() yield clear_config()
def df(): load_config_files() from GangaDirac.Lib.Files.DiracFile import DiracFile f = DiracFile('np', 'ld', 'lfn') f.locations = ['location'] f.guid = 'guid' yield f clear_config()
def load_config(): """Load the Ganga config files before the test and clean them up afterwards""" load_config_files() # make sure post-boostrap hook is run to ensure Dirac config options are set correctly # Only becomes an issue if this test is run on it's own from GangaLHCb import postBootstrapHook postBootstrapHook() yield clear_config()
def dirac_job(): load_config_files() sandbox_str = random_str() time.sleep(0.5) get_file_str = random_str() time.sleep(0.5) remove_file_str = random_str() exe_script = """ #!/bin/bash echo '%s' > sandboxFile.txt echo '%s' > getFile.dst echo '%s' > removeFile.dst """ % (sandbox_str, get_file_str, remove_file_str) logger.info("exe_script:\n%s\n" % str(exe_script)) exe_file, exe_path_name = tempfile.mkstemp() with os.fdopen(exe_file, 'wb') as f: f.write(exe_script) api_script = """ from DIRAC.Interfaces.API.Dirac import Dirac from DIRAC.Interfaces.API.Job import Job from DIRAC.Core.Utilities.SiteSEMapping import getSEsForCountry uk_ses = getSEsForCountry('uk')['Value'] j = Job() j.setName('Ganga-DiracCommands-InitTestJob') j.setCPUTime(10) j.setExecutable('###EXE_SCRIPT_BASE###','','Ganga_Executable.log') j.setInputSandbox(['###EXE_SCRIPT###']) j.setOutputSandbox(['std.out','std.err','sandboxFile.txt']) j.setOutputData(['getFile.dst', 'removeFile.dst'], outputSE=uk_ses) j.setBannedSites(['LCG.CERN.ch', 'LCG.CNAF.it', 'LCG.GRIDKA.de', 'LCG.IN2P3.fr', 'LCG.NIKHEF.nl', 'LCG.PIC.es', 'LCG.RAL.uk', 'LCG.SARA.nl']) #submit the job to dirac dirac=Dirac() result = dirac.submit(j) output(result) """ api_script = dedent(api_script) final_submit_script = api_script.replace('###EXE_SCRIPT###', exe_path_name).replace('###EXE_SCRIPT_BASE###', os.path.basename(exe_path_name)) confirm = execute(final_submit_script) if not isinstance(confirm, dict): raise RuntimeError('Problem submitting job\n{0}'.format(confirm)) job_id = confirm['Value'] logger.info(job_id) os.remove(exe_path_name) logger.info('Waiting for DIRAC job to finish') timeout = 1200 end_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=timeout) status = execute('status([%s], %s)' % (job_id, repr(statusmapping))) while statusmapping[status[0][1]] not in ['completed', 'failed'] and datetime.datetime.utcnow() < end_time: time.sleep(5) status = execute('status([%s], %s)' % (job_id, repr(statusmapping))) assert statusmapping[status[0][1]] == 'completed', 'job not completed properly: %s' % status logger.info("status: %s", status) output_data_info = execute('getOutputDataInfo("%s")' % job_id) logger.info(output_data_info) while not output_data_info.get('OK', True): time.sleep(5) output_data_info = execute('getOutputDataInfo("%s")' % job_id) logger.info("\n%s\n", output_data_info) logger.info("\n\n\noutput_data_info: %s\n\n\n" % output_data_info) get_file_lfn = output_data_info['getFile.dst']['LFN'] remove_file_lfn = output_data_info['removeFile.dst']['LFN'] logger.info("%s %s", get_file_lfn, remove_file_lfn) yield JobInfo(job_id, get_file_lfn, remove_file_lfn) confirm = execute('removeFile("%s")' % get_file_lfn) assert confirm['OK'], 'Command not executed successfully' clear_config()
def load_config(): """Load the Ganga config files before the test and clean them up afterwards""" load_config_files() yield clear_config()
def db(): """Provides a DiracBase object per test function""" load_config_files() from GangaDirac.Lib.Backends.DiracBase import DiracBase yield DiracBase() clear_config()