From patchwork Fri May 7 10:26:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Yang X-Patchwork-Id: 97715 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 o47AQOcp023890 for ; Fri, 7 May 2010 10:26:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755196Ab0EGK0T (ORCPT ); Fri, 7 May 2010 06:26:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54699 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753965Ab0EGK0S (ORCPT ); Fri, 7 May 2010 06:26:18 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o47AQG5G004335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 May 2010 06:26:16 -0400 Received: from localhost.localdomain ([10.66.91.72]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o47AQDFa032427; Fri, 7 May 2010 06:26:14 -0400 From: Feng Yang To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Feng Yang Subject: [Autotest][PATCH] KVM Test: Make remote_scp() more robust. Date: Fri, 7 May 2010 18:26:13 +0800 Message-Id: <1273227973-11862-1-git-send-email-fyang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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, 07 May 2010 10:27:03 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 25f3c8c..3db4dec 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -524,7 +524,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): return None -def remote_scp(command, password, timeout=300, login_timeout=10): +def remote_scp(command, password, timeout=600, login_timeout=10): """ Run the given command using kvm_spawn and provide answers to the questions asked. If timeout expires while waiting for the transfer to complete , @@ -548,12 +548,18 @@ def remote_scp(command, password, timeout=300, login_timeout=10): password_prompt_count = 0 _timeout = login_timeout + end_time = time.time() + timeout + logging.debug("Trying to SCP...") - logging.debug("Trying to login...") while True: + if end_time <= time.time(): + logging.debug("transfer timeout!") + sub.close() + return False (match, text) = sub.read_until_last_line_matches( - [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"lost connection"], + [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"lost connection", + r"Exit status", r"stalled"], timeout=_timeout, internal_timeout=0.5) if match == 0: # "Are you sure you want to continue connecting" logging.debug("Got 'Are you sure...'; sending 'yes'") @@ -574,15 +580,29 @@ def remote_scp(command, password, timeout=300, login_timeout=10): logging.debug("Got 'lost connection'") sub.close() return False + elif match == 3: # "Exit status" + sub.close() + if "Exit status 0" in text: + logging.debug("SCP command completed successfully") + return True + else: + logging.debug("SCP command fail with exit status %s" % text) + return False + elif match == 4: # "stalled" + logging.debug("SCP connection stalled for some reason") + continue + else: # match == None - logging.debug("Timeout elapsed or process terminated") + if sub.is_alive(): + continue + logging.debug("Process terminated for some reason") status = sub.get_status() sub.close() return status == 0 def scp_to_remote(host, port, username, password, local_path, remote_path, - timeout=300): + timeout=600): """ Copy files to a remote host (guest). @@ -596,14 +616,14 @@ def scp_to_remote(host, port, username, password, local_path, remote_path, @return: True on success and False on failure. """ - command = ("scp -o UserKnownHostsFile=/dev/null " + 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) def scp_from_remote(host, port, username, password, remote_path, local_path, - timeout=300): + timeout=600): """ Copy files from a remote host (guest). @@ -617,7 +637,7 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, @return: True on success and False on failure. """ - command = ("scp -o UserKnownHostsFile=/dev/null " + 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) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 6bc7987..d1e0246 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -808,7 +808,7 @@ class VM: return session - def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=300): + def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=600): """ Transfer files to the guest. @@ -833,7 +833,7 @@ class VM: local_path, remote_path, timeout) - def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=300): + def copy_files_from(self, remote_path, local_path, nic_index=0, timeout=600): """ Transfer files from the guest.