From patchwork Fri Jun 18 00:14:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 106781 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5I0FZBn016037 for ; Fri, 18 Jun 2010 00:15:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760926Ab0FRAPb (ORCPT ); Thu, 17 Jun 2010 20:15:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64197 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760905Ab0FRAPS (ORCPT ); Thu, 17 Jun 2010 20:15:18 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0FFCm030163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Jun 2010 20:15:16 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0FCOj030852; Thu, 17 Jun 2010 20:15:12 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0EljY005733; Thu, 17 Jun 2010 20:15:11 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 18/18] KVM test: log output of all shell sessions and SCP transfers Date: Fri, 18 Jun 2010 03:14:35 +0300 Message-Id: <1276820075-31310-18-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276820075-31310-17-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> <1276820075-31310-15-git-send-email-mgoldish@redhat.com> <1276820075-31310-16-git-send-email-mgoldish@redhat.com> <1276820075-31310-17-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 18 Jun 2010 00:15:35 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 074fa2c..409804a 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -572,7 +572,7 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): def remote_login(client, host, port, username, password, prompt, linesep="\n", - timeout=10): + log_filename=None, timeout=10): """ Log into a remote host (guest) using SSH/Telnet/Netcat. @@ -584,6 +584,7 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", @param prompt: Shell prompt (regular expression) @param linesep: The line separator to use when sending lines (e.g. '\\n' or '\\r\\n') + @param log_filename: If specified, log all output to this file @param timeout: The maximal time duration (in seconds) to wait for each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) @@ -601,16 +602,21 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", else: logging.error("Unknown remote shell client: %s" % client) return + logging.debug("Trying to login with command '%s'" % cmd) session = kvm_subprocess.kvm_shell_session(cmd, linesep=linesep, prompt=prompt) if _remote_login(session, username, password, prompt, timeout): + if log_filename: + session.set_output_func(log_line) + session.set_output_params((log_filename,)) return session else: session.close() -def remote_scp(command, password, transfer_timeout=600, login_timeout=10): +def remote_scp(command, password, log_filename=None, transfer_timeout=600, + login_timeout=10): """ Transfer file(s) to a remote host (guest) using SCP. @@ -619,6 +625,7 @@ def remote_scp(command, password, transfer_timeout=600, login_timeout=10): @param command: The command to execute (e.g. "scp -r foobar root@localhost:/tmp/"). @param password: The password to send in reply to a password prompt. + @param log_filename: If specified, log all output to this file @param transfer_timeout: The time duration (in seconds) to wait for the transfer to complete. @param login_timeout: The maximal time duration (in seconds) to wait for @@ -629,7 +636,17 @@ def remote_scp(command, password, transfer_timeout=600, login_timeout=10): """ logging.debug("Trying to SCP with command '%s', timeout %ss", command, transfer_timeout) - session = kvm_subprocess.kvm_expect(command) + + if log_filename: + output_func = log_line + output_params = (log_filename,) + else: + output_func = None + output_params = () + + session = kvm_subprocess.kvm_expect(command, + output_func=output_func, + output_params=output_params) try: return _remote_scp(session, password, transfer_timeout, login_timeout) finally: @@ -637,7 +654,7 @@ def remote_scp(command, password, transfer_timeout=600, login_timeout=10): def scp_to_remote(host, port, username, password, local_path, remote_path, - timeout=600): + log_filename=None, timeout=600): """ Copy files to a remote host (guest). @@ -646,6 +663,7 @@ def scp_to_remote(host, port, username, password, local_path, remote_path, @param password: Password (if required) @param local_path: Path on the local machine where we are copying from @param remote_path: Path on the remote machine where we are copying to + @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. @@ -654,11 +672,11 @@ def scp_to_remote(host, port, username, password, local_path, remote_path, command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" % (port, local_path, username, host, remote_path)) - return remote_scp(command, password, timeout) + return remote_scp(command, password, log_filename, timeout) def scp_from_remote(host, port, username, password, remote_path, local_path, - timeout=600): + log_filename=None, timeout=600): """ Copy files from a remote host (guest). @@ -667,6 +685,7 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, @param password: Password (if required) @param local_path: Path on the local machine where we are copying from @param remote_path: Path on the remote machine where we are copying to + @param log_filename: If specified, log all output to this file @param timeout: The time duration (in seconds) to wait for the transfer to complete. @@ -675,7 +694,7 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" % (port, username, host, remote_path, local_path)) - return remote_scp(command, password, timeout) + return remote_scp(command, password, log_filename, timeout) # The following are utility functions related to ports. diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index c8a282d..c5234c8 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -921,13 +921,16 @@ class VM: client = self.params.get("shell_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("shell_port"))) + log_filename = ("session-%s-%s.log" % + (self.name, kvm_utils.generate_random_string(4))) if not address or not port: logging.debug("IP address or port unavailable") return None session = kvm_utils.remote_login(client, address, port, username, - password, prompt, linesep, timeout) + password, prompt, linesep, + log_filename, timeout) if session: session.set_status_test_command(self.params.get("status_test_" @@ -950,6 +953,8 @@ class VM: client = self.params.get("file_transfer_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("file_transfer_port"))) + log_filename = ("scp-%s-%s.log" % + (self.name, kvm_utils.generate_random_string(4))) if not address or not port: logging.debug("IP address or port unavailable") @@ -957,7 +962,8 @@ class VM: if client == "scp": return kvm_utils.scp_to_remote(address, port, username, password, - local_path, remote_path, timeout) + local_path, remote_path, + log_filename, timeout) def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=600): @@ -975,6 +981,8 @@ class VM: client = self.params.get("file_transfer_client") address = self.get_address(nic_index) port = self.get_port(int(self.params.get("file_transfer_port"))) + log_filename = ("scp-%s-%s.log" % + (self.name, kvm_utils.generate_random_string(4))) if not address or not port: logging.debug("IP address or port unavailable") @@ -982,7 +990,8 @@ class VM: if client == "scp": return kvm_utils.scp_from_remote(address, port, username, password, - remote_path, local_path, timeout) + remote_path, local_path, + log_filename, timeout) def serial_login(self, timeout=10):