]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
tests: Use temporary mount point
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 10 Dec 2023 09:54:31 +0000 (10:54 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 10 Dec 2023 10:49:46 +0000 (11:49 +0100)
Instead of creating a directory owned by root in the cwd, let's just
use a temporary directory that we remove again afterwards.

tests/test_initrd.py

index 095409c1ec21d075af98a91e90705a6f43eefc92..428edc36a207a869e8094f4123774f01c67d3607 100644 (file)
@@ -97,10 +97,10 @@ def test_initrd_lvm(initrd: Image) -> None:
         run(["udevadm", "wait", "/dev/vg_mkosi/lv0"])
         run([f"mkfs.{image.distribution.filesystem()}", "-L", "root", "/dev/vg_mkosi/lv0"])
 
-        with mount(Path("/dev/vg_mkosi/lv0"), Path("mnt")) as mnt:
+        with tempfile.TemporaryDirectory() as mnt, mount(Path("/dev/vg_mkosi/lv0"), Path(mnt)):
             # The image might have been built unprivileged so we need to fix the file ownership. Making all the
             # files owned by root isn't completely correct but good enough for the purposes of the test.
-            copy_tree(Path(image.output_dir.name) / "image", mnt, preserve_owner=False)
+            copy_tree(Path(image.output_dir.name) / "image", Path(mnt), preserve_owner=False)
 
         stack.close()
 
@@ -214,10 +214,10 @@ def test_initrd_luks_lvm(initrd: Image, passphrase: Path) -> None:
         run(["udevadm", "wait", "/dev/vg_mkosi/lv0"])
         run([f"mkfs.{image.distribution.filesystem()}", "-L", "root", "/dev/vg_mkosi/lv0"])
 
-        with mount(Path("/dev/vg_mkosi/lv0"), Path("mnt")) as mnt:
+        with tempfile.TemporaryDirectory() as mnt, mount(Path("/dev/vg_mkosi/lv0"), Path(mnt)):
             # The image might have been built unprivileged so we need to fix the file ownership. Making all the
             # files owned by root isn't completely correct but good enough for the purposes of the test.
-            copy_tree(Path(image.output_dir.name) / "image", mnt, preserve_owner=False)
+            copy_tree(Path(image.output_dir.name) / "image", Path(mnt), preserve_owner=False)
 
         stack.close()