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 <prudo@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
This commit is contained in:
Coiby Xu 2023-09-14 15:27:48 +08:00
parent 2f52973feb
commit 8bf11dc3f6
3 changed files with 14 additions and 5 deletions

View File

@ -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.

View File

@ -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.

View File

@ -1,3 +0,0 @@
#!/bin/sh -e
. "$SHELLSPEC_SUPPORT_BIN"
invoke grubby "$@"