Skip to content

Commit 33c4edf

Browse files
authored
Merge pull request #8227 from aldbr/9.0_FIX_input-data-download-job-wrapper
[9.0] fix(wms): download input data in the job directory
2 parents 59b4cce + eb7c23c commit 33c4edf

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/DIRAC/WorkloadManagementSystem/Client/DownloadInputData.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ def __checkDiskSpace(self, totalSize):
243243
return S_ERROR(msg)
244244

245245
def __getDownloadDir(self, incrementCounter=True):
246+
jobIDPath = str(self.configuration.get("JobIDPath", os.getcwd()))
246247
if self.inputDataDirectory == "PerFile":
247248
if incrementCounter:
248249
self.counter += 1
249-
return tempfile.mkdtemp(prefix=f"InputData_{self.counter}", dir=os.getcwd())
250+
return tempfile.mkdtemp(prefix=f"InputData_{self.counter}", dir=jobIDPath)
250251
elif self.inputDataDirectory == "CWD":
251-
return os.getcwd()
252+
return jobIDPath
252253
else:
253254
return self.inputDataDirectory
254255

src/DIRAC/WorkloadManagementSystem/Client/test/Test_Client_DownloadInputData.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Test for WMS clients."""
22
# pylint: disable=protected-access, missing-docstring, invalid-name
33

4+
from pathlib import Path
5+
import shutil
46
import pytest
57

68
from unittest.mock import MagicMock
@@ -280,3 +282,30 @@ def test_DLI_execute_NoLocal(mocker, dli, mockSE):
280282
assert res["Value"]["Failed"]
281283
assert "/a/lfn/1.txt" in res["Value"]["Failed"], res
282284
assert res["Value"]["Failed"][0] == "/a/lfn/1.txt", res
285+
286+
287+
def test_DLI_execute_jobIDPath(mocker, dli, mockSE):
288+
"""Specify a jobIDPath. Output should be in the jobIDPath directory."""
289+
mocker.patch("DIRAC.WorkloadManagementSystem.Client.DownloadInputData.gConfig.getValue", return_value=2)
290+
291+
# Create the jobIDPath directory
292+
jobIDPath = Path().cwd() / "job" / "12345"
293+
jobIDPath.mkdir(parents=True, exist_ok=True)
294+
295+
dli.configuration["JobIDPath"] = str(jobIDPath)
296+
297+
mocker.patch("DIRAC.WorkloadManagementSystem.Client.DownloadInputData.gConfig.getValue", return_value=2)
298+
mockObjectSE = mockSE.return_value
299+
mockObjectSE.getFileMetadata.return_value = S_OK(
300+
{"Successful": {"/a/lfn/1.txt": {"Cached": 1, "Accessible": 0}}, "Failed": {}}
301+
)
302+
dli._downloadFromSE = MagicMock(side_effect=[S_ERROR("Failed to down"), S_OK({"path": jobIDPath / "1.txt"})])
303+
dli._isCache = MagicMock(return_value=True)
304+
res = dli.execute(dataToResolve=["/a/lfn/1.txt"])
305+
306+
assert res["OK"]
307+
assert not res["Value"]["Failed"]
308+
assert "/a/lfn/1.txt" in res["Value"]["Successful"], res
309+
310+
# Check that the output path is in the jobIDPath directory
311+
assert res["Value"]["Successful"]["/a/lfn/1.txt"]["path"] == jobIDPath / "1.txt", res

0 commit comments

Comments
 (0)