From 35dd6a9f3b5311fc4a016b9ba3887071d9e98624 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Thu, 16 May 2024 23:25:01 +0100 Subject: [PATCH 1/3] Update Condor.py (#2339) --- ganga/GangaCore/Lib/Condor/Condor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ganga/GangaCore/Lib/Condor/Condor.py b/ganga/GangaCore/Lib/Condor/Condor.py index 704a754103..10c80d1ad8 100755 --- a/ganga/GangaCore/Lib/Condor/Condor.py +++ b/ganga/GangaCore/Lib/Condor/Condor.py @@ -345,6 +345,7 @@ def prepareSubjob(self, job, jobconfig, master_input_sandbox): "", "workdir = os.getcwd()", "execmd = %s" % repr(exeCmd), + "runenv = os.environ.copy()", "", "###VIRTUALIZATION###", "", From 6ac63273c94dcc88df4d4a2b1818268b7a8a97c7 Mon Sep 17 00:00:00 2001 From: Ulrik Egede Date: Fri, 17 May 2024 08:59:55 +1000 Subject: [PATCH 2/3] Update to make sure that Local jobs run in fresh environment (#2338) * Update to make sure that Local jobs run in fresh environment * Avoid functions and ensure that environment is clean * Add test case --- .../Lib/Localhost/LocalHostExec.py.template | 15 ++++++++++--- ganga/GangaCore/test/GPI/TestLocalCleanenv.py | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 ganga/GangaCore/test/GPI/TestLocalCleanenv.py diff --git a/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template b/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template index 2ab0d73256..f89b21ca7c 100644 --- a/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template +++ b/ganga/GangaCore/Lib/Localhost/LocalHostExec.py.template @@ -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') diff --git a/ganga/GangaCore/test/GPI/TestLocalCleanenv.py b/ganga/GangaCore/test/GPI/TestLocalCleanenv.py new file mode 100644 index 0000000000..246cb0d5a2 --- /dev/null +++ b/ganga/GangaCore/test/GPI/TestLocalCleanenv.py @@ -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)) From ec140deddd1852132637fb2ee781c59a7b00a9d4 Mon Sep 17 00:00:00 2001 From: Mark Smith Date: Mon, 20 May 2024 17:37:58 +0200 Subject: [PATCH 3/3] tidy --- ganga/GangaLHCb/Utility/LHCbDIRACenv.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ganga/GangaLHCb/Utility/LHCbDIRACenv.py b/ganga/GangaLHCb/Utility/LHCbDIRACenv.py index b2f7770949..00db422fc9 100644 --- a/ganga/GangaLHCb/Utility/LHCbDIRACenv.py +++ b/ganga/GangaLHCb/Utility/LHCbDIRACenv.py @@ -24,8 +24,6 @@ def store_dirac_environment(): # except KeyError: # logger.error("Environment variable %s is missing. Can't cache LHCbDIRAC environment.", platform_env_var) # raise PluginError - # While LHCbDirac is only available for gcc49 we shall unfortunately hard-code the platform. - platform = 'x86_64-slc6-gcc49-opt' requestedVersion = GangaCore.Utility.Config.getConfig('LHCb')['LHCbDiracVersion'] @@ -33,7 +31,7 @@ def store_dirac_environment(): logger.warn( f"Specific DIRAC version ({requestedVersion}) is set in the [LHCb]LHCbDiracVersion configuration parameter. Unless you really know what you are doing, this should not be done.") - fdir = join(expanduser("~/.cache/Ganga/GangaLHCb"), platform) + fdir = expanduser("~/.cache/Ganga/GangaLHCb") fname = join(fdir, requestedVersion) cmd = ( @@ -50,7 +48,7 @@ def store_dirac_environment(): raise OptionValueError(f"LHCbDirac version {requestedVersion} does not exist") try: write_env_cache(env, fname) - logger.debug(f"Storing new LHCbDirac environment ({requestedVersion}:{platform})") + logger.debug(f"Storing new LHCbDirac environment ({requestedVersion})") except (OSError, IOError, TypeError): logger.error("Unable to store LHCbDirac environment") raise PluginError