From patchwork Fri Jun 18 00:14:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 106778 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 o5I0FNCa015974 for ; Fri, 18 Jun 2010 00:15:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760918Ab0FRAPS (ORCPT ); Thu, 17 Jun 2010 20:15:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46079 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760909Ab0FRAPH (ORCPT ); Thu, 17 Jun 2010 20:15:07 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0F5Gl030036 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Jun 2010 20:15:06 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0F4On012179; Thu, 17 Jun 2010 20:15:04 -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 o5I0EljS005733; Thu, 17 Jun 2010 20:15:03 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish , Jason Wang Subject: [KVM-AUTOTEST PATCH 12/18] KVM test: send username in remote_login() Date: Fri, 18 Jun 2010 03:14:29 +0300 Message-Id: <1276820075-31310-12-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276820075-31310-11-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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 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:23 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 468e7a8..6750d15 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(session, password, prompt, timeout=10): +def _remote_login(session, username, password, prompt, timeout=10): """ Log into a remote host (guest) using SSH or Telnet. Wait for questions and provide answers. If timeout expires while waiting for output from the @@ -460,6 +460,7 @@ def _remote_login(session, password, prompt, timeout=10): @brief: Log into a remote host (guest) using SSH or Telnet. @param session: A kvm_expect or kvm_shell_session instance to operate on + @param username: The username to send in reply to a login prompt @param password: The password to send in reply to a password prompt @param prompt: The shell prompt that indicates a successful login @param timeout: The maximal time duration (in seconds) to wait for each @@ -469,6 +470,7 @@ def _remote_login(session, password, prompt, timeout=10): @return: True on success and False otherwise. """ password_prompt_count = 0 + login_prompt_count = 0 while True: (match, text) = session.read_until_last_line_matches( @@ -490,8 +492,14 @@ def _remote_login(session, password, prompt, timeout=10): logging.debug("Got password prompt again") return False elif match == 2: # "login:" - logging.debug("Got unexpected login prompt") - return False + if login_prompt_count == 0: + logging.debug("Got username prompt; sending '%s'" % username) + session.sendline(username) + login_prompt_count += 1 + continue + else: + logging.debug("Got username prompt again") + return False elif match == 3: # "Connection closed" logging.debug("Got 'Connection closed'") return False @@ -596,7 +604,7 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", logging.debug("Trying to login with command '%s'" % cmd) session = kvm_subprocess.kvm_shell_session(cmd, linesep=linesep, prompt=prompt) - if _remote_login(session, password, prompt, timeout): + if _remote_login(session, username, password, prompt, timeout): return session else: session.close()