nicdriver_unload.py 2.8 KB
Newer Older
1 2
import logging, os, time
from autotest.client import utils
3
from autotest.client.shared import error
4
from virttest import utils_test, utils_net
5 6


7
@error.context_aware
8 9
def run_nicdriver_unload(test, params, env):
    """
10
    Test nic driver load/unload.
11 12 13

    1) Boot a VM.
    2) Get the NIC driver name.
14 15
    3) Multi-session TCP transfer on test interface.
    4) Repeatedly unload/load NIC driver during file transfer.
16 17
    5) Check whether the test interface should still work.

18
    @param test: QEMU test object.
19 20 21
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
22 23


24 25 26 27 28
    timeout = int(params.get("login_timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)

29
    error.context("Get NIC interface name in guest.", logging.info)
30
    ethname = utils_net.get_linux_ifname(session_serial,
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
                                               vm.get_mac_address(0))

    # get ethernet driver from '/sys' directory.
    # ethtool can do the same thing and doesn't care about os type.
    # if we make sure all guests have ethtool, we can make a change here.
    sys_path = params.get("sys_path") % (ethname)

    # readlink in RHEL4.8 doesn't have '-e' param, should use '-f' in RHEL4.8.
    readlink_cmd = params.get("readlink_command", "readlink -e")
    driver = os.path.basename(session_serial.cmd("%s %s" % (readlink_cmd,
                                                 sys_path)).strip())

    logging.info("driver is %s", driver)

    try:
        threads = []
47 48 49
        for i in range(int(params.get("sessions_num", "10"))):
            txt = "File transfer on test interface. Thread %s" % i
            error.context(txt, logging.info)
50 51 52 53 54 55
            thread = utils.InterruptedThread(utils_test.run_file_transfer,
                                             (test, params, env))
            thread.start()
            threads.append(thread)

        time.sleep(10)
56
        logging.info("Repeatedly unload/load NIC driver during file transfer.")
57 58
        while threads[0].isAlive():
            session_serial.cmd("sleep 10")
59
            error.context("Shutdown the driver for NIC interface.", logging.info)
60
            session_serial.cmd("ifconfig %s down" % ethname)
61
            error.context("Unload  NIC driver.", logging.info)
62
            session_serial.cmd("modprobe -r %s" % driver)
63
            error.context("Load NIC driver.", logging.info)
64
            session_serial.cmd("modprobe %s" % driver)
65
            error.context("Activate NIC driver.", logging.info)
66 67 68 69 70 71 72 73
            session_serial.cmd("ifconfig %s up" % ethname)
    except Exception:
        for thread in threads:
            thread.join(suppress_exception=True)
            raise
    else:
        for thread in threads:
            thread.join()