To reuse the codes and simplify the test.

Signed-off-by: Jason Wang <jasow...@redhat.com>
---
 client/tests/kvm/tests/nic_promisc.py  |  106 +++++---------------------------
 client/tests/kvm/tests_base.cfg.sample |    4 +
 2 files changed, 18 insertions(+), 92 deletions(-)

diff --git a/client/tests/kvm/tests/nic_promisc.py 
b/client/tests/kvm/tests/nic_promisc.py
index c6d70b6..ac6f983 100644
--- a/client/tests/kvm/tests/nic_promisc.py
+++ b/client/tests/kvm/tests/nic_promisc.py
@@ -1,6 +1,7 @@
 import logging, threading
 from autotest_lib.client.common_lib import error
 from autotest_lib.client.bin import utils
+from autotest_lib.client.tests.kvm.tests import file_transfer
 import kvm_utils, kvm_test_utils
 
 
@@ -10,10 +11,7 @@ def run_nic_promisc(test, params, env):
 
     1) Boot up a VM.
     2) Repeatedly enable/disable promiscuous mode in guest.
-    3) TCP data transmission from host to guest, and from guest to host,
-       with 1/1460/65000/100000000 bytes payloads.
-    4) Clean temporary files.
-    5) Stop enable/disable promiscuous mode change.
+    3) Transfer file from host to guest, and from guest to host in the same 
time
 
     @param test: KVM test object.
     @param params: Dictionary with the test parameters.
@@ -22,94 +20,20 @@ def run_nic_promisc(test, params, env):
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
     timeout = int(params.get("login_timeout", 360))
-    session = vm.wait_for_login(timeout=timeout)
     session_serial = vm.wait_for_serial_login(timeout=timeout)
 
-    def compare(filename):
-        md5_host = utils.hash_file(filename, method="md5")
-        md5_guest = session.cmd("md5sum %s" % filename)
-        md5_guest = md5_guest.split()[0]
-        if md5_host != md5_guest:
-            logging.error("MD5 hash mismatch between file %s "
-                          "present on guest and on host", filename)
-            logging.error("MD5 hash for file on guest: %s,"
-                          "MD5 hash for file on host: %s", md5_host, md5_guest)
-            return False
-        return True
+    ethname = kvm_test_utils.get_linux_ifname(session_serial,
+                                              vm.get_mac_address(0))
 
-    ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0))
-
-    class ThreadPromiscCmd(threading.Thread):
-        def __init__(self, session, termination_event):
-            self.session = session
-            self.termination_event = termination_event
-            super(ThreadPromiscCmd, self).__init__()
-
-
-        def run(self):
-            set_promisc_cmd = ("ip link set %s promisc on; sleep 0.01;"
-                               "ip link set %s promisc off; sleep 0.01" %
-                               (ethname, ethname))
-            while True:
-                self.session.cmd_output(set_promisc_cmd)
-                if self.termination_event.isSet():
-                    break
-
-
-    logging.info("Started thread to change promisc mode in guest")
-    termination_event = threading.Event()
-    promisc_thread = ThreadPromiscCmd(session_serial, termination_event)
-    promisc_thread.start()
-
-    dd_cmd = "dd if=/dev/urandom of=%s bs=%d count=1"
-    filename = "/tmp/nic_promisc_file"
-    file_size = params.get("file_size", "1, 1460, 65000, 100000000").split(",")
-    success_counter = 0
     try:
-        for size in file_size:
-            logging.info("Create %s bytes file on host", size)
-            utils.run(dd_cmd % (filename, int(size)))
-
-            logging.info("Transfer file from host to guest")
-            try:
-                vm.copy_files_to(filename, filename)
-            except kvm_utils.SCPError, e:
-                logging.error("File transfer failed (%s)", e)
-                continue
-            if not compare(filename):
-                logging.error("Compare file failed")
-                continue
-            else:
-                success_counter += 1
-
-            logging.info("Create %s bytes file on guest", size)
-            session.cmd(dd_cmd % (filename, int(size)), timeout=100)
-
-            logging.info("Transfer file from guest to host")
-            try:
-                vm.copy_files_from(filename, filename)
-            except kvm_utils.SCPError, e:
-                logging.error("File transfer failed (%s)", e)
-                continue
-            if not compare(filename):
-                logging.error("Compare file failed")
-                continue
-            else:
-                success_counter += 1
-
-            logging.info("Clean temporary files")
-            cmd = "rm -f %s" % filename
-            utils.run(cmd)
-            session.cmd_output(cmd)
-
-    finally:
-        logging.info("Stopping the promisc thread")
-        termination_event.set()
-        promisc_thread.join(10)
-        logging.info("Restore the %s to the nonpromisc mode", ethname)
-        session.cmd_output("ip link set %s promisc off" % ethname)
-        session.close()
-
-    if success_counter != 2 * len(file_size):
-        raise error.TestFail("Some tests failed, succss_ratio : %s/%s" %
-                             (success_counter, len(file_size)))
+        transfer_thread = kvm_utils.Thread(file_transfer.run_file_transfer,
+                                           (test, params, env))
+        transfer_thread.start()
+        while transfer_thread.isAlive():
+            session_serial.cmd("ip link set %s promisc on" % ethname)
+            session_serial.cmd("ip link set %s promisc off" % ethname)
+    except:
+        transfer_thread.join(suppress_exception=True)
+        raise
+    else:
+        transfer_thread.join()
diff --git a/client/tests/kvm/tests_base.cfg.sample 
b/client/tests/kvm/tests_base.cfg.sample
index 8de3db0..d8898a6 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -654,7 +654,9 @@ variants:
 
     - nic_promisc:  install setup unattended_install.cdrom
         type = nic_promisc
-        file_size = 1, 1460, 65000, 100000000
+        filesize = 400
+        transfer_timeout = 100
+        transfer_type = remote
 
     - multicast: install setup unattended_install.cdrom
         type = multicast

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to