From patchwork Tue May 11 09:03:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 98649 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 o4B8wn0w015391 for ; Tue, 11 May 2010 08:58:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932301Ab0EKI6h (ORCPT ); Tue, 11 May 2010 04:58:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17028 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932068Ab0EKI6g (ORCPT ); Tue, 11 May 2010 04:58:36 -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 o4B8wZOn019989 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 May 2010 04:58:35 -0400 Received: from localhost.localdomain ([10.66.91.25]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4B8wWA0018500; Tue, 11 May 2010 04:58:33 -0400 Subject: [PATCH v2 02/10] KVM test: Send the username in remote_login() To: lmr@redhat.com, autotest@test.kernel.org From: Jason Wang Cc: kvm@vger.kernel.org Date: Tue, 11 May 2010 17:03:26 +0800 Message-ID: <20100511090326.19914.81130.stgit@localhost.localdomain> In-Reply-To: <20100511083338.19914.7719.stgit@localhost.localdomain> References: <20100511083338.19914.7719.stgit@localhost.localdomain> User-Agent: StGit/0.15 MIME-Version: 1.0 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]); Tue, 11 May 2010 08:58:49 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 11f2b1a..2800fae 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -451,7 +451,7 @@ def check_kvm_source_dir(source_dir): # The following are functions used for SSH, SCP and Telnet communication with # guests. -def remote_login(command, password, prompt, linesep="\n", timeout=10, +def remote_login(command, username, password, prompt, linesep="\n", timeout=10, prompt_assist=None): """ Log into a remote host (guest) using SSH or Telnet. Run the given command @@ -462,6 +462,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, @brief: Log into a remote host (guest) using SSH or Telnet. @param command: The command to execute (e.g. "ssh root@localhost") + @param username: The username to send in reply to a username prompt @param password: The password to send in reply to a password prompt @param prompt: The shell prompt that indicates a successful login @param linesep: The line separator to send instead of "\\n" @@ -471,6 +472,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, password prompt, the shell prompt, etc) @param prompt_assist: An assistant string sent before the pattern matching in order to get the prompt for some kinds of shell_client. + @return Return the kvm_spawn object on success and None on failure. """ sub = kvm_subprocess.kvm_shell_session(command, @@ -478,6 +480,7 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, prompt=prompt) password_prompt_count = 0 + login_prompt_count = 0 logging.debug("Trying to login with command '%s'" % command) @@ -505,9 +508,15 @@ def remote_login(command, password, prompt, linesep="\n", timeout=10, sub.close() return None elif match == 2: # "login:" - logging.debug("Got unexpected login prompt") - sub.close() - return None + if login_prompt_count == 0: + logging.debug("Got username prompt; sending '%s'" % username) + sub.sendline(username) + login_prompt_count += 1 + continue + else: + logging.debug("Got username prompt again") + sub.close() + return None elif match == 3: # "Connection closed" logging.debug("Got 'Connection closed'") sub.close() @@ -644,7 +653,7 @@ def ssh(host, port, username, password, prompt, linesep="\n", timeout=10): command = ("ssh -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -p %s %s@%s" % (port, username, host)) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) def telnet(host, port, username, password, prompt, linesep="\n", timeout=10): @@ -661,7 +670,7 @@ def telnet(host, port, username, password, prompt, linesep="\n", timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "telnet -l %s %s %s" % (username, host, port) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) def netcat(host, port, username, password, prompt, linesep="\n", timeout=10): @@ -678,7 +687,7 @@ def netcat(host, port, username, password, prompt, linesep="\n", timeout=10): @return: kvm_spawn object on success and None on failure. """ command = "nc %s %s" % (host, port) - return remote_login(command, password, prompt, linesep, timeout) + return remote_login(command, username, password, prompt, linesep, timeout) # The following are utility functions related to ports.