Skip to content

Commit faf7ae4

Browse files
fix(ci): configure image inspection for arbitrary Slurm UIDs
Signed-off-by: functionstackx <47992694+functionstackx@users.noreply.github.com>
1 parent 202b3af commit faf7ae4

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎scripts/ci/rocm/build_images.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ def record_image(docker, image_id, results, scratch):
4343
# Bind node-local inputs and copy evidence back as the submitting user.
4444
inspection = scratch / "image-inspection"
4545
inspection.mkdir(mode=0o700)
46+
(inspection / "home").mkdir(mode=0o700)
4647
shutil.copytree(results / "controller", inspection / "controller")
4748
for name in ("request.json", "image-build.json"):
4849
shutil.copyfile(results / name, inspection / name)
50+
# The Slurm UID need not have an image passwd entry. Libraries still need
51+
# a username and writable home/cache directories during import.
4952
try:
5053
run(
5154
docker.command(
@@ -56,6 +59,16 @@ def record_image(docker, image_id, results, scratch):
5659
docker.cgroup_parent,
5760
"--user",
5861
f"{os.getuid()}:{os.getgid()}",
62+
"--env",
63+
"HOME=/results/home",
64+
"--env",
65+
"USER=dynamo",
66+
"--env",
67+
"LOGNAME=dynamo",
68+
"--env",
69+
"XDG_CACHE_HOME=/results/home/.cache",
70+
"--env",
71+
"TORCHINDUCTOR_CACHE_DIR=/results/home/.cache/torchinductor",
5972
"--mount",
6073
f"type=bind,src={inspection},dst=/results",
6174
"--mount",

‎scripts/ci/tests/test_slurm_build_images.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Exercise the official image-build sequence without starting a daemon."""
44

5+
import getpass
56
import json
67
import os
78
import subprocess
@@ -206,6 +207,34 @@ def fail(command, log, **kwargs):
206207
)
207208
self.assertFalse((self.results / "build-manifest.json").exists())
208209

210+
def test_inspection_supports_uid_without_passwd_entry(self):
211+
(self.results / "image-build.json").write_text("{}")
212+
213+
def inspect(command, log, **kwargs):
214+
environment = dict(
215+
command[index + 1].split("=", 1)
216+
for index, argument in enumerate(command)
217+
if argument == "--env"
218+
)
219+
with (
220+
patch.dict(os.environ, environment, clear=True),
221+
patch("pwd.getpwuid", side_effect=KeyError("unmapped uid")),
222+
):
223+
self.assertEqual(getpass.getuser(), "dynamo")
224+
self.assertEqual(Path("~").expanduser(), Path("/results/home"))
225+
home = self.scratch / "image-inspection/home"
226+
(home / "probe").write_text("writable")
227+
self.assertTrue(
228+
Path(environment["TORCHINDUCTOR_CACHE_DIR"]).is_relative_to(
229+
"/results/home"
230+
)
231+
)
232+
233+
with patch.object(build_images, "run", side_effect=inspect):
234+
build_images.record_image(
235+
self.daemon, self.test["Id"], self.results, self.scratch
236+
)
237+
209238

210239
if __name__ == "__main__":
211240
unittest.main()

0 commit comments

Comments
 (0)