Skip to content

Commit

Permalink
Update to make sure that Local jobs run in fresh environment (#2338)
Browse files Browse the repository at this point in the history
* Update to make sure that Local jobs run in fresh environment

* Avoid functions and ensure that environment is clean

* Add test case
  • Loading branch information
egede authored May 16, 2024
1 parent 35dd6a9 commit 6ac6327
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
15 changes: 12 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,18 @@ 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(["env -i HOME=\"$HOME\" bash -lc '(set -o posix; set)'"],
capture_output=True, encoding='utf-8',
shell=True)
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
21 changes: 21 additions & 0 deletions ganga/GangaCore/test/GPI/TestLocalCleanenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from GangaCore.testlib.GangaUnitTest import GangaUnitTest


class TestLocalCleanenv(GangaUnitTest):
def testLocalCleanenv(self):
from GangaCore.GPI import Job
from GangaTest.Framework.utils import sleep_until_completed, file_contains

envname = 'LocalCleanenv_sjt5p'
os.environ[envname] = 'Test'
os.environ['PATH'] = os.environ['PATH'] + ':' + envname

j = Job()

j.submit()

self.assertTrue(sleep_until_completed(j, 60), 'Timeout on completing job')

self.assertEqual(j.status, 'completed')
self.assertFalse(file_contains(j.outputdir + '/stdout', envname))

0 comments on commit 6ac6327

Please sign in to comment.