Skip to content

Commit f87f8df

Browse files
authored
Set srun job name to "<account>-CloudAI_install_docker_image.%Y%m%d_%H%M%S" (#544)
1 parent 09dff16 commit f87f8df

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

src/cloudai/util/docker_image_cache_manager.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import shutil
2020
import subprocess
21+
from datetime import datetime
2122
from pathlib import Path
2223
from typing import Optional
2324

@@ -185,7 +186,15 @@ def check_docker_image_exists(self, docker_image_url: str, docker_image_filename
185186
def _import_docker_image(
186187
self, srun_prefix: str, docker_image_url: str, docker_image_path: Path
187188
) -> DockerImageCacheResult:
188-
enroot_import_cmd = f"{srun_prefix} enroot import -o {docker_image_path} docker://{docker_image_url}"
189+
job_name = "CloudAI_install_docker_image"
190+
if self.system.account:
191+
job_name = f"{self.system.account}-{job_name}.{datetime.now().strftime('%Y%m%d_%H%M%S')}"
192+
else:
193+
job_name = f"{job_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
194+
195+
enroot_import_cmd = (
196+
f"{srun_prefix} --job-name={job_name} enroot import -o {docker_image_path} docker://{docker_image_url}"
197+
)
189198
logging.debug(f"Importing Docker image: {enroot_import_cmd}")
190199
try:
191200
p = subprocess.run(enroot_import_cmd, shell=True, check=True, capture_output=True, text=True)

tests/test_docker_image_cache_manager.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ def test_cache_docker_image(
108108
] # Ensure all path checks return True
109109
mock_run.return_value = subprocess.CompletedProcess(args=["cmd"], returncode=0, stderr="")
110110
result = manager.cache_docker_image("docker.io/hello-world", "image.tar.gz")
111-
mock_run.assert_called_once_with(
112-
(
113-
f"srun --export=ALL --partition={slurm_system.default_partition} enroot "
114-
f"import -o {slurm_system.install_path}/image.tar.gz docker://docker.io/hello-world"
115-
),
116-
shell=True,
117-
check=True,
118-
capture_output=True,
119-
text=True,
120-
)
111+
112+
assert mock_run.call_count == 1
113+
actual_command = mock_run.call_args[0][0]
114+
assert f"srun --export=ALL --partition={slurm_system.default_partition}" in actual_command
115+
assert "--job-name=CloudAI_install_docker_image_" in actual_command
116+
assert f"enroot import -o {slurm_system.install_path}/image.tar.gz docker://docker.io/hello-world" in actual_command
117+
assert mock_run.call_args[1] == {"shell": True, "check": True, "capture_output": True, "text": True}
118+
121119
assert result.success
122120
assert result.message == f"Docker image cached successfully at {slurm_system.install_path}/image.tar.gz."
123121

@@ -215,17 +213,25 @@ def test_docker_import_with_extra_system_config(slurm_system: SlurmSystem, accou
215213
res = manager.cache_docker_image("docker.io/hello-world", "docker_image.sqsh")
216214
assert res.success
217215

218-
command = f"srun --export=ALL --partition={slurm_system.default_partition}"
219-
if slurm_system.account:
220-
command += f" --account={slurm_system.account}"
221-
if slurm_system.gpus_per_node:
222-
command += " --gres=gpu:1"
223-
command += f" enroot import -o {slurm_system.install_path}/docker_image.sqsh docker://docker.io/hello-world"
224-
225-
mock_run.assert_called_once_with(
226-
command,
227-
shell=True,
228-
check=True,
229-
capture_output=True,
230-
text=True,
216+
assert mock_run.call_count == 1
217+
218+
actual_command = mock_run.call_args[0][0]
219+
220+
expected_prefix = f"srun --export=ALL --partition={slurm_system.default_partition}"
221+
assert expected_prefix in actual_command
222+
223+
if account:
224+
assert f"--account={account}" in actual_command
225+
assert f"--job-name={account}-CloudAI_install_docker_image." in actual_command
226+
else:
227+
assert "--job-name=CloudAI_install_docker_image_" in actual_command
228+
229+
if gpus_per_node:
230+
assert "--gres=gpu:1" in actual_command
231+
232+
assert (
233+
f"enroot import -o {slurm_system.install_path}/docker_image.sqsh docker://docker.io/hello-world"
234+
in actual_command
231235
)
236+
237+
assert mock_run.call_args[1] == {"shell": True, "check": True, "capture_output": True, "text": True}

0 commit comments

Comments
 (0)