Redirct and make use of the guest serial console
v2 cover Redirct and make use of the guest serial console
The guest console is useful for failure troubleshooting especially for the one who has calltrace. And as we plan to push the network related test in the next few weeks, we found the serial session in more reliable during the network testing. So this patchset logs the guest serial throught the redirectied serial of guest and also enable the ability to log into guest through serial console. I only open the serial console for linux, I would do some investigation on windows guests.
Change from v1:
- Coding style improvement according to the suggestions from Michael Goldish
- Improve the username sending handling in remote_login()
- Change the matching re of login to [Ll]ogin:\s*$
- Check whether vm have already dead in dumpping thread
- Return none rather than raise exception when met unknown shell_client
- Keep tty0 for all linux guests
- Enable the serial console in unattended installation
- Add a helper to check whether the panic information was occured
- Keep the porcess() at its original location in preprocess()
---
Jason Wang (10):
KVM test: Introduce prompt assist
KVM test: Send the username in remote_login()
KVM test: Make the login re suitable for serial console KVM test: Redirect the serial to the unix domain socket KVM test: Log the content from guest serial console
KVM test: Return none when met unknown type in kvm_vm.remote_login(). KVM test: Introduce local_login()
KVM test: Enable the serial console for all linux guests KVM test: Enable the serial console during unattended installation KVM test: Add a helper to search the panic in the log
client/tests/kvm/kvm_preprocessing.py | 59 ++++++++++++++++++++++++++ client/tests/kvm/kvm_utils.py | 32 ++++++++++---- client/tests/kvm/kvm_vm.py | 49 ++++++++++++++++++---- client/tests/kvm/scripts/check_serial.py | 41 ++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 16 ++++--- client/tests/kvm/unattended/Fedora-10.ks | 2 - client/tests/kvm/unattended/Fedora-11.ks | 2 - client/tests/kvm/unattended/Fedora-12.ks | 2 - client/tests/kvm/unattended/Fedora-8.ks | 2 - client/tests/kvm/unattended/Fedora-9.ks | 2 - client/tests/kvm/unattended/OpenSUSE-11.xml | 1 client/tests/kvm/unattended/RHEL-3-series.ks | 2 - client/tests/kvm/unattended/RHEL-4-series.ks | 2 - client/tests/kvm/unattended/RHEL-5-series.ks | 2 - client/tests/kvm/unattended/SLES-11.xml | 1 15 files changed, 183 insertions(+), 32 deletions(-) create mode 100644 client/tests/kvm/scripts/check_serial.py
Signature · 1 line
Signature
PATCH v2 1/10 KVM test: Introduce prompt assist
We need to send an assist string to a session in order to get the prompt when re-connecting to session through serial. This patch sends assist string before matching the prompt in remote_login().
--- client/tests/kvm/kvm_utils.py | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_utils.py +7 -2
@@ -451,7 +451,8 @@ def check_kvm_source_dir(source_dir): # The following are functions used for SSH, SCP and Telnet communication with # guests. -def remote_login(command, password, prompt, linesep="\n", timeout=10): +def remote_login(command, password, prompt, linesep="\n", timeout=10, + prompt_assist=None): """ Log into a remote host (guest) using SSH or Telnet. Run the given command using kvm_spawn and provide answers to the questions asked. If timeout
@@ -468,7 +469,8 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): @param timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt, the password prompt, the shell prompt, etc) - + @param prompt_assist: An assistant string sent before the pattern + matching in order to get the prompt for some kinds of shell_client. @return Return the kvm_spawn object on success and None on failure. """ sub = kvm_subprocess.kvm_shell_session(command,
@@ -479,6 +481,9 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): logging.debug("Trying to login with command '%s'" % command) + if prompt_assist is not None: + sub.sendline(prompt_assist) + while True: (match, text) = sub.read_until_last_line_matches( [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"^\s*[Ll]ogin:\s*$",
Re: [PATCH v2 01/10] KVM test: Introduce prompt assist
Hi Jason, just hold on cause next week I'm back and will finish work on your patchset.
Cheers,
Quoted 49 lines · Jason Wang
We need to send an assist string to a session in order to get the prompt when re-connecting to session through serial. This patch sends assist string before matching the prompt in
remote_login().Signed-off-by Jason Wang <[email protected]>---
client/tests/kvm/kvm_utils.py | 9 +++++++--1 files changed, 7 insertions(+), 2 deletions(-)client/tests/kvm/kvm_utils.py +2
-1@@ -451,7 +451,8 @@ def check_kvm_source_dir(source_dir): # The following are functions used for SSH, SCP and Telnet communication with # guests. -def remote_login(command, password, prompt, linesep="\n", timeout=10): +def remote_login(command, password, prompt, linesep="\n", timeout=10, + prompt_assist=None):"""
Log into a remote host (guest) using SSH or Telnet. Run the given command usingkvm_spawnand provide answers to the questions asked. If timeoutclient/tests/kvm/kvm_utils.py +0
-0@@ -468,7 +469,8 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10):@param timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt, the password prompt, the shell prompt, etc)
-
+ @paramprompt_assist: An assistant string sent before the pattern
+ matching in order to get the prompt for some kinds ofshell_client. @return Return thekvm_spawnobject on success and None on failure. """
sub = kvm_subprocess.kvm_shell_session(command,client/tests/kvm/kvm_utils.py +3
-0@@ -479,6 +481,9 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): logging.debug("Trying to login with command '%s'" % command) + if prompt_assist is not None: + sub.sendline(prompt_assist) +while True:
(match, text) = sub.read_until_last_line_matches( [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"^\s*[Ll]ogin:\s*$",_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
Signature · 1 line
Lucas
PATCH v2 2/10 KVM test: Send the username in remote_login()
In reply to Jason WangIn order to let the serial console work, we must let the remote_login() send the username when met the username prompt. This patch fails the progress if if it met the username prompt twice.
--- client/tests/kvm/kvm_utils.py | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-)
client/tests/kvm/kvm_utils.py +16 -7
@@ -451,7 +451,7 @@ def check_kvm_source_dir(source_dir): # The following are functions used for SSH, SCP and Telnet communication with # guests. -def remote_login(command, password, prompt, linesep="\n", timeout=10, +def remote_login(command, username, password, prompt, linesep="\n", timeout=10, prompt_assist=None): """ Log into a remote host (guest) using SSH or Telnet. Run the given command
@@ -462,6 +462,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, @brief: Log into a remote host (guest) using SSH or Telnet. @param command: The command to execute (e.g. "ssh root@localhost") + @param username: The username to send in reply to a username prompt @param password: The password to send in reply to a password prompt @param prompt: The shell prompt that indicates a successful login @param linesep: The line separator to send instead of "\\n"
@@ -471,6 +472,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, password prompt, the shell prompt, etc) @param prompt_assist: An assistant string sent before the pattern matching in order to get the prompt for some kinds of shell_client. + @return Return the kvm_spawn object on success and None on failure. """ sub = kvm_subprocess.kvm_shell_session(command,
@@ -478,6 +480,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, prompt=prompt) password_prompt_count = 0 + login_prompt_count = 0 logging.debug("Trying to login with command '%s'" % command)
@@ -505,9 +508,15 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, sub.close() return None elif match == 2: # "login:" - logging.debug("Got unexpected login prompt") - sub.close() - return None + if login_prompt_count == 0: + logging.debug("Got username prompt; sending '%s'" % username) + sub.sendline(username) + login_prompt_count += 1 + continue + else: + logging.debug("Got username prompt again") + sub.close() + return None elif match == 3: # "Connection closed" logging.debug("Got 'Connection closed'") sub.close()
@@ -644,7 +653,7 @@ def ssh(host, port, username, password, prompt, linesep="\n", timeout=10): command = ("ssh -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -p %s %s@%s" % (port, username, host)) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) def telnet(host, port, username, password, prompt, linesep="\n", timeout=10):
@@ -661,7 +670,7 @@ def telnet(host, port, username, password, prompt, linesep="\n", timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "telnet -l %s %s %s" % (username, host, port) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) def netcat(host, port, username, password, prompt, linesep="\n", timeout=10):
@@ -678,7 +687,7 @@ def netcat(host, port, username, password, prompt, linesep="\n", timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "nc %s %s" % (host, port) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) # The following are utility functions related to ports.
PATCH v2 3/10 KVM test: Make the login re suitable for serial console
In reply to Jason WangCurrent matching re ^\s*[Ll]ogin:\s*$ is not suitable for the serial console, so change it to [Ll]ogin:\s*$.
--- client/tests/kvm/kvm_utils.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_utils.py +1 -1
@@ -489,7 +489,7 @@ def remote_login(command, username, password, prompt, linesep="\n", timeout=10, while True: (match, text) = sub.read_until_last_line_matches( - [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"^\s*[Ll]ogin:\s*$", + [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"[Ll]ogin:\s*$", r"[Cc]onnection.*closed", r"[Cc]onnection.*refused", r"[Pp]lease wait", prompt], timeout=timeout, internal_timeout=0.5)
PATCH v2 4/10 KVM test: Redirect the serial to the unix domain socket
In reply to Jason WangThis patch redirect the guest serial to the unix domain socket which would be used by the following patches to dump its content or use it as a session.
--- client/tests/kvm/kvm_vm.py | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
client/tests/kvm/kvm_vm.py +12 -7
@@ -116,17 +116,20 @@ class VM: self.address_cache = address_cache self.pci_assignable = None - # Find available monitor filename + # Find available filenames for monitor and guest serial redirection while True: - # The monitor filename should be unique + # The filenames should be unique self.instance = (time.strftime("%Y%m%d-%H%M%S-") + kvm_utils.generate_random_string(4)) - self.monitor_file_name = os.path.join("/tmp", - "monitor-" + self.instance) - if not os.path.exists(self.monitor_file_name): - break - + names = [os.path.join("/tmp", type + self.instance) for type in + "monitor-", "serial-"] + if True in [os.path.exists(file) for file in names]: + continue + else: + [self.monitor_file_name, self.serial_file_name] = names + break + def clone(self, name=None, params=None, root_dir=None, address_cache=None): """ Return a clone of the VM object with optionally modified parameters.
@@ -316,6 +319,8 @@ class VM: for pci_id in self.pa_pci_ids: qemu_cmd += " -pcidevice host=%s" % pci_id + qemu_cmd += " -serial unix:%s,server,nowait" % self.serial_file_name + return qemu_cmd
PATCH v2 5/10 KVM test: Log the content from guest serial console
In reply to Jason WangThis patch tries to get the content of guest serial and log it into the debug directoy of the testcase through a dedicated thread which is created in the preprocessing and ended in the postprocessing. The params of serial_mode must be set to "dump" in order to make use of this feature.
--- client/tests/kvm/kvm_preprocessing.py | 59 +++++++++++++++++++++++++++++++- client/tests/kvm/tests_base.cfg.sample | 1 + 2 files changed, 59 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_preprocessing.py +58 -1
@@ -1,4 +1,5 @@ import sys, os, time, commands, re, logging, signal, glob, threading, shutil +import socket, select from autotest_lib.client.bin import test, utils from autotest_lib.client.common_lib import error import kvm_vm, kvm_utils, kvm_subprocess, ppm_utils
@@ -13,7 +14,8 @@ except ImportError: _screendump_thread = None _screendump_thread_termination_event = None - +_serialdump_thread = None +_serialdump_thread_termination_event = None def preprocess_image(test, params): """
@@ -267,6 +269,16 @@ def preprocess(test, params, env): args=(test, params, env)) _screendump_thread.start() + # Start the serial dump thread + if params.get("serial_mode") == "dump": + logging.debug("Starting serialdump thread") + global _serialdump_thread, _serialdump_thread_termination_event + _serialdump_thread_termination_event = threading.Event() + _serialdump_thread = threading.Thread(target=_dump_serial_console, + args=(test, params, env)) + _serialdump_thread.start() + + def postprocess(test, params, env): """
@@ -286,6 +298,13 @@ def postprocess(test, params, env): _screendump_thread_termination_event.set() _screendump_thread.join(10) + # Terminate the serialdump thread + global _serialdump_thread, _serialdump_thread_termination_event + if _serialdump_thread: + logging.debug("Terminating serialdump thread...") + _serialdump_thread_termination_event.set() + _serialdump_thread.join(10) + # Warn about corrupt PPM files for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): if not ppm_utils.image_verify_ppm_file(f):
@@ -450,3 +469,41 @@ def _take_screendumps(test, params, env): if _screendump_thread_termination_event.isSet(): break _screendump_thread_termination_event.wait(delay) + +def _dump_serial_console(test, params, env): + global _serialdump_thread_termination_event + rs = [] + files = {} + + while True: + for vm in kvm_utils.env_get_all_vms(env): + if not vm in files and not vm.is_dead(): + try: + serial_socket = socket.socket(socket.AF_UNIX, + socket.SOCK_STREAM) + serial_socket.setblocking(False) + serial_socket.connect(vm.serial_file_name) + except: + logging.debug("Could not connect to serial socket for %s" % + vm.name) + continue + rs.append(serial_socket) + serial_dump_filename = os.path.join(test.debugdir, + "serial-%s" % vm.name) + files[vm] = [serial_socket, file(serial_dump_filename, "a+")] + + r, w, x = select.select(rs, [], [], 0.5) + for vm in files.keys(): + (s ,d) = files[vm] + if s in r: + data = s.recv(16384) + if not data: + rs.remove(s) + files.pop(vm) + else: + d.write(data) + + if _serialdump_thread_termination_event.isSet(): + break + +
client/tests/kvm/tests_base.cfg.sample +1 -0
@@ -13,6 +13,7 @@ start_vm = yes kill_vm = no kill_vm_gracefully = yes kill_unresponsive_vms = yes +serial_mode = dump # Screendump specific stuff convert_ppm_files_to_png_on_error = yes
PATCH v2 6/10 KVM test: Return none when met unknown type in kvm_vm.remote_login().
In reply to Jason WangNone is returned when met the unknown type of shell_client in kvm_vm.remote_login() in order to avoid the traceback.
--- client/tests/kvm/kvm_vm.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_vm.py +4 -1
@@ -806,7 +806,10 @@ class VM: elif client == "nc": session = kvm_utils.netcat(address, port, username, password, prompt, linesep, timeout) - + else: + logging.error("Unknown shell_client type %s" % client) + return None + if session: session.set_status_test_command(self.params.get("status_test_" "command", ""))
PATCH v2 7/10 KVM test: Introduce local_login()
In reply to Jason WangThis patch introduces a new method which is used to log into the guest through the guest serial console. The serial_mode must be set to "session" in order to make use of this patch. Serial does not support cocurrent sessions, so it doest not aim at replacing the regular remote shell servers. But it would be useful for the network related test which may cause the network unresponsive such as driver load/unload or some kinds of network stress testing.
--- client/tests/kvm/kvm_vm.py | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +25 -0
@@ -815,7 +815,32 @@ class VM: "command", "")) return session + def local_login(self, timeout=240): + """ + Log into the guest via serial console + If timeout expires while waiting for output from the guest (e.g. a + password prompt or a shell prompt) -- fail. + """ + + serial_mode = self.params.get("serial_mode") + username = self.params.get("username", "") + password = self.params.get("password", "") + prompt = self.params.get("shell_prompt", "[\#\$]") + linesep = eval("'%s'" % self.params.get("shell_linesep", r"\n")) + if serial_mode != "session": + logging.debug("serial_mode is not session") + return None + else: + command = "nc -U %s" % self.serial_file_name + assist = self.params.get("prompt_assist", "") + session = kvm_utils.remote_login(command, username, password, prompt, + linesep, timeout, assist) + if session: + session.set_status_test_command(self.params.get("status_test_" + "command", "")) + return session + def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=300): """ Transfer files to the guest.
PATCH v2 8/10 KVM test: Enable the serial console for all linux guests
In reply to Jason WangAs we have the ability to dump the content from serial console or use a session through it, we need to redirect the console to serial through unattended files to make use of it. The patch also keep the tty0 accroding to the suggestion of Michael Goldish.
--- client/tests/kvm/unattended/Fedora-10.ks | 2 +- client/tests/kvm/unattended/Fedora-11.ks | 2 +- client/tests/kvm/unattended/Fedora-12.ks | 2 +- client/tests/kvm/unattended/Fedora-8.ks | 2 +- client/tests/kvm/unattended/Fedora-9.ks | 2 +- client/tests/kvm/unattended/OpenSUSE-11.xml | 1 + client/tests/kvm/unattended/RHEL-3-series.ks | 2 +- client/tests/kvm/unattended/RHEL-4-series.ks | 2 +- client/tests/kvm/unattended/RHEL-5-series.ks | 2 +- client/tests/kvm/unattended/SLES-11.xml | 1 + 10 files changed, 10 insertions(+), 8 deletions(-)
client/tests/kvm/unattended/Fedora-10.ks +1 -1
@@ -11,7 +11,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel autopart
client/tests/kvm/unattended/Fedora-11.ks +1 -1
@@ -10,7 +10,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel
client/tests/kvm/unattended/Fedora-12.ks +1 -1
@@ -10,7 +10,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel
client/tests/kvm/unattended/Fedora-8.ks +1 -1
@@ -11,7 +11,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel autopart
client/tests/kvm/unattended/Fedora-9.ks +1 -1
@@ -11,7 +11,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel autopart
client/tests/kvm/unattended/OpenSUSE-11.xml +1 -0
@@ -50,6 +50,7 @@ <module>edd</module> </initrd_module> </initrd_modules> + <append>console=ttyS0,115200 console=tty0</append> <loader_type>grub</loader_type> <sections config:type="list"/> </bootloader>
client/tests/kvm/unattended/RHEL-3-series.ks +1 -1
@@ -10,7 +10,7 @@ rootpw 123456 firewall --enabled --ssh timezone America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" clearpart --all --initlabel autopart reboot
client/tests/kvm/unattended/RHEL-4-series.ks +1 -1
@@ -11,7 +11,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel autopart
client/tests/kvm/unattended/RHEL-5-series.ks +1 -1
@@ -11,7 +11,7 @@ firewall --enabled --ssh selinux --enforcing timezone --utc America/New_York firstboot --disable -bootloader --location=mbr +bootloader --location=mbr --append="console=ttyS0,115200 console=tty0" zerombr clearpart --all --initlabel autopart
client/tests/kvm/unattended/SLES-11.xml +1 -0
@@ -49,6 +49,7 @@ <module>edd</module> </initrd_module> </initrd_modules> + <append>console=ttyS0,115200 console=tty0</append> <loader_type>grub</loader_type> <sections config:type="list"/> </bootloader>
PATCH v2 9/10 KVM test: Enable the serial console during unattended installation
In reply to Jason WangThis patch enable the serial console during unattended installation for all linux guests.
--- client/tests/kvm/tests_base.cfg.sample | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
client/tests/kvm/tests_base.cfg.sample +4 -4
@@ -452,7 +452,7 @@ variants: pxe_initrd = "initrd.img" tftp = "images/tftpboot" extra_params += " -bootp /pxelinux.0 -boot cn" - kernel_args = "ks=floppy nicdelay=60" + kernel_args = "ks=floppy nicdelay=60 console=ttyS0,115200 console=tty0" variants: - 8.32:
@@ -592,7 +592,7 @@ variants: pxe_initrd = "initrd" tftp = "images/tftpboot" extra_params += " -bootp /pxelinux.0 -boot cn" - kernel_args = "autoyast=floppy" + kernel_args = "autoyast=floppy console=ttyS0,115200 console=tty0" post_install_delay = 10 variants:
@@ -674,7 +674,7 @@ variants: pxe_image = "linux" pxe_initrd = "initrd" extra_params += " -bootp /pxelinux.0 -boot n" - kernel_args = "autoyast=floppy" + kernel_args = "autoyast=floppy console=ttyS0,115200 console=tty0" post_install_delay = 10 variants:
@@ -733,7 +733,7 @@ variants: pxe_initrd = "initrd.img" tftp = "images/tftpboot" extra_params += " -bootp /pxelinux.0 -boot cn" - kernel_args = "ks=floppy nicdelay=60" + kernel_args = "ks=floppy nicdelay=60 console=ttyS0,115200 console=tty0" variants: - 3.9.i386:
PATCH v2 10/10 KVM test: Add a helper to search the panic in the log
In reply to Jason WangThis checker serves as the post_command to find the panic information in the file which contains the content of guest serial console.
--- client/tests/kvm/scripts/check_serial.py | 41 ++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 client/tests/kvm/scripts/check_serial.py
client/tests/kvm/scripts/check_serial.py new file +41 -0
@@ -0,0 +1,41 @@ +import os, sys, glob, re + + +class SerialCheckerError(Exception): + """ + Simple wrapper for the builtin Exception class. + """ + pass + + +class SerialChecker(object): + """ + Serach the panic or other keywords in the guest serial. + """ + def __init__(self): + """ + Gets params from environment variables and sets class attributes. + """ + client_dir = os.environ['AUTODIR'] + self.pattern = os.environ['KVM_TEST_search_pattern'] + self.shortname = os.environ['KVM_TEST_shortname'] + self.debugdir = os.path.join(client_dir, "results/default/kvm.%s/debug" \ + % self.shortname) + self.serial_files = glob.glob(os.path.join(self.debugdir, 'serial*')) + + + def check(self): + """ + Check whether the pattern were found in the serial files + """ + fail = [ f for f in self.serial_files if + re.findall(self.pattern, file(f).read(), re.I) ] + if fail: + print "%s is found in %s" % (self.pattern, fail) + raise SerialCheckerError("Error found during the check, Please" \ + " check the log") + + +if __name__ == "__main__": + checker = SerialChecker() + checker.check()
client/tests/kvm/tests_base.cfg.sample +5 -2
@@ -52,6 +52,10 @@ address_index = 0 # Misc profilers = kvm_stat +# pattern serach in guest serial console +serach_pattern = panic +post_command = "python scripts/check_serial.py" +post_command_noncritical = no # Tests variants:
@@ -1314,10 +1318,9 @@ virtio|virtio_blk|e1000|balloon_check: variants: - @qcow2: image_format = qcow2 - post_command = " python scripts/check_image.py;" + post_command = " python scripts/check_image.py; python scripts/check_serial.py" remove_image = no post_command_timeout = 600 - post_command_noncritical = yes - vmdk: only Fedora Ubuntu Windows only smp2
Re: [PATCH v2 10/10] KVM test: Add a helper to search the panic in the log
Quoted 28 lines · Jason Wang
This checker serves as the
post_commandto find the panic information in the file which contains the content of guest serial console.Signed-off-by Jason Wang <[email protected]>--- client/tests/kvm/scripts/check_serial.py | 41 ++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 client/tests/kvm/scripts/check_serial.pyclient/tests/kvm/scripts/check_serial.py new file +12
-0@@ -0,0 +1,41 @@ +import os, sys, glob, re + + +class SerialCheckerError(Exception): + """ + Simple wrapper for the builtin Exception class. + """ + pass + + +class SerialChecker(object): + """
client/tests/kvm/scripts/check_serial.py line 22
Quoted 10 lines
client/tests/kvm/scripts/check_serial.py new file +10
-0+ Serach the panic or other keywords in the guest serial. + """ + def __init__(self): + """ + Gets params from environment variables and sets class attributes. + """ + client_dir = os.environ['AUTODIR'] + self.pattern = os.environ['KVM_TEST_search_pattern'] + self.shortname = os.environ['KVM_TEST_shortname'] + self.debugdir = os.path.join(client_dir, "results/default/kvm.%s/debug" \
I think the final backslash is unnecessary.
client/tests/kvm/scripts/check_serial.py line 35
Quoted 13 lines
client/tests/kvm/scripts/check_serial.py new file +13
-0+ % self.shortname) + self.serial_files = glob.glob(os.path.join(self.debugdir, 'serial*')) + + + def check(self): + """ + Check whether the pattern were found in the serial files + """ + fail = [ f for f in self.serial_files if + re.findall(self.pattern, file(f).read(), re.I) ] + if fail: + print "%s is found in %s" % (self.pattern, fail) + raise SerialCheckerError("Error found during the check, Please" \
Same here.
client/tests/kvm/scripts/check_serial.py line 41
Quoted 6 lines
client/tests/kvm/scripts/check_serial.py new file +6
-0+ " check the log") + + +if __name__ == "__main__": + checker = SerialChecker() + checker.check()
I wonder why we need a class. Why not just put all the code here?
Quoted 16 lines
client/tests/kvm/tests_base.cfg.sample +4
-0@@ -52,6 +52,10 @@ address_index = 0 # Misc profilers = kvm_stat +# pattern serach in guest serial console +serach_pattern = panic +post_command = "python scripts/check_serial.py" +post_command_noncritical = no # Tests variants:
client/tests/kvm/tests_base.cfg.sample virtio|virtio_blk|e1000|balloon_check: · line 1321
Quoted 5 lines
client/tests/kvm/tests_base.cfg.sample +1
-1@@ -1314,10 +1318,9 @@ virtio|virtio_blk|e1000|balloon_check: variants: - @qcow2: image_format = qcow2 - post_command = " python scripts/check_image.py;" + post_command = " python scripts/check_image.py; python scripts/check_serial.py"
^
This should be +=, because post_command may have been previously assigned some value.
Quoted 11 lines
client/tests/kvm/tests_base.cfg.sample +0
-2remove_image = no post_command_timeout = 600 - post_command_noncritical = yes - vmdk: only Fedora Ubuntu Windows only smp2 --To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 10/10] KVM test: Add a helper to search the panic in the log
Quoted 63 lines · Michael Goldish
Quoted 29 lines · Jason Wang
This checker serves as the
post_commandto find the panic information in the file which contains the content of guest serial console.Signed-off-by Jason Wang <[email protected]>--- client/tests/kvm/scripts/check_serial.py | 41 ++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 client/tests/kvm/scripts/check_serial.pyclient/tests/kvm/scripts/check_serial.py new file +12
-0@@ -0,0 +1,41 @@ +import os, sys, glob, re + + +class SerialCheckerError(Exception): + """ + Simple wrapper for the builtin Exception class. + """ + pass + + +class SerialChecker(object): + """client/tests/kvm/scripts/check_serial.py line 22
Quoted 10 lines
client/tests/kvm/scripts/check_serial.py new file +10
-0+ Serach the panic or other keywords in the guest serial. + """ + def __init__(self): + """ + Gets params from environment variables and sets class attributes. + """ + client_dir = os.environ['AUTODIR'] + self.pattern = os.environ['KVM_TEST_search_pattern'] + self.shortname = os.environ['KVM_TEST_shortname'] + self.debugdir = os.path.join(client_dir, "results/default/kvm.%s/debug" \I think the final backslash is unnecessary.
Quoted 4 lines
client/tests/kvm/scripts/check_serial.py new file +3
-0+ % self.shortname) + self.serial_files = glob.glob(os.path.join(self.debugdir, 'serial*')) +client/tests/kvm/scripts/check_serial.py line 35
Quoted 10 lines
client/tests/kvm/scripts/check_serial.py new file +10
-0+ + def check(self): + """ + Check whether the pattern were found in the serial files + """ + fail = [ f for f in self.serial_files if + re.findall(self.pattern, file(f).read(), re.I) ] + if fail: + print "%s is found in %s" % (self.pattern, fail) + raise SerialCheckerError("Error found during the check, Please" \Same here.
Quoted 11 lines
client/tests/kvm/scripts/check_serial.py line 41
Quoted 7 lines
client/tests/kvm/scripts/check_serial.py new file +6
-0+ " check the log") + + +if __name__ == "__main__": + checker = SerialChecker() + checker.check()I wonder why we need a class. Why not just put all the code here?
Just follow the style of other pre_command, maybe Lucas like it.
Quoted 23 lines
Quoted 16 lines
client/tests/kvm/tests_base.cfg.sample +4
-0@@ -52,6 +52,10 @@ address_index = 0 # Misc profilers = kvm_stat +# pattern serach in guest serial console +serach_pattern = panic +post_command = "python scripts/check_serial.py" +post_command_noncritical = no # Tests variants:client/tests/kvm/tests_base.cfg.sample virtio|virtio_blk|e1000|balloon_check: · line 1322
Quoted 6 lines
client/tests/kvm/tests_base.cfg.sample +1
-1@@ -1314,10 +1318,9 @@ virtio|virtio_blk|e1000|balloon_check: variants: - @qcow2: image_format = qcow2 - post_command = " python scripts/check_image.py;" + post_command = " python scripts/check_image.py; python scripts/check_serial.py"^
Quoted 4 lines
This should be +=, because
post_commandmay have been previously assigned some value.
Would change it, and do you have any other comments about this patchset?
Quoted 18 lines
Quoted 7 lines
client/tests/kvm/tests_base.cfg.sample +0
-1remove_image = no post_command_timeout = 600 - post_command_noncritical = yes - vmdk: only Fedora Ubuntu Windowsonly smp2
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 10/10] KVM test: Add a helper to search the panic in the log
Quoted 24 lines · Jason Wang
Quoted 23 lines · Michael Goldish
Quoted 21 lines · Jason Wang
This checker serves as the
post_commandto find the panic information in the file which contains the content of guest serial console.Signed-off-by Jason Wang <[email protected]>--- client/tests/kvm/scripts/check_serial.py | 41 ++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++++- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 client/tests/kvm/scripts/check_serial.pyclient/tests/kvm/scripts/check_serial.py new file +5
-0@@ -0,0 +1,41 @@ +import os, sys, glob, re + + +class SerialCheckerError(Exception): + """
Quoted 8 lines
Quoted 8 lines
client/tests/kvm/scripts/check_serial.py line 13
Quoted 8 lines
client/tests/kvm/scripts/check_serial.py new file +8
-0+ Simple wrapper for the builtin Exception class. + """ + pass + + +class SerialChecker(object): + """ + Serach the panic or other keywords in the guest serial.
^ Typo here, search.
Quoted 43 lines
Quoted 32 lines
client/tests/kvm/scripts/check_serial.py line 22
Quoted 10 lines
client/tests/kvm/scripts/check_serial.py new file +9
-0+ """ + def __init__(self): + """ + Gets params from environment variables and sets class attributes. + """ + client_dir = os.environ['AUTODIR'] + self.pattern = os.environ['KVM_TEST_search_pattern'] + self.shortname = os.environ['KVM_TEST_shortname'] + self.debugdir = os.path.join(client_dir, "results/default/kvm.%s/debug" \I think the final backslash is unnecessary.
Quoted 4 lines
client/tests/kvm/scripts/check_serial.py new file +3
-0+ % self.shortname) + self.serial_files = glob.glob(os.path.join(self.debugdir, 'serial*')) +client/tests/kvm/scripts/check_serial.py line 35
Quoted 10 lines
client/tests/kvm/scripts/check_serial.py new file +10
-0+ + def check(self): + """ + Check whether the pattern were found in the serial files + """ + fail = [ f for f in self.serial_files if + re.findall(self.pattern, file(f).read(), re.I) ] + if fail: + print "%s is found in %s" % (self.pattern, fail) + raise SerialCheckerError("Error found during the check, Please" \Same here.
Quoted 11 lines
client/tests/kvm/scripts/check_serial.py line 41
Quoted 7 lines
client/tests/kvm/scripts/check_serial.py new file +6
-0+ " check the log") + + +if __name__ == "__main__": + checker = SerialChecker() + checker.check()I wonder why we need a class. Why not just put all the code here?
Quoted 1 line
Just follow the style of other
pre_command, maybe Lucas like it.
When I made the first pre command script, I opted to use a class to represent the unattended install setup, and other pre commands followed this style. Since the code is small, I see no problem in putting it under __main__ altogether. So Jason, you can remove the code from the class and put it under __main__, please.
Quoted 10 lines
Quoted 10 lines
client/tests/kvm/tests_base.cfg.sample address_index = 0 · line 56
Quoted 10 lines
client/tests/kvm/tests_base.cfg.sample +2
-0@@ -52,6 +52,10 @@ address_index = 0 # Misc profilers = kvm_stat +# pattern serach in guest serial console +serach_pattern = panic
^ typo, should be search_pattern
Quoted 17 lines
Quoted 13 lines
client/tests/kvm/tests_base.cfg.sample virtio|virtio_blk|e1000|balloon_check: · line 1322
Quoted 12 lines
client/tests/kvm/tests_base.cfg.sample +3
-1+post_command = "python scripts/check_serial.py" +post_command_noncritical = no # Tests variants:@@ -1314,10 +1318,9 @@ virtio|virtio_blk|e1000|balloon_check: variants: - @qcow2: image_format = qcow2 - post_command = " python scripts/check_image.py;" + post_command = " python scripts/check_image.py; python scripts/check_serial.py"^Quoted 4 lines
This should be +=, because
post_commandmay have been previously assigned some value.
Quoted 1 line
Would change it, and do you have any other comments about this patchset?
Other than the issues pointed out, looks good.
Quoted 11 lines · Jason Wang
The guest console is useful for failure troubleshooting especially for the one who has calltrace. And as we plan to push the network related test in the next few weeks, we found the serial session in more reliable during the network testing. So this patchset logs the guest serial throught the redirectied serial of guest and also enable the ability to log into guest through serial console. I only open the serial console for linux, I would do some investigation on windows guests.
Change from v1:
Quoted 9 lines
- Coding style improvement according to the suggestions from Michael Goldish
- Improve the username sending handling inremote_login()
- Change the matching re of login to [Ll]ogin:\s*$
- Check whether vm have already dead in dumpping thread
- Return none rather than raise exception when met unknownshell_client
- Keep tty0 for all linux guests
- Enable the serial console in unattended installation
- Add a helper to check whether the panic information was occured
- Keep theporcess()at its original location inpreprocess()
Jason, after a long conversation I've had with Michael during the previous week, we reached some common points:
1 - We believe it is possible to be able to both log in *and* log serial console output. That will require changes to kvm_subprocess and might take a little bit more time.
2 - We know you guys are depending on this patchset to be accepted in order to proceed with the network related cases. However, we ask for a little more patience, and we'd like to get your opinions on the patches that we are going to roll out. This way we can get to a better solution for all of us.
So, please bear with us and I'll try to see with Michael and Dor if we can prioritize this work to not block work items for you guys.
Cheers,
Lucas
Quoted 24 lines · Lucas Meneghel Rodrigues
Quoted 11 lines · Jason Wang
The guest console is useful for failure troubleshooting especially for the one who has calltrace. And as we plan to push the network related test in the next few weeks, we found the serial session in more reliable during the network testing. So this patchset logs the guest serial throught the redirectied serial of guest and also enable the ability to log into guest through serial console. I only open the serial console for linux, I would do some investigation on windows guests.
Change from v1:
Quoted 10 lines
- Coding style improvement according to the suggestions from Michael Goldish
- Improve the username sending handling inremote_login()
- Change the matching re of login to [Ll]ogin:\s*$
- Check whether vm have already dead in dumpping thread
- Return none rather than raise exception when met unknownshell_client
- Keep tty0 for all linux guests
- Enable the serial console in unattended installation
- Add a helper to check whether the panic information was occured
- Keep theporcess()at its original location inpreprocess()
Quoted 7 lines
Jason, after a long conversation I've had with Michael during the previous week, we reached some common points:
1 - We believe it is possible to be able to both log in *and* log serial console output. That will require changes to
kvm_subprocessand might take a little bit more time.
Yes, I've tried a ugly implementation of a server in serial_dump_thread ( finally dropped from my patch ), so I agree that it would be much more elegant if I can get the support from kvm_subprocess.
Quoted 6 lines
2 - We know you guys are depending on this patchset to be accepted in order to proceed with the network related cases. However, we ask for a little more patience, and we'd like to get your opinions on the patches that we are going to roll out. This way we can get to a better solution for all of us.
Quoted 8 lines
So, please bear with us and I'll try to see with Michael and Dor if we can prioritize this work to not block work items for you guys.
Cheers,
Lucas
Ok, no problem.