From 2f0ed8c755e78736fa3c6b9e6fb499581ee98335 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 7 Mar 2024 10:54:46 +0100 Subject: [PATCH] osbuild: ensure a usable /var/tmp is available inside the buildroot Colin asked for this in https://github.com/osbuild/bootc-image-builder/issues/223 and it's easy enough. --- osbuild/buildroot.py | 6 ++++++ test/mod/test_buildroot.py | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/osbuild/buildroot.py b/osbuild/buildroot.py index 85c3e192..9e16053b 100644 --- a/osbuild/buildroot.py +++ b/osbuild/buildroot.py @@ -138,6 +138,12 @@ class BuildRoot(contextlib.AbstractContextManager): self.var = os.path.join(self.tmp, "var") os.makedirs(self.var, exist_ok=True) + # Ensure /var/tmp is available, see + # https://github.com/osbuild/bootc-image-builder/issues/223 + try: + os.symlink("/tmp", os.path.join(self.var, "tmp")) + except FileExistsError: + pass proc = os.path.join(self.tmp, "proc") os.makedirs(proc) diff --git a/test/mod/test_buildroot.py b/test/mod/test_buildroot.py index 8197caae..d7146338 100644 --- a/test/mod/test_buildroot.py +++ b/test/mod/test_buildroot.py @@ -44,11 +44,19 @@ def test_basic(tempdir, runner): # Test we can use `.run` multiple times r = root.run(["/usr/bin/true"], monitor) - assert r.returncode == 0 + assert r.returncode == 0, f"{r.stdout} {r.stderr}" r = root.run(["/usr/bin/false"], monitor) assert r.returncode != 0 + # Test that fs setup looks correct + r = root.run(["readlink", "-f", "/var/tmp"], monitor) + assert r.returncode == 0 + assert r.stdout.strip().split("\n")[-1] == "/tmp" + r = root.run(["stat", "-L", "--format=%a", "/var/tmp"], monitor) + assert r.returncode == 0 + assert r.stdout.strip().split("\n")[-1] == "1777" + @pytest.mark.skipif(not TestBase.can_bind_mount(), reason="root only") def test_runner_fail(tempdir):