[PATCH] virt.tests.ethtool: Improving logging and fixing loop execution

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

 



Make sure we go through all tests available and record the failures.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx>
---
 client/virt/tests/ethtool.py |  101 ++++++++++++++++++++++++++----------------
 1 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/client/virt/tests/ethtool.py b/client/virt/tests/ethtool.py
index fa9448e..45942a8 100644
--- a/client/virt/tests/ethtool.py
+++ b/client/virt/tests/ethtool.py
@@ -6,7 +6,7 @@ from autotest_lib.client.virt import virt_test_utils, virt_utils, aexpect
 
 def run_ethtool(test, params, env):
     """
-    Test offload functions of ethernet device by ethtool
+    Test offload functions of ethernet device using ethtool
 
     1) Log into a guest.
     2) Initialize the callback of sub functions.
@@ -35,9 +35,11 @@ def run_ethtool(test, params, env):
             }
         o = session.cmd("ethtool -k %s" % ethname)
         try:
-            return re.findall("%s: (.*)" % feature_pattern.get(f_type), o)[0]
+            result = re.findall("%s: (.*)" % feature_pattern.get(f_type), o)[0]
+            logging.debug("(%s) %s: %s", ethname, f_type, result)
+            return result
         except IndexError:
-            logging.debug("Could not get %s status", f_type)
+            logging.debug("(%s) %s: failed to get status", ethname, f_type)
 
 
     def ethtool_set(f_type, status):
@@ -47,7 +49,7 @@ def run_ethtool(test, params, env):
         @param f_type: Offload type name
         @param status: New status will be changed to
         """
-        logging.info("Try to set %s %s", f_type, status)
+        logging.info("(%s) %s: set status %s", ethname, f_type, status)
         if status not in ["off", "on"]:
             return False
         cmd = "ethtool -K %s %s %s" % (ethname, f_type, status)
@@ -55,28 +57,30 @@ def run_ethtool(test, params, env):
             try:
                 session.cmd(cmd)
                 return True
-            except Exception:
+            except aexpect.ShellCmdError, e:
+                logging.error(e)
                 return False
         if ethtool_get(f_type) != status:
-            logging.error("Fail to set %s %s", f_type, status)
+            logging.error("(%s) %s: set status %s failed", ethname, f_type,
+                          status)
             return False
         return True
 
 
     def ethtool_save_params():
-        logging.info("Save ethtool configuration")
+        logging.info("Saving ethtool configuration")
         for i in supported_features:
             feature_status[i] = ethtool_get(i)
 
 
     def ethtool_restore_params():
-        logging.info("Restore ethtool configuration")
+        logging.info("Restoring ethtool configuration")
         for i in supported_features:
             ethtool_set(i, feature_status[i])
 
 
     def compare_md5sum(name):
-        logging.info("Compare md5sum of the files on guest and host")
+        logging.info("Comparing md5sum of the files on guest and host")
         host_result = utils.hash_file(name, method="md5")
         try:
             o = session.cmd_output("md5sum %s" % name)
@@ -88,7 +92,7 @@ def run_ethtool(test, params, env):
         return guest_result == host_result
 
 
-    def transfer_file(src="guest"):
+    def transfer_file(src):
         """
         Transfer file by scp, use tcpdump to capture packets, then check the
         return string.
@@ -97,21 +101,24 @@ def run_ethtool(test, params, env):
         @return: Tuple (status, error msg/tcpdump result)
         """
         session2.cmd_output("rm -rf %s" % filename)
+
         dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" %
                   (filename, params.get("filesize")))
-        failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd)
-        logging.info("Creating file in source host, cmd: %s", dd_cmd)
+
+        failure = (False, "Failed to create file using: %s" % dd_cmd)
+
+        logging.info("Creating file in %s, cmd: %s", src, dd_cmd)
         tcpdump_cmd = "tcpdump -lep -s 0 tcp -vv port ssh"
         if src == "guest":
             tcpdump_cmd += " and src %s" % guest_ip
-            copy_files_from = vm.copy_files_from
+            copy_files_func = vm.copy_files_from
             try:
                 session.cmd_output(dd_cmd, timeout=360)
             except aexpect.ShellCmdError, e:
                 return failure
         else:
             tcpdump_cmd += " and dst %s" % guest_ip
-            copy_files_from = vm.copy_files_to
+            copy_files_func = vm.copy_files_to
             try:
                 utils.system(dd_cmd)
             except error.CmdError, e:
@@ -119,34 +126,36 @@ def run_ethtool(test, params, env):
 
         # only capture the new tcp port after offload setup
         original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip,
-                                      utils.system_output("/bin/netstat -nap"))
+                                       utils.system_output("/bin/netstat -nap"))
+
         for i in original_tcp_ports:
             tcpdump_cmd += " and not port %s" % i
-        logging.debug("Listen using command: %s", tcpdump_cmd)
+
+        logging.debug("Listening traffic using command: %s", tcpdump_cmd)
         session2.sendline(tcpdump_cmd)
         if not virt_utils.wait_for(
                            lambda:session.cmd_status("pgrep tcpdump") == 0, 30):
             return (False, "Tcpdump process wasn't launched")
 
-        logging.info("Start to transfer file")
+        logging.info("Transfering file %s from %s", filename, src)
         try:
-            copy_files_from(filename, filename)
+            copy_files_func(filename, filename)
         except virt_utils.SCPError, e:
             return (False, "File transfer failed (%s)" % e)
-        logging.info("Transfer file completed")
+
         session.cmd("killall tcpdump")
         try:
             tcpdump_string = session2.read_up_to_prompt(timeout=60)
         except aexpect.ExpectError:
-            return (False, "Fail to read tcpdump's output")
+            return (False, "Failed to read tcpdump's output")
 
         if not compare_md5sum(filename):
-            return (False, "Files' md5sum mismatched")
+            return (False, "Failure, md5sum mismatch")
         return (True, tcpdump_string)
 
 
     def tx_callback(status="on"):
-        s, o = transfer_file(src="guest")
+        s, o = transfer_file("guest")
         if not s:
             logging.error(o)
             return False
@@ -154,7 +163,7 @@ def run_ethtool(test, params, env):
 
 
     def rx_callback(status="on"):
-        s, o = transfer_file(src="host")
+        s, o = transfer_file("host")
         if not s:
             logging.error(o)
             return False
@@ -162,7 +171,7 @@ def run_ethtool(test, params, env):
 
 
     def so_callback(status="on"):
-        s, o = transfer_file(src="guest")
+        s, o = transfer_file("guest")
         if not s:
             logging.error(o)
             return False
@@ -173,7 +182,7 @@ def run_ethtool(test, params, env):
 
 
     def ro_callback(status="on"):
-        s, o = transfer_file(src="host")
+        s, o = transfer_file("host")
         if not s:
             logging.error(o)
             return False
@@ -183,6 +192,7 @@ def run_ethtool(test, params, env):
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
     session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
+
     # Let's just error the test if we identify that there's no ethtool installed
     session.cmd("ethtool -h")
     session2 = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
@@ -191,11 +201,13 @@ def run_ethtool(test, params, env):
     filename = "/tmp/ethtool.dd"
     guest_ip = vm.get_address()
     ethname = virt_test_utils.get_linux_ifname(session, vm.get_mac_address(0))
+
     supported_features = params.get("supported_features")
     if supported_features:
         supported_features = supported_features.split()
     else:
-        supported_features = []
+        raise error.TestError("No supported features set on the parameters")
+
     test_matrix = {
         # type:(callback,    (dependence), (exclude)
         "tx":  (tx_callback, (), ()),
@@ -207,28 +219,41 @@ def run_ethtool(test, params, env):
         "lro": (rx_callback, (), ("gro",)),
         }
     ethtool_save_params()
-    success = True
+    failed_tests = []
     try:
         for f_type in supported_features:
             callback = test_matrix[f_type][0]
+
             for i in test_matrix[f_type][2]:
                 if not ethtool_set(i, "off"):
-                    logging.error("Fail to disable %s", i)
-                    success = False
+                    e_msg = "Failed to disable %s" % i
+                    logging.error(e_msg)
+                    failed_tests.append(e_msg)
+
             for i in [f for f in test_matrix[f_type][1]] + [f_type]:
                 if not ethtool_set(i, "on"):
-                    logging.error("Fail to enable %s", i)
-                    success = False
-            if not callback():
-                raise error.TestFail("Test failed, %s: on" % f_type)
+                    e_msg = "Failed to enable %s" % i
+                    logging.error(e_msg)
+                    failed_tests.append(e_msg)
+
+            if not callback(status="on"):
+                e_msg = "Callback failed after enabling %s" % f_type
+                logging.error(e_msg)
+                failed_tests.append(e_msg)
 
             if not ethtool_set(f_type, "off"):
-                logging.error("Fail to disable %s", f_type)
-                success = False
+                e_msg = "Failed to disable %s" % f_type
+                logging.error(e_msg)
+                failed_tests.append(e_msg)
+
             if not callback(status="off"):
-                raise error.TestFail("Test failed, %s: off" % f_type)
-        if not success:
-            raise error.TestError("Enable/disable offload function fail")
+                e_msg = "Callback failed after disabling %s" % f_type
+                logging.error(e_msg)
+                failed_tests.append(e_msg)
+
+        if failed_tests:
+            raise error.TestFail("Failed tests: %s" % failed_tests)
+
     finally:
         ethtool_restore_params()
         session.close()
-- 
1.7.7.6

--
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