[KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These are intended as a replacement for kvm_test_utils.wait_for_login().

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_utils.py |   29 +++++++++++++++++++++++++++
 client/tests/kvm/kvm_vm.py    |   43 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 24285d4..cb79c59 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -616,6 +616,35 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n",
     return session
 
 
+def wait_for_login(client, host, port, username, password, prompt, linesep="\n",
+                   log_filename=None, timeout=240, internal_timeout=10):
+    """
+    Make multiple attempts to log into a remote host (guest) until one succeeds
+    or timeout expires.
+
+    @param timeout: Total time duration to wait for a successful login
+    @param internal_timeout: The maximal time duration (in seconds) to wait for
+            each step of the login procedure (e.g. the "Are you sure" prompt
+            or the password prompt)
+    @see: remote_login()
+    @raise: Whatever remote_login() raises
+    @return: A ShellSession object.
+    """
+    logging.debug("Attempting to log into %s:%s using %s (timeout %ds)" %
+                  (host, port, client))
+    end_time = time.time() + timeout
+    while time.time() < end_time:
+        try:
+            return remote_login(client, host, port, username, password, prompt,
+                                linesep, log_filename, internal_timeout)
+        except LoginError, e:
+            logging.debug(e)
+        time.sleep(2)
+    # Timeout expired; try one more time but don't catch exceptions
+    return remote_login(client, host, port, username, password, prompt,
+                        linesep, log_filename, internal_timeout)
+
+
 def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
     """
     Transfer file(s) to a remote host (guest) using SCP.  Wait for questions
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 023926b..0bc8a8b 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -1091,6 +1091,28 @@ class VM:
         return session
 
 
+    def wait_for_login(self, nic_index=0, timeout=240, internal_timeout=10):
+        """
+        Make multiple attempts to log into the guest via SSH/Telnet/Netcat.
+
+        @param nic_index: The index of the NIC to connect to.
+        @param timeout: Time (seconds) to keep trying to log in.
+        @param internal_timeout: Timeout to pass to remote_login().
+        @return: A ShellSession object.
+        """
+        logging.debug("Attempting to log into '%s' (timeout %ds)" % (self.name,
+                                                                     timeout))
+        end_time = time.time() + timeout
+        while time.time() < end_time:
+            try:
+                return self.remote_login(nic_index, internal_timeout)
+            except kvm_utils.LoginError, e:
+                logging.debug(e)
+            time.sleep(2)
+        # Timeout expired; try one more time but don't catch exceptions
+        return self.remote_login(nic_index, internal_timeout)
+
+
     def copy_files_to(self, local_path, remote_path, nic_index=0, timeout=600):
         """
         Transfer files to the remote host(guest).
@@ -1162,6 +1184,27 @@ class VM:
         return self.serial_console
 
 
+    def wait_for_serial_login(self, timeout=240, internal_timeout=10):
+        """
+        Make multiple attempts to log into the guest via serial console.
+
+        @param timeout: Time (seconds) to keep trying to log in.
+        @param internal_timeout: Timeout to pass to serial_login().
+        @return: A ShellSession object.
+        """
+        logging.debug("Attempting to log into '%s' via serial console "
+                      "(timeout %ds)" % (self.name, timeout))
+        end_time = time.time() + timeout
+        while time.time() < end_time:
+            try:
+                return self.serial_login(internal_timeout)
+            except kvm_utils.LoginError, e:
+                logging.debug(e)
+            time.sleep(2)
+        # Timeout expired; try one more time but don't catch exceptions
+        return self.serial_login(internal_timeout)
+
+
     def send_key(self, keystr):
         """
         Send a key event to the VM.
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux