Changes from v1:
- Convert all net tests to use new function
- Update debug info

Signed-off-by: Amos Kong <[email protected]>
---
 0 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_test_utils.py 
b/client/tests/kvm/kvm_test_utils.py
index 014f265..11e3e58 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -44,7 +44,7 @@ def get_living_vm(env, vm_name):
     return vm
 
 
-def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2):
+def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2, serial=None):
     """
     Try logging into a VM repeatedly.  Stop on success or when timeout expires.
 
@@ -53,9 +53,16 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, 
step=2):
     @param timeout: Time to wait before giving up.
     @return: A shell session object.
     """
-    logging.info("Trying to log into guest '%s', timeout %ds", vm.name, 
timeout)
-    session = kvm_utils.wait_for(lambda: vm.remote_login(nic_index=nic_index),
-                                 timeout, start, step)
+    if serial:
+        logging.info("Trying to log into guest using serial connection,"
+                     " timeout %ds", timeout)
+        session = kvm_utils.wait_for(lambda: vm.serial_login(), timeout,
+                                     start, step)
+    else:
+        logging.info("Trying to log into guest %s using remote connection,"
+                     " timeout %ds", vm.name, timeout)
+        session = kvm_utils.wait_for(lambda: vm.remote_login(
+                  nic_index=nic_index), timeout, start, step)
     if not session:
         raise error.TestFail("Could not log into guest '%s'" % vm.name)
     logging.info("Logged into guest '%s'" % vm.name)
diff --git a/client/tests/kvm/tests/mac_change.py 
b/client/tests/kvm/tests/mac_change.py
index c614e15..f286b03 100644
--- a/client/tests/kvm/tests/mac_change.py
+++ b/client/tests/kvm/tests/mac_change.py
@@ -17,12 +17,8 @@ def run_mac_change(test, params, env):
     """
     timeout = int(params.get("login_timeout", 360))
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
-    logging.info("Trying to log into guest '%s' by serial", vm.name)
-    session = kvm_utils.wait_for(lambda: vm.serial_login(),
-                                  timeout, 0, step=2)
-    if not session:
-        raise error.TestFail("Could not log into guest '%s'" % vm.name)
-
+    session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2,
+                                                   serial=True)
     old_mac = vm.get_mac_address(0)
     while True:
         vm.free_mac_address(0)
@@ -30,30 +26,30 @@ def run_mac_change(test, params, env):
         if old_mac != new_mac:
             break
     logging.info("The initial MAC address is %s", old_mac)
-    interface = kvm_test_utils.get_linux_ifname(session, old_mac)
+    interface = kvm_test_utils.get_linux_ifname(session_serial, old_mac)
     # Start change MAC address
     logging.info("Changing MAC address to %s", new_mac)
     change_cmd = ("ifconfig %s down && ifconfig %s hw ether %s && "
                   "ifconfig %s up" % (interface, interface, new_mac, 
interface))
-    if session.get_command_status(change_cmd) != 0:
+    if session_serial.get_command_status(change_cmd) != 0:
         raise error.TestFail("Fail to send mac_change command")
 
     # Verify whether MAC address was changed to the new one
     logging.info("Verifying the new mac address")
-    if session.get_command_status("ifconfig | grep -i %s" % new_mac) != 0:
+    if session_serial.get_command_status("ifconfig |grep -i %s" % new_mac) != 
0:
         raise error.TestFail("Fail to change MAC address")
 
     # Restart `dhclient' to regain IP for new mac address
     logging.info("Restart the network to gain new IP")
     dhclient_cmd = "dhclient -r && dhclient %s" % interface
-    session.sendline(dhclient_cmd)
+    session_serial.sendline(dhclient_cmd)
 
     # Re-log into the guest after changing mac address
-    if kvm_utils.wait_for(session.is_responsive, 120, 20, 3):
+    if kvm_utils.wait_for(session_serial.is_responsive, 120, 20, 3):
         # Just warning when failed to see the session become dead,
         # because there is a little chance the ip does not change.
         logging.warn("The session is still responsive, settings may fail.")
-    session.close()
+    session_serial.close()
 
     # Re-log into guest and check if session is responsive
     logging.info("Re-log into the guest")
diff --git a/client/tests/kvm/tests/nic_promisc.py 
b/client/tests/kvm/tests/nic_promisc.py
index 99bbf8c..f7965e0 100644
--- a/client/tests/kvm/tests/nic_promisc.py
+++ b/client/tests/kvm/tests/nic_promisc.py
@@ -21,12 +21,8 @@ def run_nic_promisc(test, params, env):
     timeout = int(params.get("login_timeout", 360))
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
     session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
-
-    logging.info("Trying to log into guest '%s' by serial", vm.name)
-    session2 = kvm_utils.wait_for(lambda: vm.serial_login(),
-                                  timeout, 0, step=2)
-    if not session2:
-        raise error.TestFail("Could not log into guest '%s'" % vm.name)
+    session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2,
+                                                   serial=True)
 
     def compare(filename):
         cmd = "md5sum %s" % filename
@@ -50,7 +46,7 @@ def run_nic_promisc(test, params, env):
                        "ip link set %s promisc off; sleep 0.01" %
                        (ethname, ethname))
     logging.info("Set promisc change repeatedly in guest")
-    session2.sendline("while true; do %s; done" % set_promisc_cmd)
+    session_serial.sendline("while true; do %s; done" % set_promisc_cmd)
 
     dd_cmd = "dd if=/dev/urandom of=%s bs=%d count=1"
     filename = "/tmp/nic_promisc_file"
@@ -94,7 +90,7 @@ def run_nic_promisc(test, params, env):
 
     finally:
         logging.info("Restore the %s to the nonpromisc mode", ethname)
-        session2.close()
+        session_serial.close()
         session.get_command_status("ip link set %s promisc off" % ethname)
         session.close()
 
diff --git a/client/tests/kvm/tests/nicdriver_unload.py 
b/client/tests/kvm/tests/nicdriver_unload.py
index 47318ba..6a2bc10 100644
--- a/client/tests/kvm/tests/nicdriver_unload.py
+++ b/client/tests/kvm/tests/nicdriver_unload.py
@@ -20,11 +20,8 @@ def run_nicdriver_unload(test, params, env):
     timeout = int(params.get("login_timeout", 360))
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
     session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
-    logging.info("Trying to log into guest '%s' by serial", vm.name)
-    session2 = kvm_utils.wait_for(lambda: vm.serial_login(),
-                                  timeout, 0, step=2)
-    if not session2:
-        raise error.TestFail("Could not log into guest '%s'" % vm.name)
+    session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2,
+                                                   serial=True)
 
     ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0))
     sys_path = "/sys/class/net/%s/device/driver" % (ethname)
@@ -77,7 +74,8 @@ def run_nicdriver_unload(test, params, env):
         logging.info("Unload/load NIC driver repeatedly in guest...")
         while True:
             logging.debug("Try to unload/load nic drive once")
-            if session2.get_command_status(unload_load_cmd, timeout=120) != 0:
+            if session_serial.get_command_status(unload_load_cmd,
+                                                 timeout=120) != 0:
                 session.get_command_output("rm -rf /tmp/Thread-*")
                 raise error.TestFail("Unload/load nic driver failed")
             pid, s = os.waitpid(pid, os.WNOHANG)
@@ -96,7 +94,7 @@ def run_nicdriver_unload(test, params, env):
             t.join(timeout = scp_timeout)
         os._exit(0)
 
-    session2.close()
+    session_serial.close()
 
     try:
         logging.info("Check MD5 hash for received files in multi-session")

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to