• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import logging
2from autotest_lib.client.common_lib import error
3from autotest_lib.client.virt import virt_utils
4
5
6def run_kdump(test, params, env):
7    """
8    KVM reboot test:
9    1) Log into a guest
10    2) Check and enable the kdump
11    3) For each vcpu, trigger a crash and check the vmcore
12
13    @param test: kvm test object
14    @param params: Dictionary with the test parameters
15    @param env: Dictionary with test environment.
16    """
17    vm = env.get_vm(params["main_vm"])
18    vm.verify_alive()
19    timeout = float(params.get("login_timeout", 240))
20    crash_timeout = float(params.get("crash_timeout", 360))
21    session = vm.wait_for_login(timeout=timeout)
22    def_kernel_param_cmd = ("grubby --update-kernel=`grubby --default-kernel`"
23                            " --args=crashkernel=128M")
24    kernel_param_cmd = params.get("kernel_param_cmd", def_kernel_param_cmd)
25    def_kdump_enable_cmd = "chkconfig kdump on && service kdump start"
26    kdump_enable_cmd = params.get("kdump_enable_cmd", def_kdump_enable_cmd)
27    def_crash_kernel_prob_cmd = "grep -q 1 /sys/kernel/kexec_crash_loaded"
28    crash_kernel_prob_cmd = params.get("crash_kernel_prob_cmd",
29                                       def_crash_kernel_prob_cmd)
30
31    def crash_test(vcpu):
32        """
33        Trigger a crash dump through sysrq-trigger
34
35        @param vcpu: vcpu which is used to trigger a crash
36        """
37        session = vm.wait_for_login(timeout=timeout)
38        session.cmd_output("rm -rf /var/crash/*")
39
40        logging.info("Triggering crash on vcpu %d ...", vcpu)
41        crash_cmd = "taskset -c %d echo c > /proc/sysrq-trigger" % vcpu
42        session.sendline(crash_cmd)
43
44        if not virt_utils.wait_for(lambda: not session.is_responsive(), 240, 0,
45                                  1):
46            raise error.TestFail("Could not trigger crash on vcpu %d" % vcpu)
47
48        logging.info("Waiting for kernel crash dump to complete")
49        session = vm.wait_for_login(timeout=crash_timeout)
50
51        logging.info("Probing vmcore file...")
52        session.cmd("ls -R /var/crash | grep vmcore")
53        logging.info("Found vmcore.")
54
55        session.cmd_output("rm -rf /var/crash/*")
56
57    try:
58        logging.info("Checking the existence of crash kernel...")
59        try:
60            session.cmd(crash_kernel_prob_cmd)
61        except:
62            logging.info("Crash kernel is not loaded. Trying to load it")
63            session.cmd(kernel_param_cmd)
64            session = vm.reboot(session, timeout=timeout)
65
66        logging.info("Enabling kdump service...")
67        # the initrd may be rebuilt here so we need to wait a little more
68        session.cmd(kdump_enable_cmd, timeout=120)
69
70        nvcpu = int(params.get("smp", 1))
71        for i in range (nvcpu):
72            crash_test(i)
73
74    finally:
75        session.close()
76