Hi Coiby,
On Tue, 1 Mar 2022 14:17:26 +0800 Coiby Xu coxu@redhat.com wrote:
This commit adds a relatively thorough test suite for kdumpctl reset-crashkernel [--fadump=[on|off|nocma]] [--kernel=path_to_kernel] [--reboot] as implemented in commit 140da74 ("rewrite reset_crashkernel to support fadump and to used by RPM scriptlet").
grubby have a few options to support its own testing,
- --no-etc-grub-update, not update /etc/default/grub
- --bad-image-okay, don't check the validity of the image
- --env, specify custom grub2 environment block file to avoid modifying the default /boot/grub2/grubenv
- --bls-directory, specify custom BootLoaderSpec config files to avoid modifying the default /boot/loader/entries
So the grubby called by kdumpctl is mocked as @grubby --grub2 --no-etc-grub-update --bad-image-okay --env=$SPEC_TEST_DIR/env_temp -b $SPEC_TEST_DIR/boot_load_entries "$@" in the tests. To be able to call the actual grubby in the mock function [1], ShellSpec provides the following command $ shellspec --gen-bin @grubby to generate spec/support/bins/@grubby which is used to call the actual grubby.
kdumpctl has implemented its own version of updating /etc/default/grub in _update_kernel_cmdline_in_grub_etc_default. To avoiding writing to /etc/default/grub, this function is mocked as outputting its name and received arguments similar to python unitest's assert_called_with.
[1] https://github.com/shellspec/shellspec#execute-the-actual-command-within-a-m...
Signed-off-by: Coiby Xu coxu@redhat.com
spec/kdumpctl_reset_crashkernel_spec.sh | 223 ++++++++++++++++++ spec/support/bin/@grubby | 3 + ...846f63134c7295458cf36300ba5b-0-rescue.conf | 8 + ...58cf36300ba5b-5.14.14-200.fc34.x86_64.conf | 8 + ...458cf36300ba5b-5.15.6-100.fc34.x86_64.conf | 8 + spec/support/grub_env | 3 + 6 files changed, 253 insertions(+) create mode 100644 spec/kdumpctl_reset_crashkernel_spec.sh create mode 100755 spec/support/bin/@grubby create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf create mode 100644 spec/support/grub_env
diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh new file mode 100644 index 0000000..3fc7459 --- /dev/null +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -0,0 +1,223 @@ +#!/bin/bash +Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]'
- Include ./kdumpctl
- kernel1=/boot/vmlinuz-5.15.6-100.fc34.x86_64
- kernel2=/boot/vmlinuz-5.14.14-200.fc34.x86_64
- ck=222M
- KDUMP_SPEC_TEST_RUN_DIR=$(mktemp -d /tmp/spec_test.XXXXXXXXXX)
- current_kernel=5.15.6-100.fc34.x86_64
- setup() {
cp -r spec/support/boot_load_entries $KDUMP_SPEC_TEST_RUN_DIRcp spec/support/grub_env $KDUMP_SPEC_TEST_RUN_DIR/env_temp- }
- cleanup() {
rm -rf $KDUMP_SPEC_TEST_RUN_DIR- }
- BeforeAll 'setup'
- AfterAll 'cleanup'
- grubby() {
# - --no-etc-grub-update, not update /etc/default/grub# - --bad-image-okay, don't check the validity of the image# - --env, specify custom grub2 environment block file to avoid modifying# 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 "$@"- }
- Describe "Test the kdump dump mode "
kdump_crashkernel=$(get_default_crashkernel kdump)
I think the line above should ...
uname() {if [[ $1 == '-m' ]]; thenecho -n x86_64elif [[ $1 == '-r' ]]; thenecho -n $current_kernelfi}
...go here. Otherwise you are not mocking the call to uname in kdump_get_arch_recommend_crashkernel.
Context "when --kernel not specified"grubby --args crashkernel=$ck --update-kernel ALLSpecify 'kdumpctl should warn the user that crashkernel has been udpated'When call reset_crashkernelThe error should include "Updated crashkernel=$kdump_crashkernel"EndSpecify 'Current running kernel should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$kdump_crashkernel
Add this?
The line 3 of output should not include crashkernel=$ck
Thanks Philipp
EndSpecify 'Other kernel still use the old crashkernel value'When call grubby --info $kernel2The line 3 of output should include crashkernel=$ckEndEndContext "--kernel=ALL"grubby --args crashkernel=$ck --update-kernel ALLSpecify 'kdumpctl should warn the user that crashkernel has been udpated'When call reset_crashkernel --kernel=ALLThe error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel1"The error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel2"EndSpecify 'kernel1 should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$kdump_crashkernelEndSpecify 'kernel2 should have crashkernel updated'When call grubby --info $kernel2The line 3 of output should include crashkernel=$kdump_crashkernelEndEndContext "--kernel=/boot/one-kernel to update one specified kernel"grubby --args crashkernel=$ck --update-kernel ALLSpecify 'kdumpctl should warn the user that crashkernel has been updated'When call reset_crashkernel --kernel=$kernel1The error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel1"EndSpecify 'kernel1 should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$kdump_crashkernelEndSpecify 'kernel2 should have the old crashkernel'When call grubby --info $kernel2The line 3 of output should include crashkernel=$ckEndEnd- End
- Describe "FADump" fadump
uname() {if [[ $1 == '-m' ]]; thenecho -n ppc64leelif [[ $1 == '-r' ]]; thenecho -n $current_kernelfi}_update_kernel_arg_in_grub_etc_default() {# don't modify /etc/default/grub during the testecho _update_kernel_arg_in_grub_etc_default "$@"}kdump_crashkernel=$(get_default_crashkernel kdump)fadump_crashkernel=$(get_default_crashkernel fadump)Context "when no --kernel specified"grubby --args crashkernel=$ck --update-kernel ALLgrubby --remove-args=fadump --update-kernel ALLSpecify 'kdumpctl should warn the user that crashkernel has been udpated'When call reset_crashkernelThe error should include "Updated crashkernel=$kdump_crashkernel"EndSpecify 'Current running kernel should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$kdump_crashkernelEndSpecify 'Other kernel still use the old crashkernel value'When call grubby --info $kernel2The line 3 of output should include crashkernel=$ckEndEndContext "--kernel=ALL --fadump=on"grubby --args crashkernel=$ck --update-kernel ALLSpecify 'kdumpctl should warn the user that crashkernel has been udpated'When call reset_crashkernel --kernel=ALL --fadump=onThe line 1 of output should include "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel"The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1"The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2"EndSpecify 'kernel1 should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$fadump_crashkernelEndSpecify 'kernel2 should have crashkernel updated'When call get_grub_kernel_boot_parameter $kernel2 crashkernelThe output should equal $fadump_crashkernelEndEndContext "--kernel=/boot/one-kernel to update one specified kernel"grubby --args crashkernel=$ck --update-kernel ALLgrubby --args fadump=on --update-kernel $kernel1Specify 'kdumpctl should warn the user that crashkernel has been updated'When call reset_crashkernel --kernel=$kernel1The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1"EndSpecify 'kernel1 should have crashkernel updated'When call grubby --info $kernel1The line 3 of output should include crashkernel=$fadump_crashkernelEndSpecify 'kernel2 should have the old crashkernel'When call get_grub_kernel_boot_parameter $kernel2 crashkernelThe output should equal $ckEndEndContext "Update all kernels but without --fadump specified"grubby --args crashkernel=$ck --update-kernel ALLgrubby --args fadump=on --update-kernel $kernel1Specify 'kdumpctl should warn the user that crashkernel has been updated'When call reset_crashkernel --kernel=$kernel1The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1"EndSpecify 'kernel1 should have crashkernel updated'When call get_grub_kernel_boot_parameter $kernel1 crashkernelThe output should equal $fadump_crashkernelEndSpecify 'kernel2 should have the old crashkernel'When call get_grub_kernel_boot_parameter $kernel2 crashkernelThe output should equal $ckEndEndContext 'Switch between fadump=on and fadump=nocma'grubby --args crashkernel=$ck --update-kernel ALLgrubby --args fadump=on --update-kernel ALLSpecify 'fadump=on to fadump=nocma'When call reset_crashkernel --kernel=ALL --fadump=nocmaThe line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel"The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump nocma"The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1"The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2"EndSpecify 'kernel1 should have fadump=nocma in cmdline'When call get_grub_kernel_boot_parameter $kernel1 fadumpThe output should equal nocmaEndSpecify 'fadump=nocma to fadump=on'When call reset_crashkernel --kernel=ALL --fadump=onThe line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel"The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump on"The error should include "Updated fadump=on for kernel=$kernel1"EndSpecify 'kernel2 should have fadump=on in cmdline'When call get_grub_kernel_boot_parameter $kernel1 fadumpThe output should equal onEndEnd- End
+End diff --git a/spec/support/bin/@grubby b/spec/support/bin/@grubby new file mode 100755 index 0000000..2a9b33f --- /dev/null +++ b/spec/support/bin/@grubby @@ -0,0 +1,3 @@ +#!/bin/sh -e +. "$SHELLSPEC_SUPPORT_BIN" +invoke grubby "$@" diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf new file mode 100644 index 0000000..b821952 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf @@ -0,0 +1,8 @@ +title Fedora (0-rescue-e986846f63134c7295458cf36300ba5b) 33 (Workstation Edition) +version 0-rescue-e986846f63134c7295458cf36300ba5b +linux /boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b +initrd /boot/initramfs-0-rescue-e986846f63134c7295458cf36300ba5b.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class kernel diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf new file mode 100644 index 0000000..08bd411 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf @@ -0,0 +1,8 @@ +title Fedora (5.14.14-200.fc34.x86_64) 34 (Workstation Edition) +version 5.14.14-200.fc34.x86_64 +linux /boot/vmlinuz-5.14.14-200.fc34.x86_64 +initrd /boot/initramfs-5.14.14-200.fc34.x86_64.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class kernel diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf new file mode 100644 index 0000000..9259b99 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf @@ -0,0 +1,8 @@ +title Fedora (5.15.6-100.fc34.x86_64) 34 (Workstation Edition) +version 5.15.6-100.fc34.x86_64 +linux /boot/vmlinuz-5.15.6-100.fc34.x86_64 +initrd /boot/initramfs-5.15.6-100.fc34.x86_64.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class fedora diff --git a/spec/support/grub_env b/spec/support/grub_env new file mode 100644 index 0000000..a77303c --- /dev/null +++ b/spec/support/grub_env @@ -0,0 +1,3 @@ +# GRUB Environment Block +# WARNING: Do not edit this file by tools other than grub-editenv!!! +################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################## \ No newline at end of file