Skip to content

Commit

Permalink
test: fix when running with py2
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Dec 14, 2021
1 parent 51fd002 commit 96de927
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
46 changes: 31 additions & 15 deletions src/DIRAC/Resources/Computing/SingularityComputingElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, ceUniqueID):
self.__workdir = CONTAINER_WORKDIR
self.__innerdir = CONTAINER_INNERDIR
self.__singularityBin = "singularity"
self.__installDIRACInContainer = self.ceParameters.get("InstallDIRACInContainer", True)
self.__installDIRACInContainer = self.ceParameters.get("InstallDIRACInContainer", True)
if isinstance(self.__installDIRACInContainer, six.string_types) and self.__installDIRACInContainer.lower() in (
"false",
"no",
Expand Down Expand Up @@ -155,8 +155,17 @@ def __hasSingularity(self):
# No suitable binaries found
return False

@staticmethod
def __findInstallBaseDir():
"""Find the path to root of the current DIRAC installation"""
if six.PY3:
return os.path.realpath(sys.base_prefix) # pylint: disable=no-member
else:
candidate = os.path.join(DIRAC.rootPath, "bashrc")
return os.path.dirname(os.path.realpath(candidate))

def __getInstallFlags(self, infoDict=None):
"""Get the flags for installing inside the container."""
"""Get the flags for installing inside the container."""

if not infoDict:
infoDict = {}
Expand All @@ -168,20 +177,20 @@ def __getInstallFlags(self, infoDict=None):
setup = gConfig.getValue("/DIRAC/Setup", "unknown")
setup = str(setup)

diracProject = "DIRAC"
diracProject = "DIRAC"

project = str(infoDict.get("Project"))
if not project or project == "None":
diracProject = Operations.Operations(setup=setup).getValue("Pilot/Project", "") + project
project = str(infoDict.get("Project"))
if not project or project == "None":
diracProject = Operations.Operations(setup=setup).getValue("Pilot/Project", "") + project

diracVersions = str(infoDict["Setups"][setup].get("Version")).split(",")
if not diracVersions:
diracVersions = str(infoDict["Setups"]["Defaults"].get("Version")).split(",")
if not diracVersions:
diracVersions = Operations.Operations(setup=setup).getValue("Pilot/Version", [])
version = diracVersions[0].strip()
version = diracVersions[0].strip()

return diracProject, version
return diracProject, version

@staticmethod
def __getConfigFlags(infoDict=None):
Expand Down Expand Up @@ -265,8 +274,8 @@ def __createWorkArea(self, jobDesc=None, log=None, logLevel="INFO", proxy=None):
wrapperPath = result["Value"]

if self.__installDIRACInContainer:
if six.PY2:
result = S_ERROR("InstallDIRACInContainer is not supported with Python 2")
if six.PY2:
result = S_ERROR("InstallDIRACInContainer is not supported with Python 2")
result["ReschedulePayload"] = True
return result

Expand All @@ -276,11 +285,11 @@ def __createWorkArea(self, jobDesc=None, log=None, logLevel="INFO", proxy=None):
infoDict = json.load(pj)

# Extra Wrapper (Container DIRAC installer)
installFlags = self.__getInstallFlags(infoDict)
installFlags = self.__getInstallFlags(infoDict)
wrapSubs = {
"next_wrapper": wrapperPath,
"dirac_project": installFlags[0],
"version": installFlags[1],
"dirac_project": installFlags[0],
"version": installFlags[1],
"config_args": self.__getConfigFlags(infoDict),
}
CONTAINER_WRAPPER = CONTAINER_WRAPPER_INSTALL
Expand All @@ -291,7 +300,14 @@ def __createWorkArea(self, jobDesc=None, log=None, logLevel="INFO", proxy=None):
"dirac_env_var": os.environ.get("DIRAC", ""),
"diracos_env_var": os.environ.get("DIRACOS", ""),
}
wrapSubs["rc_script"] = os.path.join(os.path.realpath(sys.base_prefix), "diracosrc")
if six.PY2:
shutil.copyfile(
os.path.join(self.__findInstallBaseDir(), "bashrc"),
os.path.join(tmpDir, "bashrc"),
)
wrapSubs["rc_script"] = "bashrc"
else:
wrapSubs["rc_script"] = os.path.join(self.__findInstallBaseDir(), "diracosrc")
shutil.copyfile("pilot.cfg", os.path.join(tmpDir, "pilot.cfg"))
CONTAINER_WRAPPER = CONTAINER_WRAPPER_NO_INSTALL

Expand Down Expand Up @@ -405,7 +421,7 @@ def submitJob(self, executableFile, proxy=None, **kwargs):
if withCVMFS:
cmd.extend(["--bind", "/cvmfs"])
if not self.__installDIRACInContainer:
cmd.extend(["--bind", "{0}:{0}:ro".format(os.path.realpath(sys.base_prefix))])
cmd.extend(["--bind", "{0}:{0}:ro".format(self.__findInstallBaseDir())])
if "ContainerBind" in self.ceParameters:
bindPaths = self.ceParameters["ContainerBind"].split(",")
for bindPath in bindPaths:
Expand Down
11 changes: 9 additions & 2 deletions tests/Integration/Resources/Computing/Test_SingularityCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This test is here and not in the unit tests because it requires singularity to be installed.
"""

import six
import os
import shutil

Expand Down Expand Up @@ -35,7 +36,10 @@ def test_submitJob():
assert res["ReschedulePayload"] is True
res = ce.getCEStatus()
assert res["OK"] is True
assert res["SubmittedJobs"] == 1
if six.PY2:
assert res["SubmittedJobs"] == 0
else:
assert res["SubmittedJobs"] == 1
_stopJob(1)
for ff in ["testJob.py", "pilot.json"]:
if os.path.isfile(ff):
Expand Down Expand Up @@ -73,7 +77,10 @@ def test_submitJobWrapper():

res = ce.getCEStatus()
assert res["OK"] is True
assert res["SubmittedJobs"] == 1
if six.PY2:
assert res["SubmittedJobs"] == 0
else:
assert res["SubmittedJobs"] == 1

_stopJob(2)
for ff in ["testJob.py", "stop_job_2", "job.info", "std.out", "pilot.json"]:
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/all_integration_client_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pytest "${THIS_DIR}/ProductionSystem/Test_Client_TS_Prod.py" |& tee -a clientTes

#-------------------------------------------------------------------------------#
echo -e "*** $(date -u) **** Resources TESTS ****\n"
pytest "${THIS_DIR}/Resources/Computing/Test_SingularityCE.py" |& tee -a "${SERVER_TEST_OUTPUT}"; (( ERR |= "${?}" ))
pytest "${THIS_DIR}/Resources/Computing/Test_SingularityCE.py" |& tee -a clientTestOutputs.txt; (( ERR |= "${?}" ))

#-------------------------------------------------------------------------------#
echo -e "*** $(date -u) **** DataManager TESTS ****\n"
Expand Down

0 comments on commit 96de927

Please sign in to comment.