def _kdump_test()

in microsoft/testsuites/kdump/kdumpcrash.py [0:0]


    def _kdump_test(self, node: Node, log: Logger) -> None:
        try:
            self._check_supported(node)
        except UnsupportedDistroException as identifier:
            raise SkippedException(identifier)

        kdump = node.tools[KdumpBase]
        kdump.config_crashkernel_memory(self.crash_kernel)
        kdump.config_dump_path()
        kdump.enable_kdump_service()
        # Cleaning up any previous crash dump files
        node.execute(
            f"mkdir -p {kdump.dump_path} && rm -rf {kdump.dump_path}/*",
            shell=True,
            sudo=True,
        )

        # Reboot system to make kdump take effect
        node.reboot()

        # Confirm that the kernel dump mechanism is enabled
        kdump.check_crashkernel_loaded(self.crash_kernel)
        # Activate the magic SysRq option
        echo = node.tools[Echo]
        echo.write_to_file("1", node.get_pure_path("/proc/sys/kernel/sysrq"), sudo=True)
        node.execute("sync", shell=True, sudo=True)

        try:
            # Trigger kdump. After execute the trigger cmd, the VM will be disconnected
            # We set a timeout time 10.
            node.execute(
                self.trigger_kdump_cmd,
                shell=True,
                sudo=True,
                timeout=10,
            )
        except Exception as identifier:
            log.debug(f"ignorable ssh exception: {identifier}")

        # Wait for the VM dump file and boot up
        # When the crash kernel boots up, port 22 can be connected even if dump file
        # is not completed. So we cann't use wait_tcp_port_ready function to judge if
        # the dump process is completed and the VM already boots up. We can use
        # try_connect function
        timer = create_timer()
        remote_node = cast(RemoteNode, node)
        stdout = None
        while not stdout and timer.elapsed(False) < self.timeout_of_dump_crash:
            try:
                stdout = try_connect(remote_node._connection_info)
            except Exception as identifier:
                log.debug(
                    "failed to connect SSH "
                    f"{remote_node._connection_info.address}:"
                    f"{remote_node._connection_info.port}. "
                    f"{identifier.__class__.__name__}: {identifier}. Retry..."
                )
                time.sleep(10)
        if not stdout:
            raise LisaException("Timeout to connect the VM after triggering kdump.")

        # After trigger kdump, the VM will reboot. We need to close and re-initialize
        node.close()
        node.initialize()
        # Verify if the kernel kdump process creates a vmcore file of size 10M+
        kdump.check_vmcore_exist()