Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
spec/kdumpctl_manage_crashkernel_spec.sh | 100 +++++++++++++++++++++++
1 file changed, 100 insertions(+)
create mode 100644 spec/kdumpctl_manage_crashkernel_spec.sh
diff --git a/spec/kdumpctl_manage_crashkernel_spec.sh
b/spec/kdumpctl_manage_crashkernel_spec.sh
new file mode 100644
index 00000000..71a9e42d
--- /dev/null
+++ b/spec/kdumpctl_manage_crashkernel_spec.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+Describe 'Management of the kernel crashkernel parameter.'
+ Include ./kdumpctl
+ kernel1=/boot/vmlinuz-5.15.6-100.fc34.x86_64
+ kernel2=/boot/vmlinuz-5.14.14-200.fc34.x86_64
+ old_ck=1G-4G:162M,4G-64G:256M,64G-:512M
+ GRUB_CFG=/boot/grub2/grub.cfg
+ KDUMP_SPEC_TEST_RUN_DIR=$(mktemp -d /tmp/spec_test.XXXXXXXXXX)
+
+ uname() {
+ if [[ $1 == '-m' ]]; then
+ echo -n x86_64
+ elif [[ $1 == '-r' ]]; then
+ echo -n $current_kernel
+ fi
+ }
+
+ kdump_crashkernel=$(get_default_crashkernel kdump)
+
+ setup() {
+ mkdir -p "$KDUMP_SPEC_TEST_RUN_DIR"
+ cp -r spec/support/boot_load_entries "$KDUMP_SPEC_TEST_RUN_DIR"
+ cp spec/support/grub_env "$KDUMP_SPEC_TEST_RUN_DIR"/env_temp
+
+ grubby --args crashkernel=$old_ck --update-kernel=$kernel1
+ grubby --args crashkernel=$kdump_crashkernel --update-kernel=$kernel2
+ grubby --remove-args fadump --update-kernel=ALL
+
+ if [[ ! -e $GRUB_CFG ]]; then
+ touch $GRUB_CFG
+ fi
+ }
+
+ cleanup() {
+ rm -rf "$KDUMP_SPEC_TEST_RUN_DIR"
+ rm -f $GRUB_CFG
+ }
+
+ 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 "When kexec-tools have its default crashkernel updated, "
+
+ BeforeAll 'setup'
+ AfterAll 'cleanup'
+
+ Context "if kexec-tools is updated alone, "
+ Specify 'reset_crashkernel_after_update should report updated kernels and note
that auto_reset_crashkernel=yes'
+ When call reset_crashkernel_after_update
+ The output should include "For kernel=$kernel1, crashkernel=$kdump_crashkernel
now."
+ The output should not include "For kernel=$kernel2,
crashkernel=$kdump_crashkernel now."
+ The output should include "auto_reset_crashkernel=no"
+ End
+
+ Specify 'kernel1 should have crashkernel updated'
+ When call grubby --info $kernel1
+ The line 3 of output should include crashkernel="$kdump_crashkernel"
+ End
+
+ Specify 'kernel2 should also have crashkernel updated'
+ When call grubby --info $kernel2
+ The line 3 of output should include crashkernel="$kdump_crashkernel"
+ End
+
+ End
+
+ Context "If kernel package is installed alone, "
+ # BeforeAll somehow doesn't work as expected, manually call setup to bypass this
issue.
+ setup
+ new_kernel_ver=new_kernel
+ new_kernel=/boot/vmlinuz-$new_kernel_ver
+ grubby --add-kernel=$new_kernel --initrd=/boot/initramfs-$new_kernel_ver.img
--title=$new_kernel_ver
+
+ Specify 'reset_crashkernel_for_installed_kernel should report the new kernel has
its crashkernel updated'
+ When call reset_crashkernel_for_installed_kernel $new_kernel_ver
+ The output should include "crashkernel=$kdump_crashkernel"
+ End
+
+ Specify 'the new kernel should have crashkernel updated'
+ When call grubby --info $new_kernel
+ The output should include crashkernel="$kdump_crashkernel"
+ End
+
+ Specify 'kernel1 keeps its crashkernel value'
+ When call grubby --info $kernel1
+ The output should include crashkernel="$old_ck"
+ End
+
+ End
+
+ End
+End
--
2.40.1