Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-20 07:59:01

0001 import atexit
0002 import os
0003 import random
0004 import string
0005 import sys
0006 import uuid
0007 
0008 from pandaharvester.harvestercore.file_spec import FileSpec
0009 from pandaharvester.harvestercore.job_spec import JobSpec
0010 from pandaharvester.harvestercore.plugin_factory import PluginFactory
0011 from pandaharvester.harvestercore.queue_config_mapper import QueueConfigMapper
0012 
0013 file_prefix = "panda.sgotest."
0014 
0015 
0016 def exit_func():
0017     for f in os.listdir("."):
0018         if f.startswith(file_prefix):
0019             os.remove(f)
0020 
0021 
0022 atexit.register(exit_func)
0023 
0024 queueName = sys.argv[1]
0025 queueConfigMapper = QueueConfigMapper()
0026 queueConfig = queueConfigMapper.get_queue(queueName)
0027 
0028 fileSpec = FileSpec()
0029 fileSpec.fileType = "output"
0030 fileSpec.lfn = file_prefix + uuid.uuid4().hex + ".gz"
0031 fileSpec.fileAttributes = {"guid": str(uuid.uuid4())}
0032 fileSpec.chksum = "0d439274"
0033 assFileSpec = FileSpec()
0034 assFileSpec.lfn = file_prefix + uuid.uuid4().hex
0035 assFileSpec.fileType = "es_output"
0036 assFileSpec.fsize = random.randint(10, 100)
0037 assFileSpec.path = os.getcwd() + "/" + assFileSpec.lfn
0038 oFile = open(assFileSpec.lfn, "w")
0039 oFile.write("".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(assFileSpec.fsize)))
0040 oFile.close()
0041 fileSpec.add_associated_file(assFileSpec)
0042 jobSpec = JobSpec()
0043 jobSpec.jobParams = {
0044     "outFiles": fileSpec.lfn + ",log",
0045     "scopeOut": "panda",
0046     "scopeLog": "panda",
0047     "logFile": "log",
0048     "realDatasets": "panda." + fileSpec.lfn,
0049     "ddmEndPointOut": "BNL-OSG2_DATADISK",
0050 }
0051 jobSpec.add_out_file(fileSpec)
0052 
0053 pluginFactory = PluginFactory()
0054 
0055 # get stage-out plugin
0056 stagerCore = pluginFactory.get_plugin(queueConfig.stager)
0057 print(f"plugin={stagerCore.__class__.__name__}")
0058 
0059 print("testing zip")
0060 tmpStat, tmpOut = stagerCore.zip_output(jobSpec)
0061 if tmpStat:
0062     print(" OK")
0063 else:
0064     print(f" NG {tmpOut}")
0065 
0066 print()
0067 
0068 print("testing stage-out")
0069 transferID = None
0070 tmpStat, tmpOut = stagerCore.trigger_stage_out(jobSpec)
0071 if tmpStat:
0072     if fileSpec.fileAttributes is None and "transferID" in fileSpec.fileAttributes:
0073         transferID = fileSpec.fileAttributes["transferID"]
0074     print(f" OK transferID={transferID}")
0075 else:
0076     print(f" NG {tmpOut}")
0077     sys.exit(1)
0078 
0079 print()
0080 
0081 print(f"checking status for transferID={transferID}")
0082 tmpStat, tmpOut = stagerCore.check_stage_out_status(jobSpec)
0083 if tmpStat:
0084     print(" OK")
0085 else:
0086     print(f" NG {tmpOut}")