diff --git a/src/DIRAC/WorkloadManagementSystem/Client/DownloadInputData.py b/src/DIRAC/WorkloadManagementSystem/Client/DownloadInputData.py index d79a21f8e96..fe2a14b533f 100644 --- a/src/DIRAC/WorkloadManagementSystem/Client/DownloadInputData.py +++ b/src/DIRAC/WorkloadManagementSystem/Client/DownloadInputData.py @@ -243,12 +243,13 @@ def __checkDiskSpace(self, totalSize): return S_ERROR(msg) def __getDownloadDir(self, incrementCounter=True): + jobIDPath = str(self.configuration.get("JobIDPath", os.getcwd())) if self.inputDataDirectory == "PerFile": if incrementCounter: self.counter += 1 - return tempfile.mkdtemp(prefix=f"InputData_{self.counter}", dir=os.getcwd()) + return tempfile.mkdtemp(prefix=f"InputData_{self.counter}", dir=jobIDPath) elif self.inputDataDirectory == "CWD": - return os.getcwd() + return jobIDPath else: return self.inputDataDirectory diff --git a/src/DIRAC/WorkloadManagementSystem/Client/test/Test_Client_DownloadInputData.py b/src/DIRAC/WorkloadManagementSystem/Client/test/Test_Client_DownloadInputData.py index 1e7ea5fcca5..3984c64f6ed 100644 --- a/src/DIRAC/WorkloadManagementSystem/Client/test/Test_Client_DownloadInputData.py +++ b/src/DIRAC/WorkloadManagementSystem/Client/test/Test_Client_DownloadInputData.py @@ -1,6 +1,8 @@ """Test for WMS clients.""" # pylint: disable=protected-access, missing-docstring, invalid-name +from pathlib import Path +import shutil import pytest from unittest.mock import MagicMock @@ -280,3 +282,30 @@ def test_DLI_execute_NoLocal(mocker, dli, mockSE): assert res["Value"]["Failed"] assert "/a/lfn/1.txt" in res["Value"]["Failed"], res assert res["Value"]["Failed"][0] == "/a/lfn/1.txt", res + + +def test_DLI_execute_jobIDPath(mocker, dli, mockSE): + """Specify a jobIDPath. Output should be in the jobIDPath directory.""" + mocker.patch("DIRAC.WorkloadManagementSystem.Client.DownloadInputData.gConfig.getValue", return_value=2) + + # Create the jobIDPath directory + jobIDPath = Path().cwd() / "job" / "12345" + jobIDPath.mkdir(parents=True, exist_ok=True) + + dli.configuration["JobIDPath"] = str(jobIDPath) + + mocker.patch("DIRAC.WorkloadManagementSystem.Client.DownloadInputData.gConfig.getValue", return_value=2) + mockObjectSE = mockSE.return_value + mockObjectSE.getFileMetadata.return_value = S_OK( + {"Successful": {"/a/lfn/1.txt": {"Cached": 1, "Accessible": 0}}, "Failed": {}} + ) + dli._downloadFromSE = MagicMock(side_effect=[S_ERROR("Failed to down"), S_OK({"path": jobIDPath / "1.txt"})]) + dli._isCache = MagicMock(return_value=True) + res = dli.execute(dataToResolve=["/a/lfn/1.txt"]) + + assert res["OK"] + assert not res["Value"]["Failed"] + assert "/a/lfn/1.txt" in res["Value"]["Successful"], res + + # Check that the output path is in the jobIDPath directory + assert res["Value"]["Successful"]["/a/lfn/1.txt"]["path"] == jobIDPath / "1.txt", res