]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
tests: Reduce duplication
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 1 Aug 2024 14:38:30 +0000 (16:38 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 2 Aug 2024 07:32:04 +0000 (09:32 +0200)
Let's reduce the amount of duplication in the tests.

mkosi.conf
tests/__init__.py
tests/test_boot.py
tests/test_initrd.py
tests/test_sysext.py

index 6977bd19e812db968f76e96171e113998def719d..cb9fe1308a209458a8e1fe6bc5fcfecec2b7c20b 100644 (file)
@@ -35,7 +35,12 @@ RemoveFiles=
         /usr/lib/kernel/install.d/50-dracut.install
 
 # Make sure that SELinux doesn't run in enforcing mode even if it's pulled in as a dependency.
-KernelCommandLine=enforcing=0
+KernelCommandLine=
+        enforcing=0
+        systemd.log_ratelimit_kmsg=0
+        systemd.crash_shell
+        printk.devkmsg=on
+        systemd.early_core_pattern=/core
 
 KernelModulesInitrdExclude=.*
 KernelModulesInitrdInclude=default
index 75b47566334a13438fe1fc67c4cc5f3dee75e528..3900198a51c454709494653ac3206f6bed2ef73d 100644 (file)
@@ -13,7 +13,6 @@ from typing import Any, Optional
 
 import pytest
 
-from mkosi.config import finalize_term
 from mkosi.distributions import Distribution
 from mkosi.run import run
 from mkosi.types import _FILE, CompletedProcess, PathString
@@ -58,18 +57,14 @@ class Image:
         check: bool = True,
     ) -> CompletedProcess:
         kcl = [
-            f"TERM={finalize_term()}",
             "loglevel=6",
-            "systemd.crash_shell",
             "systemd.log_level=debug",
             "udev.log_level=info",
-            "systemd.log_ratelimit_kmsg=0",
             "systemd.show_status=false",
             "systemd.journald.forward_to_console",
             "systemd.journald.max_level_console=info",
-            "printk.devkmsg=on",
-            "systemd.early_core_pattern=/core",
             "systemd.firstboot=no",
+            "systemd.unit=mkosi-check-and-shutdown.service",
         ]
 
         return run([
@@ -83,12 +78,12 @@ class Image:
                 else []
             ),
             *(["--tools-tree-release", self.config.tools_tree_release] if self.config.tools_tree_release else []),
+            "--incremental",
+            "--ephemeral",
+            "--runtime-build-sources=no",
             *self.options,
             *options,
             "--output-dir", self.output_dir,
-            # Some tests ignore the default image config but we still want them to reuse the cache directory for the
-            # tools tree cache.
-            "--cache-dir", "mkosi.cache",
             *(f"--kernel-command-line={i}" for i in kcl),
             "--qemu-vsock=yes",
             # TODO: Drop once both Hyper-V bugs are fixed in Github Actions.
index 3e45178315b945b71eb4312f2a8bc5c30c254af1..fa245725a1bee416bc6fdb665ec4d57292d76925 100644 (file)
@@ -26,14 +26,7 @@ def have_vmspawn() -> bool:
 
 @pytest.mark.parametrize("format", [f for f in OutputFormat if f not in (OutputFormat.confext, OutputFormat.sysext)])
 def test_format(config: ImageConfig, format: OutputFormat) -> None:
-    with Image(
-        config,
-        options=[
-            "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
-            "--incremental",
-            "--ephemeral",
-        ],
-    ) as image:
+    with Image(config) as image:
         if image.config.distribution == Distribution.rhel_ubi and format in (OutputFormat.esp, OutputFormat.uki):
             pytest.skip("Cannot build RHEL-UBI images with format 'esp' or 'uki'")
 
@@ -91,9 +84,6 @@ def test_bootloader(config: ImageConfig, bootloader: Bootloader) -> None:
     with Image(
         config,
         options=[
-            "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
-            "--incremental",
-            "--ephemeral",
             "--format=disk",
             "--bootloader", str(bootloader),
             "--qemu-firmware", str(firmware)
index b07e2ae8c7d23bcca53691585ace3943121a8672..59833fba2fbec2bd050f1514ae0777f65283859a 100644 (file)
@@ -35,15 +35,7 @@ def passphrase() -> Iterator[Path]:
 
 
 def test_initrd(config: ImageConfig) -> None:
-    with Image(
-        config,
-        options=[
-            "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
-            "--incremental",
-            "--ephemeral",
-            "--format=disk",
-        ]
-    ) as image:
+    with Image(config, options=["--format=disk"]) as image:
         image.build()
         image.qemu()
 
@@ -53,13 +45,9 @@ def test_initrd_lvm(config: ImageConfig) -> None:
     with Image(
         config,
         options=[
-            "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
             # LVM confuses systemd-repart so we mask it for this test.
             "--kernel-command-line=systemd.mask=systemd-repart.service",
             "--kernel-command-line=root=LABEL=root",
-            "--kernel-command-line=rw",
-            "--incremental",
-            "--ephemeral",
             "--qemu-firmware=linux",
         ]
     ) as image, contextlib.ExitStack() as stack:
@@ -142,10 +130,7 @@ def test_initrd_luks(config: ImageConfig, passphrase: Path) -> None:
             options=[
                 "--repart-dir", repartd,
                 "--passphrase", passphrase,
-                "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
                 "--credential=cryptsetup.passphrase=mkosi",
-                "--incremental",
-                "--ephemeral",
                 "--format=disk",
             ]
         ) as image:
@@ -158,12 +143,8 @@ def test_initrd_luks_lvm(config: ImageConfig, passphrase: Path) -> None:
     with Image(
         config,
         options=[
-            "--kernel-command-line=systemd.unit=mkosi-check-and-shutdown.service",
             "--kernel-command-line=root=LABEL=root",
-            "--kernel-command-line=rw",
             "--credential=cryptsetup.passphrase=mkosi",
-            "--incremental",
-            "--ephemeral",
             "--qemu-firmware=linux",
         ]
     ) as image, contextlib.ExitStack() as stack:
@@ -215,10 +196,7 @@ def test_initrd_luks_lvm(config: ImageConfig, passphrase: Path) -> None:
 
 
 def test_initrd_size(config: ImageConfig) -> None:
-    with Image(
-        config,
-        options=["--incremental", "--format=directory"],
-    ) as image:
+    with Image(config) as image:
         image.build()
 
         # The fallback value is for CentOS and related distributions.
index df33bd6ab8e049708e94d52a114fed3c564dc1e7..6b5cf244eaa04c74ca6c11e8172b76c08be3f88a 100644 (file)
@@ -13,7 +13,6 @@ def test_sysext(config: ImageConfig) -> None:
     with Image(
         config,
         options=[
-            "--incremental",
             "--clean-package-metadata=no",
             "--format=directory",
         ],
@@ -24,6 +23,7 @@ def test_sysext(config: ImageConfig) -> None:
             image.config,
             options=[
                 "--directory", "",
+                "--incremental=no",
                 "--base-tree", Path(image.output_dir) / "image",
                 "--overlay",
                 "--package=dnsmasq",