From patchwork Fri Jun 18 00:14:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 106783 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 o5I0FfX6016053 for ; Fri, 18 Jun 2010 00:15:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760912Ab0FRAPN (ORCPT ); Thu, 17 Jun 2010 20:15:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46701 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760858Ab0FRAPE (ORCPT ); Thu, 17 Jun 2010 20:15:04 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0F1V5001705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Jun 2010 20:15:01 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0ExSB005045; Thu, 17 Jun 2010 20:14:59 -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 o5I0EljO005733; Thu, 17 Jun 2010 20:14:57 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 08/18] KVM test: simplify remote_scp() Date: Fri, 18 Jun 2010 03:14:25 +0300 Message-Id: <1276820075-31310-8-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276820075-31310-7-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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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:41 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 0ea5a8a..1399892 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -524,20 +524,20 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10): return None -def remote_scp(command, password, timeout=600, login_timeout=10): +def remote_scp(command, password, transfer_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 , - fail. If login_timeout expires while waiting for output from the child - (e.g. a password prompt), fail. + asked. If transfer_timeout expires while waiting for the transfer to + complete, fail. If login_timeout expires while waiting for output from the + child (e.g. a password prompt), fail. @brief: Transfer files using SCP, given a command line. @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 timeout: The time duration (in seconds) to wait for the transfer - to complete. + @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 each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) @@ -547,20 +547,15 @@ def remote_scp(command, password, timeout=600, login_timeout=10): sub = kvm_subprocess.kvm_expect(command) password_prompt_count = 0 - _timeout = login_timeout - end_time = time.time() + timeout - logging.debug("Trying to SCP with command '%s', timeout %ss", command, - timeout) + timeout = login_timeout + + logging.debug("Trying to SCP with command '%s', timeout %ss", + command, timeout) while True: - if end_time <= time.time(): - logging.debug("SCP transfer timed out") - 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"Exit status", r"stalled"], - timeout=_timeout, internal_timeout=0.5) + [r"[Aa]re you sure", r"[Pp]assword:\s*$", r"lost connection"], + 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'") sub.sendline("yes") @@ -570,7 +565,7 @@ def remote_scp(command, password, timeout=600, login_timeout=10): logging.debug("Got password prompt; sending '%s'" % password) sub.sendline(password) password_prompt_count += 1 - _timeout = timeout + timeout = transfer_timeout continue else: logging.debug("Got password prompt again") @@ -580,25 +575,16 @@ def remote_scp(command, password, timeout=600, 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 is stalled") - continue - else: # match == None if sub.is_alive(): - continue - logging.debug("SCP process terminated") - status = sub.get_status() - sub.close() - return status == 0 + logging.debug("Timeout expired") + sub.close() + return False + else: + status = sub.get_status() + sub.close() + logging.debug("SCP process terminated with status %s", status) + return status == 0 def scp_to_remote(host, port, username, password, local_path, remote_path,