@@ -2308,6 +2308,63 @@ def runTest(self):
23082308 self .c .run_command (f"rm -rf /var/crash/{ latest_crashdir } ; sync" )
23092309
23102310
2311+ class OpTestKdumpKernelSwitch (OptestKernelDump ):
2312+ """
2313+ Testcase passes alternate kdump kernel and checks whether it has been loaded or not
2314+ """
2315+ def _get_installed_kernels_rhel (self ):
2316+ cmd = r"ls /boot/vmlinuz-* 2>/dev/null | sed 's#.*/vmlinuz-##' | grep -v '^0-rescue-'"
2317+ output = self .c .run_command (cmd )
2318+ kernels = []
2319+ for line in output :
2320+ line = line .strip ()
2321+ if line .startswith ("vmlinuz-" ):
2322+ line = line .replace ("vmlinuz-" , "" )
2323+ if line :
2324+ kernels .append (line )
2325+ return sorted (list (set (kernels )))
2326+
2327+ def runTest (self ):
2328+ running_kernel = self .c .run_command ("uname -r" )[0 ].strip ()
2329+ if self .distro == "sles" :
2330+ self .skipTest (
2331+ "skipping the testcase for now.. Need to figure out a way to verify kdump kernel version in sles" )
2332+ elif ("rhel" in self .distro or
2333+ "redhat" in self .distro ):
2334+ kernels = self ._get_installed_kernels_rhel ()
2335+ else :
2336+ self .skipTest ("Unsupported distro" )
2337+ log .info ("Installed kernels: %s" , kernels )
2338+ if len (kernels ) < 2 :
2339+ self .skipTest ("Need more than one installed kernel" )
2340+ # Pick alternate kernel
2341+ alternate_kernel = None
2342+ for kernel in kernels :
2343+ if kernel != running_kernel :
2344+ alternate_kernel = kernel
2345+ break
2346+ if not alternate_kernel :
2347+ self .skipTest ("No alternate kernel found" )
2348+ log .info ("Selected alternate kernel: %s" % alternate_kernel )
2349+ # configure alternale kernel
2350+ self .c .run_command ("cp /etc/sysconfig/kdump /etc/sysconfig/kdump_bck" )
2351+ self .cv_HOST .host_run_command (
2352+ f"sed -i 's/^KDUMP_KERNELVER=.*/KDUMP_KERNELVER=\" { alternate_kernel } \" /' /etc/sysconfig/kdump" )
2353+ self .cv_HOST .host_run_command ("systemctl restart kdump.service; sync;" )
2354+ self .kernel_crash ()
2355+ crash_dirs = self .c .run_command ("ls -1 /var/crash" )
2356+ crash_dirs = [d .strip () for d in crash_dirs if d .strip ()]
2357+ latest_crashdir = sorted (crash_dirs )[- 1 ]
2358+ log_path = f"/var/crash/{ latest_crashdir } /kexec-dmesg.log"
2359+ dmesg_log = "\n " .join (self .c .run_command (f"cat { log_path } " ))
2360+ self .c .run_command ("cp /etc/sysconfig/kdump_bck /etc/sysconfig/kdump" )
2361+ if alternate_kernel in dmesg_log :
2362+ log .info (
2363+ "alternale kernel: %s loaded successfully during crash" % alternate_kernel )
2364+ else :
2365+ self .fail ("fail to load alternate kdump kernel" )
2366+
2367+
23112368class OpTestWatchdog (OptestKernelDump ):
23122369 '''
23132370 This test verifies "watchdog module" with diffrent scenarios like
@@ -2817,6 +2874,7 @@ def crash_suite():
28172874 s .addTest (KernelCrash_KdumpPMEM ())
28182875 s .addTest (KernelCrash_KdumpMultiThreadCheck ())
28192876 s .addTest (OpTestMakedump ())
2877+ s .addTest (OpTestKdumpKernelSwitch ())
28202878 s .addTest (KernelCrash_FadumpEnable ())
28212879 s .addTest (KernelCrash_KdumpSMT ())
28222880 s .addTest (KernelCrash_KdumpSSH ())
0 commit comments