Skip to content

Commit

Permalink
tests: Reduce duplication
Browse files Browse the repository at this point in the history
Let's reduce the amount of duplication in the tests.
  • Loading branch information
DaanDeMeyer committed Aug 2, 2024
1 parent 7bf1855 commit a94f3d0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 46 deletions.
7 changes: 6 additions & 1 deletion mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

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
Expand Down Expand Up @@ -58,18 +57,14 @@ def mkosi(
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([
Expand All @@ -83,12 +78,12 @@ def mkosi(
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.
Expand Down
12 changes: 1 addition & 11 deletions tests/test_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down Expand Up @@ -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)
Expand Down
26 changes: 2 additions & 24 deletions tests/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sysext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_sysext(config: ImageConfig) -> None:
with Image(
config,
options=[
"--incremental",
"--clean-package-metadata=no",
"--format=directory",
],
Expand All @@ -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",
Expand Down

0 comments on commit a94f3d0

Please sign in to comment.