diff mbox

[2/9] KVM test: Add the ability to send the username in remote_login()

Message ID 20100426100338.26268.15473.stgit@localhost.localdomain (mailing list archive)
State New, archived
Headers show

Commit Message

Jason Wang April 26, 2010, 10:03 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 9adbaee..1ea0852 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -452,7 +452,7 @@  def check_kvm_source_dir(source_dir):
 # guests.
 
 def remote_login(command, password, prompt, linesep="\n", timeout=10,
-                 prompt_assist = None):
+                 prompt_assist = None, username = None):
     """
     Log into a remote host (guest) using SSH or Telnet. Run the given command
     using kvm_spawn and provide answers to the questions asked. If timeout
@@ -471,6 +471,8 @@  def remote_login(command, password, prompt, linesep="\n", timeout=10,
             password prompt, the shell prompt, etc)
     @prarm prompt_assist: An assistant string sent before the pattern
             matching in order to get the prompt for some kinds of shell_client.
+    @param username: The user name used to log into the session
+            
     @return Return the kvm_spawn object on success and None on failure.
     """
     sub = kvm_subprocess.kvm_shell_session(command,
@@ -505,9 +507,13 @@  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 username is None:
+                logging.debug("Got unexpected login prompt")
+                sub.close()
+                return None
+            else:
+                sub.sendline(username)
+                continue
         elif match == 3:  # "Connection closed"
             logging.debug("Got 'Connection closed'")
             sub.close()