From 8bf11dc3f6e418d7513260eb5ab0fa8c63797b62 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 14 Sep 2023 15:27:48 +0800 Subject: [PATCH] unit tests: fix test failures "The param /boot/boot/vmlinuz-xxx is incorrect" Currently, some tests failed with "The param /boot/boot/vmlinuz-xxx is incorrect", for example, [root@fedora kexec-tools]# shellspec spec/kdumpctl_manage_reset_spec.sh Examples: 1) kdumpctl reset-crashkernel [--kernel] [--fadump] Test the kdump dump mode --kernel=ALL kdumpctl should warn the user that crashkernel has been udpated When call reset_crashkernel --kernel=ALL 1.1) The error should include Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64 expected "The param /boot/boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect The param /boot/boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-5.15.6-100.fc34.x86_64. Please reboot the system for the change to take effect. The param /boot/boot/vmlinuz-5.14.14-200.fc34.x86_64 is incorrect The param /boot/boot/vmlinuz-5.14.14-200.fc34.x86_64 is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-5.14.14-200.fc34.x86_64. Please reboot the system for the change to take effect. The param /boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b is incorrect The param /boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b. Please reboot the system for the change to take effect." to include "Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64" # spec/kdumpctl_reset_crashkernel_spec.sh:69 This happens because when a system has a boot partition, grubby automatically prefixes a path with "/boot". The current boot loader entries used for tests already has the prefix "/boot" in the path and prefixing a path again will cause the above problem. grubby uses "mountpoint -q /boot" to tell if there is a boot partition. This patch mocks mountpoint so grubby knows the boot loader entries are for a system without a boot partition. Note this patch also avoids another error seen in the setup phase of the test "The param /boot/vmlinuz-xxx is incorrect". I believe this error is a bug of "grubby --update-kernel" in testing mode because running the grubby in normal mode actually works and "grubby --info=/boot/vmlinuz-*" also works in testing mode, [root@fedora support]# grubby --no-etc-grub-update --grub2 --bad-image-okay --env=grub_env -b boot_load_entries --args crashkernel=333M --update-kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64 The param /boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect [root@fedora support]# grubby --no-etc-grub-update --grub2 --bad-image-okay --env=grub_env -b boot_load_entries --info=/boot/vmlinuz-5.15.6-100.fc34.x86_64 index=0 kernel="/boot/boot/vmlinuz-5.15.6-100.fc34.x86_64" [root@fedora support]]# grubby --args crashkernel=333M --update-kernel=/boot/vmlinuz-6.0.7-301.fc37.x86_64 && echo "succeed" succeed Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_manage_crashkernel_spec.sh | 8 +++++++- spec/kdumpctl_reset_crashkernel_spec.sh | 8 +++++++- spec/support/bin/@grubby | 3 --- 3 files changed, 14 insertions(+), 5 deletions(-) delete mode 100755 spec/support/bin/@grubby diff --git a/spec/kdumpctl_manage_crashkernel_spec.sh b/spec/kdumpctl_manage_crashkernel_spec.sh index bae3f31..3255d9a 100644 --- a/spec/kdumpctl_manage_crashkernel_spec.sh +++ b/spec/kdumpctl_manage_crashkernel_spec.sh @@ -42,6 +42,12 @@ Describe 'Management of the kernel crashkernel parameter.' rm -rf "$KDUMP_SPEC_TEST_RUN_DIR" } + # the boot loader entries are for a system without a boot partition, mock + # mountpoint to let grubby know it + Mock mountpoint + exit 1 + End + grubby() { # - --no-etc-grub-update, not update /etc/default/grub # - --bad-image-okay, don't check the validity of the image @@ -49,7 +55,7 @@ Describe 'Management of the kernel crashkernel parameter.' # the default /boot/grub2/grubenv # - --bls-directory, specify custom BootLoaderSpec config files to avoid # modifying the default /boot/loader/entries - @grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + /usr/sbin/grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } # The mocking breaks has_command. Mock it as well to fix the tests. diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh index 2e3b2ba..88ff5a9 100644 --- a/spec/kdumpctl_reset_crashkernel_spec.sh +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -19,6 +19,12 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' BeforeAll 'setup' AfterAll 'cleanup' + # the boot loader entries are for a system without a boot partition, mock + # mountpoint to let grubby know it + Mock mountpoint + exit 1 + End + grubby() { # - --no-etc-grub-update, not update /etc/default/grub # - --bad-image-okay, don't check the validity of the image @@ -26,7 +32,7 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' # the default /boot/grub2/grubenv # - --bls-directory, specify custom BootLoaderSpec config files to avoid # modifying the default /boot/loader/entries - @grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + /usr/sbin/grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } # The mocking breaks has_command. Mock it as well to fix the tests. diff --git a/spec/support/bin/@grubby b/spec/support/bin/@grubby deleted file mode 100755 index 2a9b33f..0000000 --- a/spec/support/bin/@grubby +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e -. "$SHELLSPEC_SUPPORT_BIN" -invoke grubby "$@"