From: Jason Wang <jasowang@redhat.com>
To: lmr@redhat.com, autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH v2 02/10] KVM test: Send the username in remote_login()
Date: Tue, 11 May 2010 17:03:26 +0800 [thread overview]
Message-ID: <20100511090326.19914.81130.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100511083338.19914.7719.stgit@localhost.localdomain>
In order to let the serial console work, we must let the
remote_login() send the username when met the username prompt. This
patch fails the progress if if it met the username prompt twice.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
client/tests/kvm/kvm_utils.py | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
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.
next prev parent reply other threads:[~2010-05-11 9:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-11 9:03 [PATCH v2 00/10] Redirct and make use of the guest serial console Jason Wang
2010-05-11 9:03 ` [PATCH v2 01/10] KVM test: Introduce prompt assist Jason Wang
2010-05-12 22:00 ` Lucas Meneghel Rodrigues
2010-05-11 9:03 ` Jason Wang [this message]
2010-05-11 9:03 ` [PATCH v2 03/10] KVM test: Make the login re suitable for serial console Jason Wang
2010-05-11 9:03 ` [PATCH v2 04/10] KVM test: Redirect the serial to the unix domain socket Jason Wang
2010-05-11 9:03 ` [PATCH v2 05/10] KVM test: Log the content from guest serial console Jason Wang
2010-05-11 9:03 ` [PATCH v2 06/10] KVM test: Return none when met unknown type in kvm_vm.remote_login() Jason Wang
2010-05-11 9:04 ` [PATCH v2 07/10] KVM test: Introduce local_login() Jason Wang
2010-05-11 9:04 ` [PATCH v2 08/10] KVM test: Enable the serial console for all linux guests Jason Wang
2010-05-11 9:04 ` [PATCH v2 09/10] KVM test: Enable the serial console during unattended installation Jason Wang
2010-05-11 9:04 ` [PATCH v2 10/10] KVM test: Add a helper to search the panic in the log Jason Wang
2010-05-12 9:44 ` Michael Goldish
2010-05-17 7:28 ` Jason Wang
2010-05-17 21:23 ` Lucas Meneghel Rodrigues
2010-05-25 14:50 ` [PATCH v2 00/10] Redirct and make use of the guest serial console Lucas Meneghel Rodrigues
2010-05-28 8:19 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100511090326.19914.81130.stgit@localhost.localdomain \
--to=jasowang@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=lmr@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.