Esempio n. 1
0
    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)
        error.context("Disable guest link by set_link", logging.info)
        vm.set_link(linkid, up=False)
        error.context("Ping guest from host", logging.info)
        s, o = utils_test.ping(ip, count=10, timeout=20)
        if utils_test.get_loss_ratio(o) != 100:
            raise error.TestFail("Still can ping the %s after down %s" %
                                 (ip, linkid))

        error.context("Re-enable guest link by set_link", logging.info)
        vm.set_link(linkid, up=True)
        # Waiting for guest network up again.
        session = vm.wait_for_login(timeout=timeout)
        session.close()
        error.context("Ping guest from host", logging.info)
        s, o = utils_test.ping(ip, count=10, timeout=20)
        # we use 100% here as the notification of link status changed may be
        # delayed in guest driver
        if utils_test.get_loss_ratio(o) == 100:
            raise error.TestFail("Packet loss during ping %s after up %s" %
                                 (ip, linkid))
Esempio n. 2
0
 def flood_ping():
     logging.info("Flood with large frames")
     utils_test.ping(ip,
                     interface=ifname,
                     packetsize=max_icmp_pkt_size,
                     flood=True,
                     timeout=float(flood_time))
Esempio n. 3
0
    def ping(session, nic, dst_ip, strick_check, flood_minutes):
        d_packet_size = [1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507]
        packet_size = params.get("packet_size", "").split() or d_packet_size
        for size in packet_size:
            error.context("Ping with packet size %s" % size, logging.info)
            status, output = utils_test.ping(dst_ip, 10, interface=nic, packetsize=size, timeout=30, session=session)
            if strict_check:
                ratio = utils_test.get_loss_ratio(output)
                if ratio != 0:
                    raise error.TestFail("Loss ratio is %s for packet size" " %s" % (ratio, size))
            else:
                if status != 0:
                    raise error.TestFail("Ping returns non-zero value %s" % output)

        error.context("Flood ping test", logging.info)
        utils_test.ping(
            dst_ip, None, interface=nic, flood=True, output_func=None, timeout=flood_minutes * 60, session=session
        )
        error.context("Final ping test", logging.info)
        counts = params.get("ping_counts", 100)
        status, output = utils_test.ping(dst_ip, counts, interface=nic, timeout=float(counts) * 1.5, session=session)
        if strick_check == "yes":
            ratio = utils_test.get_loss_ratio(output)
            if ratio != 0:
                raise error.TestFail("Packet loss ratio is %s after flood" % ratio)
        else:
            if status != 0:
                raise error.TestFail("Ping returns non-zero value %s" % output)
Esempio n. 4
0
    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)
        error.context("Disable guest link by set_link", logging.info)
        vm.set_link(linkid, up=False)
        error.context("Ping guest from host", logging.info)
        s, o = utils_test.ping(ip, count=10, timeout=20)
        if utils_test.get_loss_ratio(o) != 100:
            raise error.TestFail("Still can ping the %s after down %s" %
                                 (ip, linkid))

        error.context("Re-enable guest link by set_link", logging.info)
        vm.set_link(linkid, up=True)
        # Waiting for guest network up again.
        session = vm.wait_for_login(timeout=timeout)
        session.close()
        error.context("Ping guest from host", logging.info)
        s, o = utils_test.ping(ip, count=10, timeout=20)
        # we use 100% here as the notification of link status changed may be
        # delayed in guest driver
        if utils_test.get_loss_ratio(o) == 100:
            raise error.TestFail("Packet loss during ping %s after up %s" %
                                 (ip, linkid))
Esempio n. 5
0
def ping(test, os_type, match_error, dest, count, session, same_vlan):
    """
    In 'session' ping 'dest'.
    If the two guests are in the same vlan, loss ratio should be 0%.
    Otherwise, loss ratio should be 100%.

    :param test: QEMU test object
    :param dest: dest ip address
    :param count: ping count
    :param session: in which guest to do ping test
    :param same_vlan: whether the two guests are in the same vlan
    """
    if os_type == "linux":
        status, output = utils_test.ping(dest,
                                         count,
                                         timeout=int(count) * 1.50,
                                         session=session)
        loss_ratio = utils_test.get_loss_ratio(output)
        ping_result_check(test, loss_ratio, same_vlan)
        logging.debug("%s" % output)
    elif os_type == "windows":  # TODO, not supported by now
        status, output = utils_test.ping(dest,
                                         count,
                                         timeout=60,
                                         session=session)
        if match_error in str(output):
            ratio = 100
        else:
            loss_ratio = utils_test.get_loss_ratio(output)
        ping_result_check(test, loss_ratio, same_vlan)
Esempio n. 6
0
def ping(test, os_type, match_error, dest, count, session, same_vlan):
    """
    In 'session' ping 'dest'.
    If the two guests are in the same vlan, loss ratio should be 0%.
    Otherwise, loss ratio should be 100%.

    :param test: QEMU test object
    :param dest: dest ip address
    :param count: ping count
    :param session: in which guest to do ping test
    :param same_vlan: whether the two guests are in the same vlan
    """
    if os_type == "linux":
        status, output = utils_test.ping(dest, count,
                                         timeout=int(count) * 1.50,
                                         session=session)
        loss_ratio = utils_test.get_loss_ratio(output)
        ping_result_check(test, loss_ratio, same_vlan)
        logging.debug("%s" % output)
    elif os_type == "windows":  # TODO, not supported by now
        status, output = utils_test.ping(dest, count, timeout=60,
                                         session=session)
        if match_error in str(output):
            ratio = 100
        else:
            loss_ratio = utils_test.get_loss_ratio(output)
        ping_result_check(test, loss_ratio, same_vlan)
Esempio n. 7
0
    def ping(session, nic, dst_ip, strick_check, flood_minutes):
        d_packet_size = [1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096,
                         4192, 8878, 9000, 32767, 65507]
        packet_size = params.get("packet_size", "").split() or d_packet_size
        for size in packet_size:
            error_context.context("Ping with packet size %s" % size,
                                  logging.info)
            status, output = utils_test.ping(dst_ip, 10, interface=nic,
                                             packetsize=size, timeout=30,
                                             session=session)
            if strict_check:
                ratio = utils_test.get_loss_ratio(output)
                if ratio != 0:
                    test.fail("Loss ratio is %s for packet size"
                              " %s" % (ratio, size))
            else:
                if status != 0:
                    test.fail("Ping returns non-zero value %s" % output)

        error_context.context("Flood ping test", logging.info)
        utils_test.ping(dst_ip, None, interface=nic, flood=True,
                        output_func=None, timeout=flood_minutes * 60,
                        session=session)
        error_context.context("Final ping test", logging.info)
        counts = params.get("ping_counts", 100)
        status, output = utils_test.ping(dst_ip, counts, interface=nic,
                                         timeout=float(counts) * 1.5,
                                         session=session)
        if strick_check == "yes":
            ratio = utils_test.get_loss_ratio(output)
            if ratio != 0:
                test.fail("Packet loss ratio is %s after flood" % ratio)
        else:
            if status != 0:
                test.fail("Ping returns non-zero value %s" % output)
Esempio n. 8
0
 def bridge_test(session):
     """
     bridge mode test.
     Check guest can ping remote host
     guest can ping other guest when macvtap nic is up
     guest cannot ping remote host when macvtap nic is up
     """
     ping_s, _ = ping(remote_ip,
                      count=1,
                      interface=eth_name,
                      timeout=5,
                      session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, remote_ip))
     ping_s, _ = ping(vm2_ip,
                      count=1,
                      interface=eth_name,
                      timeout=5,
                      session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, vm2.name))
     try:
         iface_cls.down()
     except error.CmdError, detail:
         raise error.TestNAError(str(detail))
Esempio n. 9
0
 def flood_ping(src, dst):
     # we must use a dedicated session becuase the aexpect
     # does not have the other method to interrupt the process in
     # the guest rather than close the session.
     error.context("Flood ping from %s interface %s to %s" % (vm[src].name, ifname[src], vlan_ip[dst]), logging.info)
     session_flood = vm[src].wait_for_login(timeout=60)
     utils_test.ping(vlan_ip[dst], flood=True, interface=ifname[src], session=session_flood, timeout=10)
     session_flood.close()
Esempio n. 10
0
 def flood_ping(src, dst):
     # we must use a dedicated session becuase the aexpect
     # does not have the other method to interrupt the process in
     # the guest rather than close the session.
     session_flood = vm[src].wait_for_login(timeout=60)
     utils_test.ping(vlan_ip[dst], flood=True,
                        interface=ifname[src],
                        session=session_flood, timeout=10)
     session_flood.close()
Esempio n. 11
0
        def size_increase_ping(step=random.randrange(90, 110)):
            logging.info("Size increase ping")
            for size in range(0, max_icmp_pkt_size + 1, step):
                logging.info("Ping %s with size %s", ip, size)
                s, o = utils_test.ping(ip, 1, interface=ifname, packetsize=size, hint="do", timeout=1)
                if s != 0:
                    s, o = utils_test.ping(
                        ip, 10, interface=ifname, packetsize=size, adaptive=True, hint="do", timeout=20
                    )

                    if utils_test.get_loss_ratio(o) > int(params.get("fail_ratio", 50)):
                        raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size)
Esempio n. 12
0
        def size_increase_ping(step=random.randrange(90, 110)):
            logging.info("Size increase ping")
            for size in range(0, max_icmp_pkt_size + 1, step):
                logging.info("Ping %s with size %s", guest_ip, size)
                status, output = utils_test.ping(guest_ip, 1, packetsize=size, hint="do", timeout=1)
                if status != 0:
                    status, output = utils_test.ping(
                        guest_ip, 10, packetsize=size, adaptive=True, hint="do", timeout=20
                    )

                    fail_ratio = int(params.get("fail_ratio", 50))
                    if utils_test.get_loss_ratio(output) > fail_ratio:
                        raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size)
Esempio n. 13
0
 def flood_ping(src, dst):
     # we must use a dedicated session because the aexpect
     # does not have the other method to interrupt the process in
     # the guest rather than close the session.
     error.context(
         "Flood ping from %s interface %s to %s" %
         (vm[src].name, ifname[src], vlan_ip[dst]), logging.info)
     session_flood = vm[src].wait_for_login(timeout=60)
     utils_test.ping(vlan_ip[dst],
                     flood=True,
                     interface=ifname[src],
                     session=session_flood,
                     timeout=10)
     session_flood.close()
Esempio n. 14
0
 def ping_hotplug_nic(ip, mac, session, is_linux_guest):
     status, output = utils_test.ping(ip, 10, timeout=30)
     if status != 0:
         if not is_linux_guest:
             return status, output
         ifname = utils_net.get_linux_ifname(session, mac)
         add_route_cmd = "route add %s dev %s" % (ip, ifname)
         del_route_cmd = "route del %s dev %s" % (ip, ifname)
         logging.warn("Failed to ping %s from host.")
         logging.info("Add route and try again")
         session.cmd_output_safe(add_route_cmd)
         status, output = utils_test.ping(hotnic_ip, 10, timeout=30)
         logging.info("Del the route.")
         status, output = session.cmd_output_safe(del_route_cmd)
     return status, output
Esempio n. 15
0
def run(test, params, env):
    """
    General stress test for linux:
       1). Install stress if need
       2). Start stress process
       3). If no stress_time defined, keep stress until test_timeout;
       otherwise execute below steps after sleeping stress_time long
       4). Stop stress process
       5). Uninstall stress
       6). Verify guest kernel crash

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """

    stress_duration = int(params.get("stress_duration", "0"))
    # NOTE: stress_duration = 0 ONLY for some legacy test cases using
    # autotest stress.control as their sub test.
    # Please DO define stress_duration to make sure the clean action
    # being performed, if your case can not be controlled by time,
    # use utils_test.VMStress() directly
    stress_type = params.get("stress_type", "stress")
    vms = env.get_all_vms()
    up_time = {}
    error = False
    stress_server = {}

    for vm in vms:
        try:
            up_time[vm.name] = vm.uptime()
            stress_server[vm.name] = utils_test.VMStress(vm, stress_type, params)
            stress_server[vm.name].load_stress_tool()
        except exceptions.TestError as err_msg:
            error = True
            logging.error(err_msg)

    if stress_duration:
        time.sleep(stress_duration)

    for vm in vms:
        try:
            s_ping, o_ping = utils_test.ping(vm.get_address(), count=5, timeout=20)
            if s_ping != 0:
                error = True
                logging.error("%s seem to have gone out of network", vm.name)
                continue
            uptime = vm.uptime()
            if up_time[vm.name] > uptime:
                error = True
                logging.error("%s seem to have rebooted during the stress run", vm.name)
            stress_server[vm.name].unload_stress()
            stress_server[vm.name].clean()
            vm.verify_dmesg()
        except exceptions.TestError as err_msg:
            error = True
            logging.error(err_msg)

    if error:
        test.fail("Run failed: see error messages above")
Esempio n. 16
0
def check_vdpa_network(vm_session,
                       vm_iface,
                       br_name,
                       ping_dest="100.100.100.100",
                       config_vdpa=True):
    """
    Check vdpa network connection

    :param vm_session: An session to VM
    :param vm_iface: VM's interface
    :param br_name: Bridge name
    :param ping_dest: The ip address to ping
    :config_vdpa: Whether to config vDPA connection
    """
    if config_vdpa:
        config_vdpa_conn(vm_session, vm_iface, br_name)

    if not utils_misc.wait_for(
            lambda: not utils_test.ping(ping_dest,
                                        count=3,
                                        timeout=5,
                                        output_func=logging.debug,
                                        session=vm_session)[0],
            first=5,
            timeout=30):
        raise exceptions.TestFail("Failed to ping %s." % ping_dest)
Esempio n. 17
0
def run(test, params, env):
    """
    Boot guest with iommu_platform, then do ping test

    1) Boot a VM with iommu_platform=on
    2) add intel_iommu=on in guest kernel line
    3) reboot guest
    4) do ping test

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

    if utils_misc.get_cpu_vendor(verbose=False) != 'GenuineIntel':
        test.cancel("This case only support Intel platform")

    login_timeout = int(params.get("login_timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=login_timeout)
    ping_count = int(params.get("ping_count", 10))
    guest_ip = vm.get_address()

    try:
        status, output = utils_test.ping(guest_ip, ping_count,
                                         timeout=float(ping_count) * 1.5)
        if status != 0:
            test.fail("Ping returns non-zero value %s" % output)
        package_lost = utils_test.get_loss_ratio(output)
        if package_lost != 0:
            test.fail("%s packeage lost when ping guest ip %s " %
                      (package_lost, guest_ip))
    finally:
        session.close()
Esempio n. 18
0
 def is_mtu_ok():
     status, _ = utils_test.ping(guest_ip,
                                 1,
                                 packetsize=max_icmp_pkt_size,
                                 hint="do",
                                 timeout=2)
     return status == 0
Esempio n. 19
0
    def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
        """
        Check whether guest network is connective by ping
        """
        if link_up:
            vm.wait_for_login()
            guest_ip = vm.get_address()
        if change_queues:
            env["run_change_queues"] = False
            bg_thread = utils.InterruptedThread(change_queues_number_repeatly,
                                                (guest_ifname, ))
            bg_thread.start()

            utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
                                "wait queues change start")

        _, output = utils_test.ping(guest_ip, count=10, timeout=20)
        if not link_up and utils_test.get_loss_ratio(output) != 100:
            err_msg = "guest network still connecting after down the link"
            raise error.TestFail(err_msg)
        elif link_up and utils_test.get_loss_ratio(output) == 100:
            err_msg = "All packets lost during ping guest ip after link up"
            raise error.TestFail(err_msg)
        else:
            logging.info("Guest network connecting is exactly as expected")

        if change_queues:
            env["run_change_queues"] = False
            bg_thread.join()
Esempio n. 20
0
 def private_test(session):
     """
     private mode test.
     Check guest cannot ping other guest, but can pin remote host
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, remote_ip))
     ping_s, _ = ping(vm2_ip, count=1, timeout=5, session=session)
     if not ping_s:
         raise error.TestFail("%s ping %s succeed, but expect failed."
                              % (vm1.name, vm2.name))
     try:
         iface_cls.down()
     except error.CmdError, detail:
         raise error.TestNAError(str(detail))
Esempio n. 21
0
    def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
        """
        Check whether guest network is connective by ping
        """
        if link_up:
            vm.wait_for_login()
            guest_ip = vm.get_address()
        if change_queues:
            env["run_change_queues"] = False
            bg_thread = utils.InterruptedThread(change_queues_number_repeatly,
                                                (guest_ifname,))
            bg_thread.start()

            utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
                                "wait queues change start")

        _, output = utils_test.ping(guest_ip, count=10, timeout=20)
        if not link_up and utils_test.get_loss_ratio(output) != 100:
            err_msg = "guest network still connecting after down the link"
            raise error.TestFail(err_msg)
        elif link_up and utils_test.get_loss_ratio(output) == 100:
            err_msg = "All packets lost during ping guest ip after link up"
            raise error.TestFail(err_msg)
        else:
            logging.info("Guest network connecting is exactly as expected")

        if change_queues:
            env["run_change_queues"] = False
            bg_thread.join()
Esempio n. 22
0
    def do_test(test, params, env):
        """
        Do ping test, check msi support and do file transfer

        :param session: guest session
        :param vm: guest vm
        """
        login_timeout = int(params.get("login_timeout", 360))
        env_process.preprocess(test, params, env)
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        session = vm.wait_for_login(timeout=login_timeout)
        guest_ip = vm.get_address()
        ping_count = int(params.get("ping_count", 0))
        if not ping_count == 0:
            status, output = utils_test.ping(guest_ip,
                                             ping_count,
                                             timeout=float(ping_count) * 1.5)
            if status != 0:
                test.fail("Ping returns non-zero value %s" % output)

            package_lost = utils_test.get_loss_ratio(output)
            if package_lost != 0:
                test.fail("%s packeage lost when ping server" % package_lost)

        check_msi_support(session)

        if params.get("do_file_transfer", "no") == "yes":
            utils_test.run_file_transfer(test, params, env)

        session.close()
        vm.destroy(gracefully=True)
Esempio n. 23
0
    def ping_test(session, dst, drop_flow=False):
        """
        Ping test, check icmp
        """
        ping_status, ping_output = utils_test.ping(dest=dst,
                                                   count=10,
                                                   timeout=20,
                                                   session=session)
        # when drop_flow is true, ping should failed(return not zero)
        # drop_flow is false, ping should success
        packets_lost = 100
        if ping_status and not drop_flow:
            raise error.TestError("Ping should success when not drop_icmp")
        elif not ping_status:
            packets_lost = utils_test.get_loss_ratio(ping_output)
            if drop_flow and packets_lost != 100:
                raise error.TestError("When drop_icmp, ping shouldn't works")
            if not drop_flow and packets_lost == 100:
                raise error.TestError("When not drop_icmp, ping should works")

        info_msg = "Correct, icmp flow %s dropped, ping '%s', "
        info_msg += "packets lost rate is: '%s'"
        logging.info(info_msg %
                     ((drop_flow and "was" or "was not"),
                      (ping_status and "failed" or "success"), packets_lost))
Esempio n. 24
0
    def start_test(param_name, param_value):
        """
        Start test. First set netkvm driver parameter 'param_name'
        to value 'param_value'. Then read the current and compare
        to 'param_value' to check identity. Finally conduct a ping
        test to check the nic is avaliable.

        param param_name: the netkvm driver parameter to modify
        param param_value: the value to set to
        """
        error_context.context("Start set %s to %s" % (param_name, param_value),
                              logging.info)
        utils_net.set_netkvm_param_value(vm, param_name, param_value)

        logging.info("Check value after setting %s", param_name)
        cur_value = utils_net.get_netkvm_param_value(vm, param_name)
        if cur_value != param_value:
            err_msg = "Current value: %s is not equal to target value: %s"
            err_msg = err_msg % (cur_value, param_value)
            test.fail(err_msg)

        error_context.context("Start ping test", logging.info)
        guest_ip = vm.get_address()
        status, output = utils_test.ping(guest_ip, 10, timeout=15)
        if status:
            test.fail("Ping returns non-zero value %s" % output)
        package_lost = utils_test.get_loss_ratio(output)
        if package_lost != 0:
            test.fail("Ping test got %s package lost" % package_lost)
Esempio n. 25
0
    def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
        """
        Check whether guest network is connective by ping
        """
        if change_queues:
            env["run_change_queues"] = False
            bg_thread = utils_misc.InterruptedThread(
                change_queues_number_repeatly, (guest_ifname, ))
            bg_thread.start()

            utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
                                "wait queues change start")
        time.sleep(0.5)
        output = utils_test.ping(guest_ip,
                                 10,
                                 interface=host_interface,
                                 timeout=20,
                                 session=None)[1]
        if not link_up and utils_test.get_loss_ratio(output) < 80:
            err_msg = "guest network still connecting after down the link"
            test.fail(err_msg)
        elif link_up and utils_test.get_loss_ratio(output) > 20:
            err_msg = "All packets lost during ping guest ip after link up"
            test.fail(err_msg)

        if change_queues:
            env["run_change_queues"] = False
            bg_thread.join()
Esempio n. 26
0
 def private_test(session):
     """
     private mode test.
     Check guest cannot ping other guest, but can pin remote host
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, remote_ip))
     ping_s, _ = ping(vm2_ip, count=1, timeout=5, session=session)
     if not ping_s:
         raise error.TestFail("%s ping %s succeed, but expect failed." %
                              (vm1.name, vm2.name))
     try:
         iface_cls.down()
     except error.CmdError, detail:
         raise error.TestNAError(str(detail))
Esempio n. 27
0
    def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
        """
        Check whether guest network is connective by ping
        """
        if change_queues:
            env["run_change_queues"] = False
            bg_thread = utils_misc.InterruptedThread(
                change_queues_number_repeatly, (guest_ifname,))
            bg_thread.start()

            utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
                                "wait queues change start")
        time.sleep(0.5)
        output = utils_test.ping(guest_ip, 10, interface=host_interface,
                                 timeout=20, session=None)[1]
        if not link_up and utils_test.get_loss_ratio(output) < 80:
            err_msg = "guest network still connecting after down the link"
            test.fail(err_msg)
        elif link_up and utils_test.get_loss_ratio(output) > 20:
            err_msg = "All packets lost during ping guest ip after link up"
            test.fail(err_msg)

        if change_queues:
            env["run_change_queues"] = False
            bg_thread.join()
Esempio n. 28
0
    def check_vm_network_accessed(vm_session,
                                  expected_iface_no=3,
                                  ping_dest="8.8.8.8",
                                  timeout=30):
        """
        Test VM's network by checking ifaces' number and the accessibility

        :param vm_session: The session object to the guest
        :param expected_iface_no: The expected number of ifaces
        :param ping_dest: The destination to be ping
        :param timeout: The timeout of the checking.
        :raise: test.fail when ifaces' number is incorrect or ping fails
        """
        if not utils_misc.wait_for(
                lambda: check_vm_iface_num(vm_session, expected_iface_no),
                first=3,
                timeout=timeout):
            test.fail("%d interfaces should be found on the vm." %
                      expected_iface_no)
        if not utils_misc.wait_for(
                lambda: not utils_test.ping(ping_dest,
                                            count=3,
                                            timeout=5,
                                            output_func=logging.debug,
                                            session=vm_session)[0],
                first=5,
                timeout=timeout):
            test.fail("Failed to ping %s." % ping_dest)
Esempio n. 29
0
def run(test, params, env):
    """
    Boot guest with iommu_platform, then do ping test

    1) Boot a VM with iommu_platform=on
    2) add intel_iommu=on in guest kernel line
    3) reboot guest
    4) do ping test

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

    if cpu.get_vendor() != 'intel':
        test.cancel("This case only support Intel platform")

    login_timeout = int(params.get("login_timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=login_timeout)
    ping_count = int(params.get("ping_count", 10))
    guest_ip = vm.get_address()

    try:
        status, output = utils_test.ping(guest_ip, ping_count,
                                         timeout=float(ping_count) * 1.5)
        if status != 0:
            test.fail("Ping returns non-zero value %s" % output)
        package_lost = utils_test.get_loss_ratio(output)
        if package_lost != 0:
            test.fail("%s packeage lost when ping guest ip %s " %
                      (package_lost, guest_ip))
    finally:
        session.close()
Esempio n. 30
0
        def size_increase_ping(step=random.randrange(90, 110)):
            logging.info("Size increase ping")
            for size in range(0, max_icmp_pkt_size + 1, step):
                logging.info("Ping %s with size %s", ip, size)
                s, o = utils_test.ping(ip, 1, interface=ifname,
                                           packetsize=size,
                                           hint="do", timeout=1)
                if s != 0:
                    s, o = utils_test.ping(ip, 10, interface=ifname,
                                               packetsize=size,
                                               adaptive=True, hint="do",
                                               timeout=20)

                    if utils_test.get_loss_ratio(o) > int(params.get(
                                                      "fail_ratio", 50)):
                        raise error.TestFail("Ping loss ratio is greater "
                                             "than 50% for size %s" % size)
Esempio n. 31
0
 def ping_test(dest_ip, ping_time, lost_raito, session=None):
     status, output = utils_test.ping(dest=dest_ip, timeout=ping_time,
                                      session=session)
     packets_lost = utils_test.get_loss_ratio(output)
     if packets_lost > lost_raito:
         err = " %s%% packages lost during ping. " % packets_lost
         err += "Ping command log:\n %s" % "\n".join(output.splitlines()[-3:])
         test.fail(err)
Esempio n. 32
0
 def passthrough_test(session):
     """
     passthrough mode test.
     Check guest can ping remote host.
     When guest is running, local host cannot ping remote host,
     When guest is poweroff, local host can ping remote host,
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         test.fail("%s ping %s failed." % (vm1.name, remote_ip))
     ping_s, _ = ping(remote_ip, count=1, timeout=5)
     if not ping_s:
         test.fail("host ping %s succeed, but expect fail." % remote_ip)
     vm1.destroy(gracefully=False)
     ping_s, _ = ping(remote_ip, count=1, timeout=5)
     if ping_s:
         test.fail("host ping %s failed." % remote_ip)
Esempio n. 33
0
 def ping_test(dest_ip, ping_time, lost_raito, session=None):
     status, output = utils_test.ping(dest=dest_ip, timeout=ping_time,
                                      session=session)
     packets_lost = utils_test.get_loss_ratio(output)
     if packets_lost > lost_raito:
         err = " %s%% packages lost during ping. " % packets_lost
         err += "Ping command log:\n %s" % "\n".join(output.splitlines()[-3:])
         raise error.TestFail(err)
Esempio n. 34
0
 def vepa_test(session):
     """
     vepa mode test.
     Check guest can ping remote host
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, remote_ip))
Esempio n. 35
0
 def vepa_test(session):
     """
     vepa mode test.
     Check guest can ping remote host
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed." % (vm1.name, remote_ip))
Esempio n. 36
0
 def large_frame_ping(count=100):
     logging.info("Large frame ping")
     _, output = utils_test.ping(guest_ip, count,
                                 packetsize=max_icmp_pkt_size,
                                 timeout=float(count) * 2)
     ratio = utils_test.get_loss_ratio(output)
     if ratio != 0:
         test.fail("Loss ratio of large frame ping is %s" % ratio)
Esempio n. 37
0
 def is_mtu_ok():
     s, _ = utils_test.ping(ip,
                            1,
                            interface=ifname,
                            packetsize=max_icmp_pkt_size,
                            hint="do",
                            timeout=2)
     return s == 0
Esempio n. 38
0
def launch_client(sessions, servers, server_ctl, clients, l, nf_args, port,
                  params):
    """
    Launch netperf clients
    """
    # Start netserver
    error.context("Start Netserver on guest", logging.info)
    remote_dir = params.get("remote_dir", "/var/tmp")
    client_path = os.path.join(remote_dir, "netperf-2.6.0/src/netperf")
    server_path = os.path.join(remote_dir, "netperf-2.6.0/src/netserver")

    if params.get("os_type") == "windows":
        winutils_vol = utils_misc.get_winutils_vol(server_ctl)
        client_path = "%s:\\netperf" % winutils_vol
        netserv_start_cmd = params.get("netserv_start_cmd") % winutils_vol

        logging.info("Netserver start cmd is '%s'" % netserv_start_cmd)
        if "NETSERVER.EXE" not in server_ctl.cmd_output("tasklist"):
            server_ctl.cmd_output(netserv_start_cmd)
            o_tasklist = server_ctl.cmd_output("tasklist")
            if "NETSERVER.EXE" not in o_tasklist.upper():
                msg = "Can not start netserver in Windows guest"
                raise error.TestError(msg)

    else:
        logging.info("Netserver start cmd is '%s'" % server_path)
        ssh_cmd(server_ctl, "pidof netserver || %s" % server_path)
    logging.info("Netserver start successfully")

    # start netperf
    error.context("Start netperf client threads", logging.info)
    client_threads = []

    for client in clients:
        test_timeout = len(clients) * l
        server = servers[clients.index(client) % len(servers)]
        netperf_cmd = "%s -H %s -l %s %s" % (client_path, server, int(l),
                                             nf_args)
        client_threads.append([ssh_cmd, (client, netperf_cmd, test_timeout)])

    result_info = utils_misc.parallel(client_threads)

    counts = 5
    for server in servers:
        if not re.findall("TEST.*to %s" % server, str(result_info)):
            raise error.TestError("Nerperf stress on nic %s failed" % server)
        logging.info("Network stress on %s successfully" % server)

        status, output = utils_test.ping(server,
                                         counts,
                                         timeout=float(counts) * 1.5)
        if status != 0:
            raise error.TestFail("Ping returns non-zero value %s" % output)

        package_lost = utils_test.get_loss_ratio(output)
        if package_lost != 0:
            raise error.TestFail("%s packeage lost when ping server ip %s " %
                                 (package_lost, server))
Esempio n. 39
0
def run(test, params, env):
    """
    Test ntpd service, in default setting the execution
    will take longer than 24 hours.

    1.Configure ntpd service in server
    2.Set the date and configure ntpd service in host
    3.Set the date and configure ntpd service in guest
    4.Check ntpd service valid in guest
    5.After long time, test ntpd service still works on guest.
    """

    ntp_test = NTPTest(test, params, env)
    ping_s, _ = utils_test.ping(ntp_test.server_ip,
                                count=1,
                                timeout=5,
                                session=ntp_test.session)
    if ping_s:
        ntp_test.close_session()
        test.cancel("Please make sure the guest can ping server!")

    # Start test from here
    try:
        # Server configuration
        try:
            ntp_test.server_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("server config failed. %s" % detail)
        logging.info("waiting for ntp server : %s s", ntp_test.ntpdate_sleep)
        # Host and Guest will use server's ntpd service to set time.
        # here wait for some seconds for server ntpd service valid
        time.sleep(ntp_test.ntpdate_sleep)

        # Host configuration
        try:
            ntp_test.host_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("host config failed.%s" % detail)

        # Guest configuration
        try:
            ntp_test.guest_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("guest config failed.%s" % detail)

        try:
            # Wait 20min for ntpq test
            ntp_test.ntpq_test()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("ntpq test failed.%s" % detail)

        try:
            # Wait 24h for  test
            ntp_test.long_time_test()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("long time test failed.%s" % detail)
    finally:
        ntp_test.close_session()
Esempio n. 40
0
 def large_frame_ping(count=100):
     logging.info("Large frame ping")
     _, o = utils_test.ping(ip, count, interface=ifname,
                                packetsize=max_icmp_pkt_size,
                                timeout=float(count) * 2)
     ratio = utils_test.get_loss_ratio(o)
     if ratio != 0:
         raise error.TestFail("Loss ratio of large frame ping is %s" %
                              ratio)
Esempio n. 41
0
 def verify_mtu():
     logging.info("Verify the path MTU")
     s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=15)
     if s != 0:
         logging.error(o)
         raise error.TestFail("Path MTU is not as expected")
     if utils_test.get_loss_ratio(o) != 0:
         logging.error(o)
         raise error.TestFail("Packet loss ratio during MTU " "verification is not zero")
Esempio n. 42
0
def launch_client(sessions, servers, server_ctl, clients,
                  l, nf_args, port, params):
    """
    Launch netperf clients
    """
    # Start netserver
    error.context("Start Netserver on guest", logging.info)
    remote_dir = params.get("remote_dir", "/var/tmp")
    client_path = os.path.join(remote_dir, "netperf-2.6.0/src/netperf")
    server_path = os.path.join(remote_dir, "netperf-2.6.0/src/netserver")

    if params.get("os_type") == "windows":
        winutils_vol = utils_misc.get_winutils_vol(server_ctl)
        client_path = "%s:\\netperf" % winutils_vol
        netserv_start_cmd = params.get("netserv_start_cmd") % winutils_vol

        logging.info("Netserver start cmd is '%s'" % netserv_start_cmd)
        if "NETSERVER.EXE" not in server_ctl.cmd_output("tasklist"):
            server_ctl.cmd_output(netserv_start_cmd)
            o_tasklist = server_ctl.cmd_output("tasklist")
            if "NETSERVER.EXE" not in o_tasklist.upper():
                msg = "Can not start netserver in Windows guest"
                raise error.TestError(msg)

    else:
        logging.info("Netserver start cmd is '%s'" % server_path)
        ssh_cmd(server_ctl, "pidof netserver || %s" % server_path)
    logging.info("Netserver start successfully")

    # start netperf
    error.context("Start netperf client threads", logging.info)
    client_threads = []

    for client in clients:
        test_timeout = len(clients) * l
        server = servers[clients.index(client) % len(servers)]
        netperf_cmd = "%s -H %s -l %s %s" % (client_path, server,
                                             int(l), nf_args)
        client_threads.append([ssh_cmd, (client, netperf_cmd, test_timeout)])

    result_info = utils_misc.parallel(client_threads)

    counts = 5
    for server in servers:
        if not re.findall("TEST.*to %s" % server, str(result_info)):
            raise error.TestError("Nerperf stress on nic %s failed" % server)
        logging.info("Network stress on %s successfully" % server)

        status, output = utils_test.ping(server, counts,
                                         timeout=float(counts) * 1.5)
        if status != 0:
            raise error.TestFail("Ping returns non-zero value %s" % output)

        package_lost = utils_test.get_loss_ratio(output)
        if package_lost != 0:
            raise error.TestFail("%s packeage lost when ping server ip %s " %
                                 (package_lost, server))
Esempio n. 43
0
 def large_frame_ping(count=100):
     logging.info("Large frame ping")
     _, output = utils_test.ping(guest_ip,
                                 count,
                                 packetsize=max_icmp_pkt_size,
                                 timeout=float(count) * 2)
     ratio = utils_test.get_loss_ratio(output)
     if ratio != 0:
         test.fail("Loss ratio of large frame ping is %s" % ratio)
Esempio n. 44
0
 def large_frame_ping(count=100):
     logging.info("Large frame ping")
     _, o = utils_test.ping(ip, count, interface=ifname,
                                packetsize=max_icmp_pkt_size,
                                timeout=float(count) * 2)
     ratio = utils_test.get_loss_ratio(o)
     if ratio != 0:
         raise error.TestFail("Loss ratio of large frame ping is %s" %
                              ratio)
Esempio n. 45
0
def run(test, params, env):
    """
    Test ntpd service, in default setting the execution
    will take longer than 24 hours.

    1.Configure ntpd service in server
    2.Set the date and configure ntpd service in host
    3.Set the date and configure ntpd service in guest
    4.Check ntpd service valid in guest
    5.After long time, test ntpd service still works on guest.
    """

    ntp_test = NTPTest(test, params, env)
    ping_s, _ = utils_test.ping(ntp_test.server_ip, count=1,
                                timeout=5, session=ntp_test.session)
    if ping_s:
        ntp_test.close_session()
        test.cancel("Please make sure the guest can ping server!")

    # Start test from here
    try:
        # Server configuration
        try:
            ntp_test.server_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("server config failed. %s" % detail)
        logging.info("waiting for ntp server : %s s" % ntp_test.ntpdate_sleep)
        # Host and Guest will use server's ntpd service to set time.
        # here wait for some seconds for server ntpd service valid
        time.sleep(ntp_test.ntpdate_sleep)

        # Host configuration
        try:
            ntp_test.host_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("host config failed.%s" % detail)

        # Guest configuration
        try:
            ntp_test.guest_config()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("guest config failed.%s" % detail)

        try:
            # Wait 20min for ntpq test
            ntp_test.ntpq_test()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("ntpq test failed.%s" % detail)

        try:
            # Wait 24h for  test
            ntp_test.long_time_test()
        except (aexpect.ShellError, remote.LoginTimeoutError) as detail:
            test.fail("long time test failed.%s" % detail)
    finally:
        ntp_test.close_session()
Esempio n. 46
0
 def bridge_test(session):
     """
     bridge mode test.
     Check guest can ping remote host
     guest can ping other guest when macvtap nic is up
     guest cannot ping remote host when macvtap nic is up
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed."
                              % (vm1.name, remote_ip))
     ping_s, _ = ping(vm2_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed."
                              % (vm1.name, vm2.name))
     try:
         iface_cls.down()
     except error.CmdError, detail:
         raise error.TestNAError(str(detail))
 def check_vm_network_accessed():
     """
     The operations to the VM need to be done before migration happens
     """
     # 1. Confirm local VM can be accessed through network.
     logging.info("Check local VM network connectivity before migrating")
     s_ping, o_ping = utils_test.ping(vm.get_address(), count=10, timeout=20)
     logging.info(o_ping)
     if s_ping != 0:
         test.error("%s did not respond after %d sec." % (vm.name, 20))
Esempio n. 48
0
 def ping_test():
     """
     Basic ping test for interface
     """
     session = vm.wait_for_login()
     dest = params.get('ping_dest', 'www.baidu.com')
     status, output = utils_test.ping(dest, 10, session=session, timeout=20)
     session.close()
     if status != 0:
         test.fail("Ping failed, status: %s,"
                   " output: %s" % (status, output))
Esempio n. 49
0
 def passthrough_test(session):
     """
     passthrough mode test.
     Check guest can ping remote host.
     When guest is running, local host cannot ping remote host,
     When guest is poweroff, local host can ping remote host,
     """
     ping_s, _ = ping(remote_ip, count=1, timeout=5, session=session)
     if ping_s:
         raise error.TestFail("%s ping %s failed."
                              % (vm1.name, remote_ip))
     ping_s, _ = ping(remote_ip, count=1, timeout=5)
     if not ping_s:
         raise error.TestFail("host ping %s succeed, but expect fail."
                              % remote_ip)
     vm1.destroy(gracefully=False)
     ping_s, _ = ping(remote_ip, count=1, timeout=5)
     if ping_s:
         raise error.TestFail("host ping %s failed."
                              % remote_ip)
Esempio n. 50
0
        def size_increase_ping(step=random.randrange(90, 110)):
            logging.info("Size increase ping")
            for size in range(0, max_icmp_pkt_size + 1, step):
                logging.info("Ping %s with size %s", guest_ip, size)
                status, output = utils_test.ping(guest_ip,
                                                 1,
                                                 packetsize=size,
                                                 hint="do",
                                                 timeout=1)
                if status != 0:
                    status, output = utils_test.ping(guest_ip,
                                                     10,
                                                     packetsize=size,
                                                     adaptive=True,
                                                     hint="do",
                                                     timeout=20)

                    fail_ratio = int(params.get("fail_ratio", 50))
                    if utils_test.get_loss_ratio(output) > fail_ratio:
                        test.fail("Ping loss ratio is greater "
                                  "than 50% for size %s" % size)
Esempio n. 51
0
    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.set_link(linkid, up=False)
        _, o = utils_test.ping(ip, count=10, timeout=20)
        if utils_test.get_loss_ratio(o) != 100:
            raise error.TestFail("Still can ping the %s after down %s" %
                                 (ip, linkid))

        vm.set_link(linkid, up=True)
        _, o = utils_test.ping(ip, count=10, timeout=20)
        # we use 100% here as the notification of link status changed may be
        # delayed in guest driver
        if utils_test.get_loss_ratio(o) == 100:
            raise error.TestFail("Packet loss during ping %s after up %s" %
                                 (ip, linkid))
Esempio n. 52
0
 def verify_mtu():
     logging.info("Verify the path MTU")
     status, output = utils_test.ping(guest_ip, 10,
                                      packetsize=max_icmp_pkt_size,
                                      hint="do", timeout=15)
     if status != 0:
         logging.error(output)
         test.fail("Path MTU is not as expected")
     if utils_test.get_loss_ratio(output) != 0:
         logging.error(output)
         test.fail("Packet loss ratio during MTU "
                   "verification is not zero")
Esempio n. 53
0
 def ping_vlan(vm, dest, vlan_if, session):
     """
     Test ping between vlans, from guest to host/guest.
     :params vm: VM object
     :params dest: Dest ip to ping.
     :params vlan_if: Vlan interface.
     :params session: VM session.
     """
     error_context.context("Test ping from '%s' to '%s' on guest '%s'" %
                           (vlan_if, dest, vm.name))
     status, output = utils_test.ping(dest=dest, count=10,
                                      interface=vlan_if,
                                      session=session,
                                      timeout=30)
     if status:
         raise NetPingError(vlan_if, dest, output)
Esempio n. 54
0
 def guest_netwok_connecting_check(guest_ip, link_up):
     """
     Check whether guest network is connective by ping
     """
     if link_up:
         vm.wait_for_login()
         guest_ip = vm.get_address()
     s, o = utils_test.ping(guest_ip, count=10, timeout=20)
     if not link_up and utils_test.get_loss_ratio(o) != 100:
         err_msg = "guest network still connecting after down the link"
         raise error.TestFail(err_msg)
     elif link_up and utils_test.get_loss_ratio(o) == 100:
         err_msg = "All packets lost during ping guest ip after link up"
         raise error.TestFail(err_msg)
     else:
         logging.info("Guest network connecting is exactly as expected")
    def check_vm_network_accessed(session=None):
        """
        The operations to the VM need to be done before or after
        migration happens

        :param session: The session object to the host

        :raise: test.error when ping fails
        """
        # Confirm local/remote VM can be accessed through network.
        logging.info("Check VM network connectivity")
        s_ping, _ = utils_test.ping(vm.get_address(),
                                    count=10,
                                    timeout=20,
                                    output_func=logging.debug,
                                    session=session)
        if s_ping != 0:
            if session:
                session.close()
            test.fail("%s did not respond after %d sec." % (vm.name, 20))
Esempio n. 56
0
    def ping_test(session, dst, drop_flow=False):
        """
        Ping test, check icmp
        """
        ping_status, ping_output = utils_test.ping(dest=dst, count=10, timeout=20, session=session)
        # when drop_flow is true, ping should failed(return not zero)
        # drop_flow is false, ping should success
        packets_lost = 100
        if ping_status and not drop_flow:
            raise error.TestError("Ping should success when not drop_icmp")
        elif not ping_status:
            packets_lost = utils_test.get_loss_ratio(ping_output)
            if drop_flow and packets_lost != 100:
                raise error.TestError("When drop_icmp, ping shouldn't works")
            if not drop_flow and packets_lost == 100:
                raise error.TestError("When not drop_icmp, ping should works")

        info_msg = "Correct, icmp flow %s dropped, ping '%s', "
        info_msg += "packets lost rate is: '%s'"
        logging.info(
            info_msg % ((drop_flow and "was" or "was not"), (ping_status and "failed" or "success"), packets_lost)
        )
        def start_check_vm(vm):
            try:
                vm.start()
            except virt_vm.VMStartError as detail:
                if status_error:
                    logging.debug("Expected failure:%s", detail)
                    return None, None
                else:
                    raise
            vm.wait_for_login()

            # Confirm VM can be accessed through network.
            # And this ip will be used on remote after migration
            vm_ip = vm.get_address()
            vm_pwd = params.get("password")
            s_ping, o_ping = utils_test.ping(vm_ip, count=2, timeout=60)
            logging.info(o_ping)
            if s_ping != 0:
                test.fail("%s did not respond after several "
                          "seconds with attaching new devices."
                          % vm.name)
            return vm_ip, vm_pwd
Esempio n. 58
0
 def kernelcompile(session, vm_name):
     vm = env.get_vm(vm_name)
     ip = vm.get_address()
     path = params.get("download_url")
     logging.info("kernel path = %s" % path)
     get_kernel_cmd = "wget %s" % path
     try:
         status, output = session.cmd_status_output(get_kernel_cmd,
                                                    timeout=240)
         if status != 0:
             logging.error(output)
             raise error.TestFail("Fail to download the kernel"
                                  " in %s" % vm_name)
         else:
             logging.info("Completed download the kernel src"
                          " in %s" %vm_name)
         test_cmd = params.get("test_cmd")
         status, output = session.cmd_status_output(test_cmd, timeout=1200)
         if status != 0:
             logging.error(output)
     finally:
         status, _ = utils_test.ping(ip, count=10, timeout=30)
         if status != 0:
             raise error.TestFail("vm no response, pls check serial log")
def run(test, params, env):
    """
    KVM migration test:
    1) Get a live VM and clone it.
    2) Verify that the source VM supports migration. If it does, proceed with
       the test.
    3) Hotplug a nic.
    4) Disable the primary link of guest.
    5) Check if new interface gets ip address.
    6) Ping guest's new ip from host.
    7) Re-enabling the primary link.
    8) Send a migration command to the source VM and wait until it's finished.
    9) Disable the primary link again.
    10) Ping guest's new ip from host.
    11) Re-enabling the primary link.

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

    def set_link(nic_name, up=False):
        for nic in vm.virtnet:
            if nic.nic_name != nic_name:
                vm.set_link(nic.device_id, up=up)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_serial_login(timeout=timeout)

    guest_is_not_windows = (params.get("os_type") != 'windows')
    run_dhclient = params.get("run_dhclient", "no")
    mig_timeout = float(params.get("mig_timeout", "3600"))
    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    mig_protocol = params.get("migration_protocol", "tcp")
    mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2
    pci_model = params.get("pci_model")

    # Modprobe the module if specified in config file
    module = params.get("modprobe_module")
    if guest_is_not_windows and module:
        session.cmd_output("modprobe %s" % module)
    if session:
        session.close()

    error.context("Add network devices through monitor cmd", logging.info)
    nic_name = 'hotadded'
    enable_msix_vectors = params.get("enable_msix_vectors")
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype,
                              queues=params.get('queues'),
                              enable_msix_vectors=enable_msix_vectors)
    nic_mac = nic_info['mac']
    vm.params['nics'] += " %s" % nic_name
    vm.params['nic_model_%s' % nic_name] = nic_info['nic_model']

    # Only run dhclient if explicitly set and guest is not running Windows.
    # Most modern Linux guests run NetworkManager, and thus do not need this.
    if run_dhclient == "yes" and guest_is_not_windows:
        session_serial = vm.wait_for_serial_login(timeout=timeout)
        ifname = utils_net.get_linux_ifname(session, nic_mac)
        utils_net.restart_guest_network(session_serial, ifname)
        # Guest need to take quite a long time to set the ip addr, sleep a
        # while to wait for guest done.
        time.sleep(60)

    error.context("Disable the primary link of guest", logging.info)
    set_link(nic_name, up=False)

    error.context("Check if new interface gets ip address", logging.info)
    try:
        ip = vm.wait_for_get_address(nic_name)
    except virt_vm.VMIPAddressMissingError:
        raise error.TestFail("Could not get or verify ip address of nic")
    logging.info("Got the ip address of new nic: %s", ip)

    error.context("Ping guest's new ip from host", logging.info)
    s, o = utils_test.ping(ip, 10, timeout=15)
    if s != 0:
        raise error.TestFail("New nic failed ping test with output:\n %s" % o)

    error.context("Re-enabling the primary link", logging.info)
    set_link(nic_name, up=True)

    error.context("Migrate from source VM to Destination VM", logging.info)
    vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay, env=env)

    error.context("Disable the primary link", logging.info)
    set_link(nic_name, up=False)

    error.context("Ping guest's new ip from host", logging.info)
    s, o = utils_test.ping(ip, 10, timeout=15)
    if s != 0:
        raise error.TestFail("New nic failed ping test with output:\n %s" % o)

    error.context("Re-enabling the primary link", logging.info)
    set_link(nic_name, up=True)

    error.context("Reboot guest and verify new nic works", logging.info)
    host_ip = utils_net.get_ip_address_by_interface(netdst)
    session = vm.reboot(session=session)
    status, output = utils_test.ping(dest=host_ip, count=100,
                                     timeout=240, session=session)
    if status != 0:
        raise error.TestFail("Fail to ping host form guest")