Index: client/tests/kvm/tests/nic_promisc.py |
diff --git a/client/tests/kvm/tests/nic_promisc.py b/client/tests/kvm/tests/nic_promisc.py |
index 99bbf8cee15abbff70307a663f2296311d65c1bd..c6d70b6992863d6ef25dd081ecd341825db6f33e 100644 |
--- a/client/tests/kvm/tests/nic_promisc.py |
+++ b/client/tests/kvm/tests/nic_promisc.py |
@@ -1,8 +1,9 @@ |
-import logging |
+import logging, threading |
from autotest_lib.client.common_lib import error |
from autotest_lib.client.bin import utils |
import kvm_utils, kvm_test_utils |
+ |
def run_nic_promisc(test, params, env): |
""" |
Test nic driver in promisc mode: |
@@ -18,24 +19,15 @@ def run_nic_promisc(test, params, env): |
@param params: Dictionary with the test parameters. |
@param env: Dictionary with test environment. |
""" |
+ vm = env.get_vm(params["main_vm"]) |
+ vm.verify_alive() |
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 = vm.wait_for_login(timeout=timeout) |
+ session_serial = vm.wait_for_serial_login(timeout=timeout) |
def compare(filename): |
- cmd = "md5sum %s" % filename |
md5_host = utils.hash_file(filename, method="md5") |
- rc_guest, md5_guest = session.get_command_status_output(cmd) |
- if rc_guest: |
- logging.debug("Could not get MD5 hash for file %s on guest," |
- "output: %s", filename, md5_guest) |
- return False |
+ 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 " |
@@ -46,11 +38,28 @@ def run_nic_promisc(test, params, env): |
return True |
ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0)) |
- set_promisc_cmd = ("ip link set %s promisc on; sleep 0.01;" |
- "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) |
+ |
+ 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" |
@@ -58,12 +67,14 @@ def run_nic_promisc(test, params, env): |
success_counter = 0 |
try: |
for size in file_size: |
- logging.info("Create %s bytes file on host" % 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") |
- if not vm.copy_files_to(filename, filename): |
- logging.error("File transfer failed") |
+ 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") |
@@ -71,15 +82,14 @@ def run_nic_promisc(test, params, env): |
else: |
success_counter += 1 |
- logging.info("Create %s bytes file on guest" % size) |
- if session.get_command_status(dd_cmd % (filename, int(size)), |
- timeout=100) != 0: |
- logging.error("Create file on guest failed") |
- continue |
+ 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") |
- if not vm.copy_files_from(filename, filename): |
- logging.error("File transfer failed") |
+ 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") |
@@ -90,12 +100,14 @@ def run_nic_promisc(test, params, env): |
logging.info("Clean temporary files") |
cmd = "rm -f %s" % filename |
utils.run(cmd) |
- session.get_command_status(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) |
- session2.close() |
- session.get_command_status("ip link set %s promisc off" % ethname) |
+ session.cmd_output("ip link set %s promisc off" % ethname) |
session.close() |
if success_counter != 2 * len(file_size): |