[PATCH 07/13] KVM test: kvm_vm.py: log serial console output and allow serial login

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Michael Goldish <mgoldish@xxxxxxxxxx>

Log serial console output to files in the debug dir.

Also, add VM.serial_login() which attempts to log in via the serial console.

Note:

- Tests must NOT close() a serial console session, because it needs to remain
  open for the following tests to use.

- Instead, tests must use session.sendline("exit") for serial console sessions:

    session = vm.serial_login()
    try:
        ...
    finally:
        session.sendline("exit")

- Only one serial console session per VM is available at a time.
  Calling serial_login() twice for the same VM, without an "exit" between the
  calls, will probably fail and/or do bad stuff.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_vm.py |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 1edecb9..71df892 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -106,6 +106,7 @@ class VM:
         @param address_cache: A dict that maps MAC addresses to IP addresses
         """
         self.process = None
+        self.serial_console = None
         self.redirs = {}
         self.vnc_port = 5900
         self.uuid = None
@@ -634,6 +635,15 @@ class VM:
                 return False
 
             logging.debug("VM appears to be alive with PID %s", self.get_pid())
+
+            # Establish a session with the serial console -- requires a version
+            # of netcat that supports -U
+            self.serial_console = kvm_subprocess.kvm_shell_session(
+                "nc -U %s" % self.get_serial_console_filename(),
+                auto_close=False,
+                output_func=kvm_utils.log_line,
+                output_params=("serial-%s.log" % name,))
+
             return True
 
         finally:
@@ -707,6 +717,8 @@ class VM:
                 self.pci_assignable.release_devs()
             if self.process:
                 self.process.close()
+            if self.serial_console:
+                self.serial_console.close()
             for f in ([self.get_testlog_filename()] +
                       self.get_monitor_filenames()):
                 try:
@@ -975,6 +987,35 @@ class VM:
                                              remote_path, local_path, timeout)
 
 
+    def serial_login(self, timeout=10):
+        """
+        Log into the guest via the serial console.
+        If timeout expires while waiting for output from the guest (e.g. a
+        password prompt or a shell prompt) -- fail.
+
+        @param timeout: Time (seconds) before giving up logging into the guest.
+        @return: kvm_spawn object on success and None on failure.
+        """
+        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"))
+        status_test_command = self.params.get("status_test_command", "")
+
+        if self.serial_console:
+            self.serial_console.set_linesep(linesep)
+            self.serial_console.set_status_test_command(status_test_command)
+        else:
+            return None
+
+        # Make sure we get a login prompt
+        self.serial_console.sendline()
+
+        if kvm_utils._remote_login(self.serial_console, username, password,
+                                   prompt, timeout):
+            return self.serial_console
+
+
     def send_key(self, keystr):
         """
         Send a key event to the VM.
-- 
1.7.0.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux