Esempio n. 1
0
def run(test, params, env):
    """
    Network stress test with netperf.

    1) Boot up VM(s), setup SSH authorization between host
       and guest(s)/external host
    2) Prepare the test environment in server/client/host
    3) Execute netperf tests, collect and analyze the results

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def mtu_set(mtu):
        """
        Set server/client/host's mtu

        :param mtu: mtu value to be set
        """

        server_mtu_cmd = params.get("server_mtu_cmd")
        client_mtu_cmd = params.get("client_mtu_cmd")
        host_mtu_cmd = params.get("host_mtu_cmd")
        error_context.context("Changing the MTU of guest", logging.info)
        if params.get("os_type") == "linux":
            ethname = utils_net.get_linux_ifname(server_ctl, mac)
            netperf_base.ssh_cmd(server_ctl, server_mtu_cmd % (ethname, mtu))
        elif params.get("os_type") == "windows":
            connection_id = utils_net.get_windows_nic_attribute(
                server_ctl, "macaddress", mac, "netconnectionid")
            netperf_base.ssh_cmd(server_ctl,
                                 server_mtu_cmd % (connection_id, mtu))

        error_context.context("Changing the MTU of client", logging.info)
        netperf_base.ssh_cmd(
            client, client_mtu_cmd % (params.get("client_physical_nic"), mtu))

        netdst = params.get("netdst", "switch")
        host_bridges = utils_net.Bridge()
        br_in_use = host_bridges.list_br()
        if netdst in br_in_use:
            ifaces_in_use = host_bridges.list_iface()
            target_ifaces = list(ifaces_in_use + br_in_use)
        if params.get("netdst_nic1") in process.system_output(
                "ovs-vsctl list-br", ignore_status=True, shell=True).decode():
            ovs_list = "ovs-vsctl list-ports %s" % params["netdst_nic1"]
            ovs_port = process.system_output(ovs_list,
                                             shell=True).decode().splitlines()
            target_ifaces = target_ifaces + \
                params.objects("netdst_nic1") + ovs_port
        if vm.virtnet[0].nettype == "macvtap":
            target_ifaces.extend([vm.virtnet[0].netdst, vm.get_ifname(0)])
        error_context.context("Change all Bridge NICs MTU to %s" % mtu,
                              logging.info)
        for iface in target_ifaces:
            try:
                process.run(host_mtu_cmd % (iface, mtu),
                            ignore_status=False,
                            shell=True)
            except process.CmdError as err:
                if "SIOCSIFMTU" in err.result.stderr.decode():
                    test.cancel("The ethenet device does not support jumbo,"
                                "cancel test")

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

    try:
        vm.wait_for_serial_login(timeout=login_timeout,
                                 restart_network=True).close()
    except virt_vm.VMIPAddressMissingError:
        pass

    if len(params.get("nics", "").split()) > 1:
        session = vm.wait_for_login(nic_index=1, timeout=login_timeout)
    else:
        session = vm.wait_for_login(timeout=login_timeout)

    config_cmds = params.get("config_cmds")
    if config_cmds:
        for config_cmd in config_cmds.split(","):
            cmd = params.get(config_cmd.strip())
            if cmd:
                s, o = session.cmd_status_output(cmd)
                if s:
                    msg = "Config command %s failed. Output: %s" % (cmd, o)
                    test.error(msg)
        if params.get("reboot_after_config", "yes") == "yes":
            session = vm.reboot(session=session, timeout=login_timeout)
            vm.wait_for_serial_login(timeout=login_timeout,
                                     restart_network=True).close()

    mac = vm.get_mac_address(0)
    if params.get("os_type") == "linux":
        ethname = utils_net.get_linux_ifname(session, mac)
    queues = int(params.get("queues", 1))
    if queues > 1:
        if params.get("os_type") == "linux":
            session.cmd_status_output("ethtool -L %s combined %s" %
                                      (ethname, queues))
        else:
            logging.info("FIXME: support to enable MQ for Windows guest!")

    if params.get("server_private_ip") and params.get("os_type") == "linux":
        server_ip = params.get("server_private_ip")
        cmd = "systemctl stop NetworkManager.service"
        cmd += " && ifconfig %s %s up" % (ethname, server_ip)
        session.cmd_output(cmd)
    else:
        server_ip = vm.wait_for_get_address(0, timeout=90)

    if len(params.get("nics", "").split()) > 1:
        server_ctl = vm.wait_for_login(nic_index=1, timeout=login_timeout)
        server_ctl_ip = vm.wait_for_get_address(1, timeout=90)
    else:
        server_ctl = vm.wait_for_login(timeout=login_timeout)
        server_ctl_ip = server_ip

    if params.get("rh_perf_envsetup_script"):
        utils_test.service_setup(vm, session, test.virtdir)
    session.close()

    if (params.get("os_type") == "windows"
            and params.get("use_cygwin") == "yes"):
        cygwin_prompt = params.get("cygwin_prompt", r"\$\s+$")
        cygwin_start = params.get("cygwin_start")
        server_cyg = vm.wait_for_login(timeout=login_timeout)
        server_cyg.set_prompt(cygwin_prompt)
        server_cyg.cmd_output(cygwin_start)
    else:
        server_cyg = None

    logging.debug(
        process.system_output("numactl --hardware",
                              verbose=False,
                              ignore_status=True,
                              shell=True).decode())
    logging.debug(
        process.system_output("numactl --show",
                              verbose=False,
                              ignore_status=True,
                              shell=True).decode())
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = netperf_base.pin_vm_threads(vm, params.get("numa_node"))

    host = params.get("host", "localhost")
    host_ip = host
    if host != "localhost":
        params_host = params.object_params("host")
        host = remote.wait_for_login(params_host.get("shell_client"), host_ip,
                                     params_host.get("shell_port"),
                                     params_host.get("username"),
                                     params_host.get("password"),
                                     params_host.get("shell_prompt"))

    client = params.get("client", "localhost")
    client_ip = client
    clients = []
    # client session 1 for control, session 2 for data communication
    for i in range(2):
        if client in params.get("vms"):
            vm_client = env.get_vm(client)
            tmp = vm_client.wait_for_login(timeout=login_timeout)
            client_ip = vm_client.wait_for_get_address(0, timeout=5)
        elif client != "localhost" and params.get("os_type_client") == "linux":
            client_pub_ip = params.get("client_public_ip")
            tmp = remote.wait_for_login(params.get("shell_client_client"),
                                        client_pub_ip,
                                        params.get("shell_port_client"),
                                        params.get("username_client"),
                                        params.get("password_client"),
                                        params.get("shell_prompt_client"))
            cmd = "ifconfig %s %s up" % (params.get("client_physical_nic"),
                                         client_ip)
            netperf_base.ssh_cmd(tmp, cmd)
        else:
            tmp = "localhost"
        clients.append(tmp)
    client = clients[0]

    vms_list = params["vms"].split()
    if len(vms_list) > 1:
        vm2 = env.get_vm(vms_list[-1])
        vm2.verify_alive()
        session2 = vm2.wait_for_login(timeout=login_timeout)
        if params.get("rh_perf_envsetup_script"):
            utils_test.service_setup(vm2, session2, test.virtdir)
        client = vm2.wait_for_login(timeout=login_timeout)
        client_ip = vm2.get_address()
        session2.close()
        netperf_base.pin_vm_threads(vm2, numa_node)

    error_context.context("Prepare env of server/client/host", logging.info)
    prepare_list = set([server_ctl, client, host])
    tag_dict = {server_ctl: "server", client: "client", host: "host"}
    if client_pub_ip:
        ip_dict = {
            server_ctl: server_ctl_ip,
            client: client_pub_ip,
            host: host_ip
        }
    else:
        ip_dict = {server_ctl: server_ctl_ip, client: client_ip, host: host_ip}
    for i in prepare_list:
        params_tmp = params.object_params(tag_dict[i])
        if params_tmp.get("os_type") == "linux":
            shell_port = int(params_tmp["shell_port"])
            password = params_tmp["password"]
            username = params_tmp["username"]
            netperf_base.env_setup(test, params, i, ip_dict[i], username,
                                   shell_port, password)
        elif params_tmp.get("os_type") == "windows":
            windows_disable_firewall = params.get("windows_disable_firewall")
            netperf_base.ssh_cmd(i, windows_disable_firewall)
    netperf_base.tweak_tuned_profile(params, server_ctl, client, host)
    mtu = int(params.get("mtu", "1500"))
    mtu_set(mtu)

    env.stop_ip_sniffing()

    try:
        error_context.context("Start netperf testing", logging.info)
        start_test(server_ip,
                   server_ctl,
                   host,
                   clients,
                   test.resultsdir,
                   test_duration=int(params.get('l')),
                   sessions_rr=params.get('sessions_rr'),
                   sessions=params.get('sessions'),
                   sizes_rr=params.get('sizes_rr'),
                   sizes=params.get('sizes'),
                   protocols=params.get('protocols'),
                   netserver_port=params.get('netserver_port', "12865"),
                   params=params,
                   server_cyg=server_cyg,
                   test=test)

        if params.get("log_hostinfo_script"):
            src = os.path.join(test.virtdir, params.get("log_hostinfo_script"))
            path = os.path.join(test.resultsdir, "systeminfo")
            process.system_output("bash %s %s &> %s" %
                                  (src, test.resultsdir, path),
                                  shell=True)

        if params.get("log_guestinfo_script") and params.get(
                "log_guestinfo_exec"):
            src = os.path.join(test.virtdir,
                               params.get("log_guestinfo_script"))
            path = os.path.join(test.resultsdir, "systeminfo")
            destpath = params.get("log_guestinfo_path",
                                  "/tmp/log_guestinfo.sh")
            vm.copy_files_to(src, destpath, nic_index=1)
            logexec = params.get("log_guestinfo_exec", "bash")
            output = server_ctl.cmd_output("%s %s" % (logexec, destpath))
            logfile = open(path, "a+")
            logfile.write(output)
            logfile.close()
    finally:
        if mtu != 1500:
            mtu_default = 1500
            error_context.context(
                "Change back server, client and host's mtu to %s" %
                mtu_default)
            mtu_set(mtu_default)
        if params.get("client_physical_nic") and params.get(
                "os_type_client") == "linux":
            cmd = 'ifconfig %s 0.0.0.0 down' % params.get(
                "client_physical_nic")
            netperf_base.ssh_cmd(client, cmd)
Esempio n. 2
0
def run(test, params, env):
    """
    Netperf UDP_STREAM test with netperf.

    1) Boot up VM
    2) Prepare the test environment in server/client/host
    3) Run netserver on guest, run netperf client on remote host
    4) Collect results

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

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

    try:
        vm.wait_for_serial_login(timeout=login_timeout, restart_network=True).close()
    except virt_vm.VMIPAddressMissingError:
        pass

    mac = vm.get_mac_address(0)
    server_ip = vm.wait_for_get_address(0, timeout=90)

    if len(params.get("nics", "").split()) > 1:
        server_ctl = vm.wait_for_login(nic_index=1, timeout=login_timeout)
        server_ctl_ip = vm.wait_for_get_address(1, timeout=90)
    else:
        server_ctl = vm.wait_for_login(timeout=login_timeout)
        server_ctl_ip = server_ip

    logging.debug(process.system_output("numactl --hardware",
                                        verbose=False, ignore_status=True,
                                        shell=True).decode())
    logging.debug(process.system_output("numactl --show",
                                        verbose=False, ignore_status=True,
                                        shell=True).decode())
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = netperf_base.pin_vm_threads(vm, params.get("numa_node"))
    host = params.get("host", "localhost")
    host_ip = host
    client = params.get("client", "localhost")
    client_ip = client
    client_pub_ip = params.get("client_public_ip")
    client = remote.wait_for_login(params["shell_client_client"],
                                   client_pub_ip,
                                   params["shell_port_client"],
                                   params["username_client"],
                                   params["password_client"],
                                   params["shell_prompt_client"])
    cmd = "ifconfig %s %s up" % (params.get("client_physical_nic"),
                                 client_ip)
    netperf_base.ssh_cmd(client, cmd)

    error_context.context("Prepare env of server/client/host", logging.info)
    prepare_list = set([server_ctl, client, host])
    tag_dict = {server_ctl: "server", client: "client", host: "host"}
    ip_dict = {server_ctl: server_ctl_ip, client: client_pub_ip,
               host: host_ip}
    for i in prepare_list:
        params_tmp = params.object_params(tag_dict[i])
        netperf_base.env_setup(test, params, i, ip_dict[i],
                               username=params_tmp["username"],
                               shell_port=int(params_tmp["shell_port"]),
                               password=params_tmp["password"])

    netperf_base.tweak_tuned_profile(params, server_ctl, client, host)

    env.stop_ip_sniffing()

    try:
        error_context.context("Start netperf udp stream testing", logging.info)
        start_test(server_ip, server_ctl, host, client, test.resultsdir,
                   test_duration=int(params.get('test_duration')),
                   burst_time=params.get('burst_time'),
                   numbers_per_burst=params.get('numbers_per_burst'),
                   params=params, test=test)

        if params.get("log_hostinfo_script"):
            src = os.path.join(test.virtdir, params.get("log_hostinfo_script"))
            path = os.path.join(test.resultsdir, "systeminfo")
            process.system_output("bash %s %s &> %s" % (
                                  src, test.resultsdir, path), shell=True)

        if params.get("log_guestinfo_script") and params.get("log_guestinfo_exec"):
            src = os.path.join(test.virtdir, params.get("log_guestinfo_script"))
            path = os.path.join(test.resultsdir, "systeminfo")
            destpath = params.get("log_guestinfo_path", "/tmp/log_guestinfo.sh")
            vm.copy_files_to(src, destpath, nic_index=1)
            logexec = params.get("log_guestinfo_exec", "bash")
            output = server_ctl.cmd_output("%s %s" % (logexec, destpath))
            logfile = open(path, "a+")
            logfile.write(output)
            logfile.close()
    except process.CmdError:
        test.cancel("test faild")