From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 15/18] KVM test: kvm_vm.py: log serial console output and allow serial login Date: Fri, 18 Jun 2010 03:14:32 +0300 Message-ID: <1276820075-31310-15-git-send-email-mgoldish@redhat.com> References: <1276820075-31310-1-git-send-email-mgoldish@redhat.com> <1276820075-31310-2-git-send-email-mgoldish@redhat.com> <1276820075-31310-3-git-send-email-mgoldish@redhat.com> <1276820075-31310-4-git-send-email-mgoldish@redhat.com> <1276820075-31310-5-git-send-email-mgoldish@redhat.com> <1276820075-31310-6-git-send-email-mgoldish@redhat.com> <1276820075-31310-7-git-send-email-mgoldish@redhat.com> <1276820075-31310-8-git-send-email-mgoldish@redhat.com> <1276820075-31310-9-git-send-email-mgoldish@redhat.com> <1276820075-31310-10-git-send-email-mgoldish@redhat.com> <1276820075-31310-11-git-send-email-mgoldish@redhat.com> <1276820075-31310-12-git-send-email-mgoldish@redhat.com> <1276820075-31310-13-git-send-email-mgoldish@redhat.com> <1276820075-31310-14-git-send-email-mgoldish@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: In-Reply-To: <1276820075-31310-14-git-send-email-mgoldish@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org 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 --- 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 5012d66..c8a282d 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 @@ -632,6 +633,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: @@ -705,6 +715,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: @@ -973,6 +985,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.5.4.1