From 84fc4c9903dd5a3af84e9a6f9c8c9efcea98043f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 20 Feb 2024 13:47:52 +0100 Subject: [PATCH] Extend unit test for org.osbuild.grub2 stage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test the content of the /etc/default/grub config file based on the provided stage options. Signed-off-by: Tomáš Hozza --- stages/test/test_grub2.py | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/stages/test/test_grub2.py b/stages/test/test_grub2.py index f3197baf..5d664400 100644 --- a/stages/test/test_grub2.py +++ b/stages/test/test_grub2.py @@ -1,5 +1,9 @@ #!/usr/bin/python3 +import os.path + +import pytest + from osbuild.testutil import make_fake_tree STAGE_NAME = "org.osbuild.grub2" @@ -26,3 +30,54 @@ def test_grub2_copy_efi_data(tmp_path, stage_module): stage_module.main(fake_tree, test_options) assert (fake_tree / "boot/efi/EFI/fedora/a.shim").exists() assert (fake_tree / "boot/efi/EFI/BOOT/BOOTX64.EFI").exists() + + +# Test that the /etc/default/grub file is created with the correct content +@pytest.mark.parametrize("test_data,expected_conf", [ + # default + ({}, """GRUB_CMDLINE_LINUX="" +GRUB_TIMEOUT=0 +GRUB_ENABLE_BLSCFG=true +"""), + # custom + ({ + "default": "0", + "timeout": 10, + "terminal_input": ["console"], + "terminal_output": ["serial"], + "serial": "serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1", + }, """GRUB_CMDLINE_LINUX="" +GRUB_TIMEOUT=10 +GRUB_ENABLE_BLSCFG=true +GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" +GRUB_TERMINAL_INPUT="console" +GRUB_TERMINAL_OUTPUT="serial" +GRUB_DEFAULT=0 +"""), +]) +def test_grub2_default_conf(tmp_path, stage_module, test_data, expected_conf): + treedir = tmp_path / "tree" + confpath = treedir / "etc/default/grub" + confpath.parent.mkdir(parents=True, exist_ok=True) + + options = { + "rootfs": { + "label": "root" + }, + "entries": [ + { + "id": "fff", + "kernel": "4.18", + "product": { + "name": "Fedora", + "version": "40" + } + } + ] + } + + options["config"] = test_data + stage_module.main(treedir, options) + + assert os.path.exists(confpath) + assert confpath.read_text() == expected_conf