Ejemplo n.º 1
0
def run_nic_bonding(test, params, env):
    """
    Nic bonding test in guest.

    1) Start guest with four nic models.
    2) Setup bond0 in guest by script nic_bonding_guest.py.
    3) Execute file transfer test between guest and host.
    4) Repeatedly put down/up interfaces by set_link
    5) Execute file transfer test between guest and host.

    @param test: Kvm test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", 1200))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)

    # get params of bonding
    modprobe_cmd = "modprobe bonding"
    bonding_params = params.get("bonding_params")
    if bonding_params:
        modprobe_cmd += " %s" % bonding_params
    session_serial.cmd(modprobe_cmd)

    session_serial.cmd("ifconfig bond0 up")
    ifnames = [
        kvm_test_utils.get_linux_ifname(session_serial,
                                        vm.get_mac_address(vlan))
        for vlan, nic in enumerate(params.get("nics").split())
    ]
    setup_cmd = "ifenslave bond0 " + " ".join(ifnames)
    session_serial.cmd(setup_cmd)
    session_serial.cmd("dhclient bond0")

    try:
        logging.info("Test file transfering:")
        file_transfer.run_file_transfer(test, params, env)

        logging.info("Failover test with file transfer")
        transfer_thread = kvm_utils.Thread(file_transfer.run_file_transfer,
                                           (test, params, env))
        try:
            transfer_thread.start()
            while transfer_thread.isAlive():
                for vlan, nic in enumerate(params.get("nics").split()):
                    device_id = vm.get_peer(vm.netdev_id[vlan])
                    vm.monitor.cmd("set_link %s down" % device_id)
                    time.sleep(1)
                    vm.monitor.cmd("set_link %s up" % device_id)
        except:
            transfer_thread.join(suppress_exception=True)
            raise
        else:
            transfer_thread.join()
    finally:
        session_serial.sendline("ifenslave -d bond0 " + " ".join(ifnames))
        session_serial.sendline("kill -9 `pgrep dhclient`")
Ejemplo n.º 2
0
def run_nic_bonding(test, params, env):
    """
    Nic bonding test in guest.

    1) Start guest with four nic models.
    2) Setup bond0 in guest by script nic_bonding_guest.py.
    3) Execute file transfer test between guest and host.
    4) Repeatedly put down/up interfaces by set_link
    5) Execute file transfer test between guest and host.

    @param test: Kvm test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", 1200))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)

    # get params of bonding
    modprobe_cmd = "modprobe bonding"
    bonding_params = params.get("bonding_params")
    if bonding_params:
        modprobe_cmd += " %s" % bonding_params
    session_serial.cmd(modprobe_cmd)

    session_serial.cmd("ifconfig bond0 up")
    ifnames = [kvm_test_utils.get_linux_ifname(session_serial,
                                               vm.get_mac_address(vlan))
               for vlan, nic in enumerate(params.get("nics").split())]
    setup_cmd = "ifenslave bond0 " + " ".join(ifnames)
    session_serial.cmd(setup_cmd)
    session_serial.cmd("dhclient bond0")

    try:
        logging.info("Test file transfering:")
        file_transfer.run_file_transfer(test, params, env)

        logging.info("Failover test with file transfer")
        transfer_thread = kvm_utils.Thread(file_transfer.run_file_transfer,
                                           (test, params, env))
        try:
            transfer_thread.start()
            while transfer_thread.isAlive():
                for vlan, nic in enumerate(params.get("nics").split()):
                    device_id = vm.get_peer(vm.netdev_id[vlan])
                    vm.monitor.cmd("set_link %s down" % device_id)
                    time.sleep(1)
                    vm.monitor.cmd("set_link %s up" % device_id)
        except:
            transfer_thread.join(suppress_exception=True)
            raise
        else:
            transfer_thread.join()
    finally:
        session_serial.sendline("ifenslave -d bond0 " + " ".join(ifnames))
        session_serial.sendline("kill -9 `pgrep dhclient`")
Ejemplo n.º 3
0
def run_set_link(test, params, env):
    """
    KVM guest link test:
    1) Boot up guest with one nic
    2) Ping guest from host
    3) Disable guest link and ping guest from host
    4) Re-enable guest link and ping guest from host
    5) Do file transfer test

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2)

    ip = vm.get_address(0)
    linkname = vm.netdev_id[0]

    logging.info("Pinging guest from host")
    s, o = kvm_test_utils.ping(ip, count=10, timeout=20)
    if s != 0:
        raise error.TestFail("Ping failed, status: %s, output: %s" % (s, o))
    ratio = kvm_test_utils.get_loss_ratio(o)
    if ratio != 0:
        raise error.TestFail("Loss ratio is %s, output: %s" % (ratio, o))

    logging.info("Executing 'set link %s off'", linkname)
    vm.monitor.cmd("set_link %s off" % linkname)
    logging.info(vm.monitor.info("network"))
    logging.info("Pinging guest from host")
    s, o = kvm_test_utils.ping(ip, count=10, timeout=20)
    if s == 0:
        raise error.TestFail("Ping unexpectedly succeeded, status: %s,"
                             "output: %s" % (s, o))
    ratio = kvm_test_utils.get_loss_ratio(o)
    if ratio != 100:
        raise error.TestFail("Loss ratio is not 100%%,"
                             "Loss ratio is %s" % ratio)

    logging.info("Executing 'set link %s on'", linkname)
    vm.monitor.cmd("set_link %s on" % linkname)
    logging.info(vm.monitor.info("network"))
    logging.info("Pinging guest from host")
    s, o = kvm_test_utils.ping(ip, count=10, timeout=20)
    if s != 0:
        raise error.TestFail("Ping failed, status: %s, output: %s" % (s, o))
    ratio = kvm_test_utils.get_loss_ratio(o)
    if ratio != 0:
        raise error.TestFail("Loss ratio is %s, output: %s" % (ratio, o))

    file_transfer.run_file_transfer(test, params, env)
    session.close()
Ejemplo n.º 4
0
def run_nic_bonding(test, params, env):
    """
    Nic bonding test in guest.

    1) Start guest with four nic models.
    2) Setup bond0 in guest by script nic_bonding_guest.py.
    3) Execute file transfer test between guest and host.
    4) Repeatedly put down/up interfaces by set_link
    5) Execute file transfer test between guest and host.

    @param test: Kvm test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    def control_link_loop(vm, termination_event):
        logging.info("Repeatedly put down/up interfaces by set_link")
        while True:
            for i in range(len(params.get("nics").split())):
                linkname = "%s.%s" % (params.get("nic_model"), i)
                cmd = "set_link %s down" % linkname
                vm.monitor.cmd(cmd)
                time.sleep(1)
                cmd = "set_link %s up" % linkname
                vm.monitor.cmd(cmd)
            if termination_event.isSet():
                break

    timeout = int(params.get("login_timeout", 1200))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)
    script_path = kvm_utils.get_path(test.bindir,
                                     "scripts/nic_bonding_guest.py")
    vm.copy_files_to(script_path, "/tmp/nic_bonding_guest.py")
    cmd = "python /tmp/nic_bonding_guest.py %s" % vm.get_mac_address()
    session_serial.cmd(cmd)

    termination_event = threading.Event()
    t = threading.Thread(target=control_link_loop,
                         args=(vm, termination_event))
    try:
        logging.info("Do some basic test before testing high availability")
        file_transfer.run_file_transfer(test, params, env)
        t.start()
        logging.info("Do file transfer testing")
        file_transfer.run_file_transfer(test, params, env)
    finally:
        termination_event.set()
        t.join(10)
        session_serial.close()
Ejemplo n.º 5
0
def run_nic_bonding(test, params, env):
    """
    Nic bonding test in guest.

    1) Start guest with four nic models.
    2) Setup bond0 in guest by script nic_bonding_guest.py.
    3) Execute file transfer test between guest and host.
    4) Repeatedly put down/up interfaces by set_link
    5) Execute file transfer test between guest and host.

    @param test: Kvm test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """

    def control_link_loop(vm, termination_event):
        logging.info("Repeatedly put down/up interfaces by set_link")
        while True:
            for i in range(len(params.get("nics").split())):
                linkname = "%s.%s" % (params.get("nic_model"), i)
                cmd = "set_link %s down" % linkname
                vm.monitor.cmd(cmd)
                time.sleep(1)
                cmd = "set_link %s up" % linkname
                vm.monitor.cmd(cmd)
            if termination_event.isSet():
                break

    timeout = int(params.get("login_timeout", 1200))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)
    script_path = kvm_utils.get_path(test.bindir, "scripts/nic_bonding_guest.py")
    vm.copy_files_to(script_path, "/tmp/nic_bonding_guest.py")
    cmd = "python /tmp/nic_bonding_guest.py %s" % vm.get_mac_address()
    session_serial.cmd(cmd)

    termination_event = threading.Event()
    t = threading.Thread(target=control_link_loop, args=(vm, termination_event))
    try:
        logging.info("Do some basic test before testing high availability")
        file_transfer.run_file_transfer(test, params, env)
        t.start()
        logging.info("Do file transfer testing")
        file_transfer.run_file_transfer(test, params, env)
    finally:
        termination_event.set()
        t.join(10)
        session_serial.close()
Ejemplo n.º 6
0
def run_set_link(test, params, env):
    """
    KVM guest link test:
    1) Boot up guest with one nic
    2) Ping guest from host
    3) Disable guest link and ping guest from host
    4) Re-enable guest link and ping guest from host
    5) Do file transfer test

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2)

    def set_link_test(linkid):
        """
        Issue set_link commands and test its function

        @param linkid: id of netdev or devices to be tested
        """
        ip = vm.get_address(0)

        vm.monitor.cmd("set_link %s down" % linkid)
        s, o = kvm_test_utils.ping(ip, count=10, timeout=20)
        if kvm_test_utils.get_loss_ratio(o) != 100:
            raise error.TestFail("Still can ping the %s after down %s" %
                                 (ip, linkid))

        vm.monitor.cmd("set_link %s up" % linkid)
        s, o = kvm_test_utils.ping(ip, count=10, timeout=20)
        # we use 100% here as the notification of link status changed may be
        # delayed in guest driver
        if kvm_test_utils.get_loss_ratio(o) == 100:
            raise error.TestFail("Packet loss during ping %s after up %s" %
                                 (ip, linkid))

    netdev_id = vm.netdev_id[0]
    device_id = vm.get_peer(netdev_id)
    logging.info("Issue set_link commands for netdevs")
    set_link_test(netdev_id)
    logging.info("Issue set_link commands for network devics")
    set_link_test(device_id)

    file_transfer.run_file_transfer(test, params, env)
    session.close()