Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to allow Gaudi slc6 jobs to run inside apptainer #2333

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ gangadir = ###GANGADIR###
sys.path.insert(0, gangadir)
sys.path.insert(0,os.path.join(os.getcwd(),PYTHON_DIR))

runenv = os.environ.copy()
for key,value in environment.items():
runenv[key] = value
runenv = dict()
result = subprocess.run(["bash", "-lc", "printenv"], capture_output=True, encoding='utf-8')
for line in result.stdout.split('\\n'):
varval = line.strip().split('=')
if len(varval) < 2:
pass
else:
content = ''.join(varval[1:])
if not str(content).startswith('() {'):
runenv[varval[0]] = content

outfile=open('stdout','w')
errorfile=open('stderr','w')
Expand Down
19 changes: 17 additions & 2 deletions ganga/GangaLHCb/Lib/RTHandlers/GaudiExecRTHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def prepareCommand(app):
for _arg in app.run_args:
run_args += ' %s ' % _arg

run_cmd = ' export ganga_jobid=%s && ./run %s ' % (app.getJobObject().fqid, run_args)
run_cmd = f' export ganga_jobid={app.getJobObject().fqid} && ./run {run_args} '
if 'slc6' in app.platform:
run_cmd = f'sed -i "s/lb-run /lb-run --container apptainer /g" ./run && {run_cmd}'

if not app.useGaudiRun:
full_cmd = sourceEnv + run_cmd + 'python %s' % app.getWrapperScriptName()
Expand Down Expand Up @@ -792,13 +794,26 @@ def flush_streams(pipe):
# Extract any/_all_ (b/g)zip files on the WN
extractAllTarFiles('.')

runenv = dict()
result = subprocess.run(["bash", "-lc",
"source /cvmfs/lhcb.cern.ch/lib/LbEnv && printenv"],
capture_output=True, encoding='utf-8')
for line in result.stdout.split('\\n'):
varval = line.strip().split('=')
if len(varval) < 2:
pass
else:
content = ''.join(varval[1:])
if not str(content).startswith('() {'):
runenv[varval[0]] = content

print("Executing: %s" % '###COMMAND###'+' '+' '.join(sys.argv[1:]))

# Execute the actual command on the WN
# NB os.system caused the entire stream to be captured before being streamed in some cases
pipe = subprocess.Popen('###COMMAND###'+' '+' '.join(sys.argv[1:]), shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
universal_newlines=True, errors="replace")
universal_newlines=True, errors="replace", env=runenv)

# Flush the stdout/stderr as the process is running correctly
flush_streams(pipe)
Expand Down