From patchwork Tue Jun 22 01:52:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 107329 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5M1qsdJ008316 for ; Tue, 22 Jun 2010 01:52:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758808Ab0FVBwv (ORCPT ); Mon, 21 Jun 2010 21:52:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37457 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758802Ab0FVBwt (ORCPT ); Mon, 21 Jun 2010 21:52:49 -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 o5M1qmcl026512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 Jun 2010 21:52:49 -0400 Received: from localhost.localdomain (vpn-11-188.rdu.redhat.com [10.11.11.188]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5M1qRts011261; Mon, 21 Jun 2010 21:52:47 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Michael Goldish Subject: [PATCH 10/13] KVM test: log output of all shell sessions and SCP transfers Date: Mon, 21 Jun 2010 22:52:22 -0300 Message-Id: <1277171545-23003-10-git-send-email-lmr@redhat.com> In-Reply-To: <1277171545-23003-1-git-send-email-lmr@redhat.com> References: <1277171545-23003-1-git-send-email-lmr@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]); Tue, 22 Jun 2010 01:52:54 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 354450c..12508b6 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 71df892..0643bca 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -923,13 +923,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_" @@ -952,6 +955,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") @@ -959,7 +964,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): @@ -977,6 +983,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") @@ -984,7 +992,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):