Exemplo n.º 1
0
def run_set_link(test, params, env):
    """
    KVM guest link test:
    1) Boot up guest with one nic
    2) Disable guest link by set_link
    3) Ping guest from host
    4) Re-enable guest link by set_link
    5) Ping guest from host
    6) Call utils_test.run_file_transfer function to test file transfer.
       It will do following steps:
       6.1) Create a large file by dd on host.
       6.2) Copy this file from host to guest.
       6.3) Copy this file from guest to host.
       6.4) Check if file transfers ended good.

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    # Waiting for guest boot up.
    session = vm.wait_for_login(timeout=timeout)
    session.close()

    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))

    netdev_id = vm.virtnet[0].netdev_id
    device_id = vm.virtnet[0].device_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)

    utils_test.run_file_transfer(test, params, env)
Exemplo n.º 2
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 = utils_test.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    session = utils_test.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.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))

    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)

    utils_test.run_file_transfer(test, params, env)
    session.close()
Exemplo n.º 3
0
def run_trans_hugepage(test, params, env):
    """
    KVM kernel hugepages user side test:
    1) Smoke test
    2) Stress test

    @param test: QEMU test object.
    @param params: Dictionary with test parameters.
    @param env: Dictionary with the test environment.
    """
    def get_mem_status(params, role):
        if role == "host":
            info = utils.system_output("cat /proc/meminfo")
        else:
            info = session.cmd("cat /proc/meminfo")
        for h in re.split("\n+", info):
            if h.startswith("%s" % params):
                output = re.split('\s+', h)[1]
        return output


    dd_timeout = float(params.get("dd_timeout", 900))
    mem = params['mem']
    failures = []

    debugfs_flag = 1
    debugfs_path = os.path.join(test.tmpdir, 'debugfs')
    mem_path = os.path.join("/tmp", 'thp_space')

    login_timeout = float(params.get("login_timeout", "3600"))

    error.context("smoke test setup")
    if not os.path.ismount(debugfs_path):
        if not os.path.isdir(debugfs_path):
            os.makedirs(debugfs_path)
        utils.run("mount -t debugfs none %s" % debugfs_path)

    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    try:
        logging.info("Smoke test start")
        error.context("smoke test")

        nr_ah_before = int(get_mem_status('AnonHugePages', 'host'))
        if nr_ah_before <= 0:
            e_msg = 'smoke: Host is not using THP'
            logging.error(e_msg)
            failures.append(e_msg)

        # Protect system from oom killer
        if int(get_mem_status('MemFree', 'guest')) / 1024 < mem :
            mem = int(get_mem_status('MemFree', 'guest')) / 1024

        session.cmd("mkdir -p %s" % mem_path)

        session.cmd("mount -t tmpfs -o size=%sM none %s" % (str(mem), mem_path))

        count = mem / 4
        session.cmd("dd if=/dev/zero of=%s/1 bs=4000000 count=%s" %
                    (mem_path, count), timeout=dd_timeout)

        nr_ah_after = int(get_mem_status('AnonHugePages', 'host'))

        if nr_ah_after <= nr_ah_before:
            e_msg = ('smoke: Host did not use new THP during dd')
            logging.error(e_msg)
            failures.append(e_msg)

        if debugfs_flag == 1:
            if int(open('%s/kvm/largepages' % debugfs_path, 'r').read()) <= 0:
                e_msg = 'smoke: KVM is not using THP'
                logging.error(e_msg)
                failures.append(e_msg)

        logging.info("Smoke test finished")

        # Use parallel dd as stress for memory
        count = count / 3
        logging.info("Stress test start")
        error.context("stress test")
        cmd = "rm -rf %s/*; for i in `seq %s`; do dd " % (mem_path, count)
        cmd += "if=/dev/zero of=%s/$i bs=4000000 count=1& done;wait" % mem_path
        output = session.cmd_output(cmd, timeout=dd_timeout)

        if len(re.findall("No space", output)) > count * 0.05:
            e_msg = "stress: Too many dd instances failed in guest"
            logging.error(e_msg)
            failures.append(e_msg)

        try:
            output = session.cmd('pidof dd')
        except Exception:
            output = None

        if output is not None:
            for i in re.split('\n+', output):
                session.cmd('kill -9 %s' % i)

        session.cmd("umount %s" % mem_path)

        logging.info("Stress test finished")

    finally:
        error.context("all tests cleanup")
        if os.path.ismount(debugfs_path):
            utils.run("umount %s" % debugfs_path)
        if os.path.isdir(debugfs_path):
            os.removedirs(debugfs_path)
        session.close()

    error.context("")
    if failures:
        raise error.TestFail("THP base test reported %s failures:\n%s" %
                             (len(failures), "\n".join(failures)))
Exemplo n.º 4
0
def run_netperf(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: KVM test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    def env_setup(session, ip, user, port, password):
        error.context("Setup env for %s" % ip)
        ssh_cmd(session, "service iptables stop")
        ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore")

        netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
        for i in params.get("netperf_files").split():
            remote.scp_to_remote(ip, shell_port, username, password,
                                 "%s/%s" % (netperf_dir, i), "/tmp/")
        ssh_cmd(session, params.get("setup_cmd"))

    def _pin_vm_threads(vm, node):
        if node:
            if not isinstance(node, utils_misc.NumaNode):
                node = utils_misc.NumaNode(int(node))
            utils_test.pin_vm_threads(vm, node)

        return node

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

    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)
                    raise error.TestError(msg)
        if params.get("reboot_after_config", "yes") == "yes":
            session = vm.reboot(session=session, timeout=login_timeout)

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

    server_ip = vm.get_address()
    server_ctl = vm.wait_for_login(timeout=login_timeout)
    server_ctl_ip = server_ip
    if (params.get("os_type") == "windows"
            and params.get("use_cygwin") == "yes"):
        cygwin_prompt = params.get("cygwin_prompt", "\$\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

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

    logging.debug(commands.getoutput("numactl --hardware"))
    logging.debug(commands.getoutput("numactl --show"))
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = _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 = []
    clients_n = 1
    # Get the sessions that needed when run netperf parallel
    # The default client connect is the first one.
    if params.get("sessions"):
        for i in re.split("\s+", params.get('sessions')):
            clients_n = max(clients_n, int(i.strip()))
    for i in range(clients_n):
        if client in params.get("vms"):
            vm_client = utils_test.get_living_vm(env, client)
            tmp = vm_client.wait_for_login(timeout=login_timeout)
            client_ip = vm_client.get_address()
        elif client != "localhost":
            tmp = remote.wait_for_login(params.get("shell_client_client"),
                                        client_ip,
                                        params.get("shell_port_client"),
                                        params.get("username_client"),
                                        params.get("password_client"),
                                        params.get("shell_prompt_client"))
        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()
        _pin_vm_threads(vm2, numa_node)

    error.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_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"]
            env_setup(i, ip_dict[i], username, shell_port, password)

    error.context("Start netperf testing", logging.info)
    start_test(server_ip,
               server_ctl,
               host,
               clients,
               test.resultsdir,
               l=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'),
               ver_cmd=params.get('ver_cmd', "rpm -q qemu-kvm"),
               netserver_port=params.get('netserver_port', "12865"),
               params=params,
               server_cyg=server_cyg,
               test=test)
Exemplo n.º 5
0
def run_multi_vms_nics(test, params, env):
    """
    KVM multi test:
    1) Log into guests
    2) Check all the nics available or not
    3) Ping among guest nic and host
       3.1) Ping with different packet size
       3.2) Flood ping test
       3.3) Final ping test
    4) Transfer files among guest nics and host
       4.1) Create file by dd command in guest
       4.2) Transfer file between nics
       4.3) Compare original file and transferred file
    5) ping among different nics
       5.1) Ping with different packet size
       5.2) Flood ping test
       5.3) Final ping test
    6) Transfer files among different nics
       6.1) Create file by dd command in guest
       6.2) Transfer file between nics
       6.3) Compare original file and transferred file
    7) Repeat step 3 - 6 on every nic.

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

    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)

    def file_transfer(session, src, dst):
        username = params.get("username", "")
        password = params.get("password", "")
        src_path = "/tmp/1"
        dst_path = "/tmp/2"
        port = int(params["file_transfer_port"])

        cmd = "dd if=/dev/urandom of=%s bs=100M count=1" % src_path
        cmd = params.get("file_create_cmd", cmd)

        error.context("Create file by dd command, cmd: %s" % cmd, logging.info)
        session.cmd(cmd)

        transfer_timeout = int(params.get("transfer_timeout"))
        log_filename = "scp-from-%s-to-%s.log" % (src, dst)
        error.context("Transfer file from %s to %s" % (src, dst), logging.info)
        remote.scp_between_remotes(
            src,
            dst,
            port,
            password,
            password,
            username,
            username,
            src_path,
            dst_path,
            log_filename=log_filename,
            timeout=transfer_timeout,
        )
        src_path = dst_path
        dst_path = "/tmp/3"
        log_filename = "scp-from-%s-to-%s.log" % (dst, src)
        error.context("Transfer file from %s to %s" % (dst, src), logging.info)
        remote.scp_between_remotes(
            dst,
            src,
            port,
            password,
            password,
            username,
            username,
            src_path,
            dst_path,
            log_filename=log_filename,
            timeout=transfer_timeout,
        )
        error.context("Compare original file and transferred file", logging.info)

        cmd1 = "md5sum /tmp/1"
        cmd2 = "md5sum /tmp/3"
        md5sum1 = session.cmd(cmd1).split()[0]
        md5sum2 = session.cmd(cmd2).split()[0]
        if md5sum1 != md5sum2:
            raise error.TestError("File changed after transfer")

    vm_list = []
    session_list = []
    vms = params["vms"].split()
    timeout = float(params.get("login_timeout", 360))
    mac_ip_filter = params["mac_ip_filter"]
    strict_check = params.get("strick_check", "no")
    host_ip = utils_net.get_ip_address_by_interface(params.get("netdst"))
    host_ip = params.get("srchost", host_ip)
    flood_minutes = float(params["flood_minutes"])
    for vm_name in vms:
        vm = utils_test.get_living_vm(env, vm_name)
        vm_list.append(vm)
        session_list.append(vm.wait_for_login(timeout=timeout))

    ip_list = []

    error.context("Check all the nics available or not", logging.info)
    count_nics = len(params.get("nics").split())
    for i in session_list:
        ips = []
        cmd = params.get("net_check_cmd")
        end_time = time.time() + timeout
        while time.time() < end_time:
            status, output = i.get_command_status_output(cmd)
            if status:
                err_msg = "Can not get ip from guest."
                err_msg += " Cmd '%s' fail with output: %s" % (cmd, output)
                logging.error(err_msg)
            ips = re.findall(mac_ip_filter, output, re.S)
            if count_nics == len(ips):
                break
            time.sleep(2)
        else:
            err_log = "Not all nics get ip.  Set '%s' nics." % count_nics
            err_log += " Guest only get '%s' ip(s). " % len(ips)
            err_log += " Command '%s' output in guest:\n%s" % (cmd, output)
            raise error.TestFail(err_log)
        for ip in ips:
            ip_list.append(ip + (i,))
    ip_list_len = len(ip_list)
    # ping and file transfer test
    for src_ip_index in range(ip_list_len):
        error.context("Ping test from guest to host", logging.info)
        src_ip_info = ip_list[src_ip_index]
        ping(src_ip_info[3], src_ip_info[0], host_ip, strict_check, flood_minutes)
        error.context("File transfer test between guest and host", logging.info)
        file_transfer(src_ip_info[3], src_ip_info[2], host_ip)
        for dst_ip in ip_list[src_ip_index:]:
            txt = "Ping test between %s and %s" % (src_ip_info[2], dst_ip[2])
            error.context(txt, logging.info)
            ping(src_ip_info[3], src_ip_info[0], dst_ip[2], strict_check, flood_minutes)
            txt = "File transfer test between %s " % src_ip_info[2]
            txt += "and %s" % dst_ip[2]
            error.context(txt, logging.info)
            file_transfer(src_ip_info[3], src_ip_info[2], dst_ip[2])
Exemplo n.º 6
0
def run_trans_hugepage(test, params, env):
    """
    KVM kernel hugepages user side test:
    1) Smoke test
    2) Stress test

    :param test: QEMU test object.
    :param params: Dictionary with test parameters.
    :param env: Dictionary with the test environment.
    """
    def get_mem_status(params, role):
        if role == "host":
            info = utils.system_output("cat /proc/meminfo")
        else:
            info = session.cmd("cat /proc/meminfo")
        for h in re.split("\n+", info):
            if h.startswith("%s" % params):
                output = re.split('\s+', h)[1]
        return output

    dd_timeout = float(params.get("dd_timeout", 900))
    mem = params['mem']
    failures = []

    debugfs_flag = 1
    debugfs_path = os.path.join(test.tmpdir, 'debugfs')
    mem_path = os.path.join("/tmp", 'thp_space')

    login_timeout = float(params.get("login_timeout", "3600"))

    error.context("smoke test setup")
    if not os.path.ismount(debugfs_path):
        if not os.path.isdir(debugfs_path):
            os.makedirs(debugfs_path)
        utils.run("mount -t debugfs none %s" % debugfs_path)

    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    funcatexit.register(env, params.get("type"), cleanup, debugfs_path,
                        session)

    logging.info("Smoke test start")
    error.context("smoke test")

    nr_ah_before = int(get_mem_status('AnonHugePages', 'host'))
    if nr_ah_before <= 0:
        e_msg = 'smoke: Host is not using THP'
        logging.error(e_msg)
        failures.append(e_msg)

    # Protect system from oom killer
    if int(get_mem_status('MemFree', 'guest')) / 1024 < mem:
        mem = int(get_mem_status('MemFree', 'guest')) / 1024

    session.cmd("mkdir -p %s" % mem_path)

    session.cmd("mount -t tmpfs -o size=%sM none %s" % (str(mem), mem_path))

    count = mem / 4
    session.cmd("dd if=/dev/zero of=%s/1 bs=4000000 count=%s" %
                (mem_path, count),
                timeout=dd_timeout)

    nr_ah_after = int(get_mem_status('AnonHugePages', 'host'))

    if nr_ah_after <= nr_ah_before:
        e_msg = ('smoke: Host did not use new THP during dd')
        logging.error(e_msg)
        failures.append(e_msg)

    if debugfs_flag == 1:
        if int(open('%s/kvm/largepages' % debugfs_path, 'r').read()) <= 0:
            e_msg = 'smoke: KVM is not using THP'
            logging.error(e_msg)
            failures.append(e_msg)

    logging.info("Smoke test finished")

    # Use parallel dd as stress for memory
    count = count / 3
    logging.info("Stress test start")
    error.context("stress test")
    cmd = "rm -rf %s/*; for i in `seq %s`; do dd " % (mem_path, count)
    cmd += "if=/dev/zero of=%s/$i bs=4000000 count=1& done;wait" % mem_path
    output = session.cmd_output(cmd, timeout=dd_timeout)

    if len(re.findall("No space", output)) > count * 0.05:
        e_msg = "stress: Too many dd instances failed in guest"
        logging.error(e_msg)
        failures.append(e_msg)

    try:
        output = session.cmd('pidof dd')
    except Exception:
        output = None

    if output is not None:
        for i in re.split('\n+', output):
            session.cmd('kill -9 %s' % i)

    session.cmd("umount %s" % mem_path)

    logging.info("Stress test finished")

    error.context("")
    if failures:
        raise error.TestFail("THP base test reported %s failures:\n%s" %
                             (len(failures), "\n".join(failures)))
Exemplo n.º 7
0
def run_netperf(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 env_setup(session, ip, user, port, password):
        error.context("Setup env for %s" % ip)
        ssh_cmd(session, "service iptables stop")
        ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore")

        netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
        for i in params.get("netperf_files").split():
            remote.scp_to_remote(ip, shell_port, username, password,
                                     "%s/%s" % (netperf_dir, i), "/tmp/")
        ssh_cmd(session, params.get("setup_cmd"))


    def _pin_vm_threads(vm, node):
        if node:
            if not isinstance(node, utils_misc.NumaNode):
                node = utils_misc.NumaNode(int(node))
            utils_test.pin_vm_threads(vm, node)

        return node


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

    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)
                    raise error.TestError(msg)
        if params.get("reboot_after_config", "yes") == "yes":
            session = vm.reboot(session=session, timeout=login_timeout)

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

    server_ip = vm.get_address()
    server_ctl = vm.wait_for_login(timeout=login_timeout)
    server_ctl_ip = server_ip
    if (params.get("os_type") == "windows"
        and params.get("use_cygwin") == "yes"):
        cygwin_prompt = params.get("cygwin_prompt", "\$\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

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



    logging.debug(commands.getoutput("numactl --hardware"))
    logging.debug(commands.getoutput("numactl --show"))
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = _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 = []
    clients_n = 1
    # Get the sessions that needed when run netperf parallel
    # The default client connect is the first one.
    if params.get("sessions") or params.get("sessions_rr"):
        sessions_str = params.get('sessions') + " " + params.get("sessions_rr")
        for i in sessions_str.split():
            clients_n = max(clients_n, int(i.strip()))
    for i in range(clients_n + 1):
        if client in params.get("vms"):
            vm_client = utils_test.get_living_vm(env, client)
            tmp = vm_client.wait_for_login(timeout=login_timeout)
            client_ip = vm_client.get_address()
        elif client != "localhost":
            tmp = remote.wait_for_login(params.get("shell_client_client"),
                                        client_ip,
                                        params.get("shell_port_client"),
                                        params.get("username_client"),
                                        params.get("password_client"),
                                        params.get("shell_prompt_client"))
        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()
        _pin_vm_threads(vm2, numa_node)

    error.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_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"]
            env_setup(i, ip_dict[i], username, shell_port, password)

    error.context("Start netperf testing", logging.info)
    start_test(server_ip, server_ctl, host, clients, test.resultsdir,
               l=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'),
               ver_cmd=params.get('ver_cmd', "rpm -q qemu-kvm"),
               netserver_port=params.get('netserver_port', "12865"),
               params=params, server_cyg=server_cyg, test=test)
Exemplo n.º 8
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    @param test:   QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    udev_rules_path = "/etc/udev/rules.d/70-persistent-net.rules"
    udev_rules_bkp_path = "/tmp/70-persistent-net.rules"

    def guest_path_isfile(path):
        try:
            session.cmd("test -f %s" % path)
        except aexpect.ShellError:
            return False
        return True

    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_path):
            session.cmd("mv -f %s %s" % (udev_rules_path, udev_rules_bkp_path))

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

    # hot-add the nic
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype)

    # 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=login_timeout)
        ifname = utils_test.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    logging.info("Shutting down the primary link(s)")
    for nic in vm.virtnet:
        if not (nic.nic_name == nic_name):
            vm.set_link(nic.device_id, up=False)

    try:
        logging.info("Waiting for new nic's ip address acquisition...")
        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)

        logging.info("Ping test the new nic ...")
        s, o = utils_test.ping(ip, 100)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")

        logging.info("Detaching the previously attached nic from vm")
        vm.hotunplug_nic(nic_name)

    finally:
        logging.info("Re-enabling the primary link(s)")
        for nic in vm.virtnet:
            if not (nic.nic_name == nic_name):
                vm.set_link(nic.device_id, up=True)

    # Attempt to put back udev network naming rules, even if the command to
    # disable the rules failed. We may be undoing what was done in a previous
    # (failed) test that never reached this point.
    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_bkp_path):
            session.cmd("mv -f %s %s" % (udev_rules_bkp_path, udev_rules_path))
Exemplo n.º 9
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    @param test:   KVM test object.
    @param params: Dictionary with the test parameters.
    @param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

    udev_rules_path = "/etc/udev/rules.d/70-persistent-net.rules"
    udev_rules_bkp_path = "/tmp/70-persistent-net.rules"

    def guest_path_isfile(path):
        try:
            session.cmd("test -f %s" % path)
        except aexpect.ShellError:
            return False
        return True

    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_path):
            session.cmd("mv -f %s %s" % (udev_rules_path, udev_rules_bkp_path))

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

    # hot-add the nic
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype)

    # 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=login_timeout)
        ifname = utils_test.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    logging.info("Shutting down the primary link(s)")
    for nic in vm.virtnet:
        if nic.nic_name == nic_name:
            continue
        else:
            vm.monitor.cmd("set_link %s off" % nic.device_id)

    try:
        logging.info("Waiting for new nic's ip address acquisition...")
        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)

        logging.info("Ping test the new nic ...")
        s, o = utils_test.ping(ip, 100)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")

        logging.info("Detaching the previously attached nic from vm")
        vm.hotunplug_nic(nic_name)

    finally:
        logging.info("Re-enabling the primary link(s)")
        for nic in vm.virtnet:
            if nic.nic_name == nic_name:
                continue
            else:
                vm.monitor.cmd("set_link %s on" % nic.device_id)

    # Attempt to put back udev network naming rules, even if the command to
    # disable the rules failed. We may be undoing what was done in a previous
    # (failed) test that never reached this point.
    if guest_is_not_windows:
        if guest_path_isfile(udev_rules_bkp_path):
            session.cmd("mv -f %s %s" % (udev_rules_bkp_path, udev_rules_path))
Exemplo n.º 10
0
def run_nic_hotplug(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one nic
    2) Add a host network device through monitor cmd and check if it's added
    3) Add nic device through monitor cmd and check if it's added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev
    8) Ping guest's new ip address after guest pause/resume
    9) Re-enable primary link of guest

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The KVM autotest default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params["main_vm"])
    login_timeout = int(params.get("login_timeout", 360))
    pci_model = params.get("pci_model", "rtl8139")
    run_dhclient = params.get("run_dhclient", "no")

    nettype = params.get("nettype", "bridge")
    netdst = params.get("netdst", "virbr0")
    guest_is_not_windows = "Win" not in params.get("guest_name", "")

    session = utils_test.wait_for_login(vm, timeout=login_timeout)

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

    # hot-add the nic
    error.context("Add network devices through monitor cmd", logging.info)
    nic_name = 'hotadded'
    nic_info = vm.hotplug_nic(nic_model=pci_model, nic_name=nic_name,
                              netdst=netdst, nettype=nettype,
                              queues=params.get('queues'),
                              vectors=params.get('vectors'))

    # 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=login_timeout)
        ifname = utils_net.get_linux_ifname(session, nic_info['mac'])
        session_serial.cmd("dhclient %s &" % ifname)

    error.context("Disable the primary link(s) of guest", logging.info)
    for nic in vm.virtnet:
        if not (nic.nic_name == nic_name):
            vm.set_link(nic.device_id, up=False)

    try:
        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:
            logging.error(o)
            raise error.TestFail("New nic failed ping test")
        error.context("Ping guest's new ip after pasue/resume", logging.info)
        vm.monitor.cmd("stop")
        vm.monitor.cmd("cont")
        s, o = utils_test.ping(ip, 10, timeout=15)
        if s != 0:
            logging.error(o)
            raise error.TestFail("New nic failed ping test after stop/cont")

        logging.info("Detaching the previously attached nic from vm")
        error.context("Detaching the previously attached nic from vm",
                      logging.info)
        vm.hotunplug_nic(nic_name)

    finally:
        error.context("Re-enabling the primary link(s)", logging.info)
        for nic in vm.virtnet:
            if not (nic.nic_name == nic_name):
                vm.set_link(nic.device_id, up=True)
Exemplo n.º 11
0
def run_multi_vms_nics(test, params, env):
    """
    KVM multi test:
    1) Log into guests
    2) Check all the nics available or not
    3) Ping among guest nic and host
       3.1) Ping with different packet size
       3.2) Flood ping test
       3.3) Final ping test
    4) Transfer files among guest nics and host
       4.1) Create file by dd command in guest
       4.2) Transfer file between nics
       4.3) Compare original file and transferred file
    5) ping among different nics
       5.1) Ping with different packet size
       5.2) Flood ping test
       5.3) Final ping test
    6) Transfer files among different nics
       6.1) Create file by dd command in guest
       6.2) Transfer file between nics
       6.3) Compare original file and transferred file
    7) Repeat step 3 - 6 on every nic.

    @param test: QEMU test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    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)

    def file_transfer(session, src, dst):
        username = params.get("username", "")
        password = params.get("password", "")
        src_path = "/tmp/1"
        dst_path = "/tmp/2"
        port = int(params["file_transfer_port"])

        cmd = "dd if=/dev/urandom of=%s bs=100M count=1" % src_path
        cmd = params.get("file_create_cmd", cmd)

        error.context("Create file by dd command, cmd: %s" % cmd, logging.info)
        session.cmd(cmd)

        transfer_timeout = int(params.get("transfer_timeout"))
        log_filename = "scp-from-%s-to-%s.log" % (src, dst)
        error.context("Transfer file from %s to %s" % (src, dst), logging.info)
        remote.scp_between_remotes(src,
                                   dst,
                                   port,
                                   password,
                                   password,
                                   username,
                                   username,
                                   src_path,
                                   dst_path,
                                   log_filename=log_filename,
                                   timeout=transfer_timeout)
        src_path = dst_path
        dst_path = "/tmp/3"
        log_filename = "scp-from-%s-to-%s.log" % (dst, src)
        error.context("Transfer file from %s to %s" % (dst, src), logging.info)
        remote.scp_between_remotes(dst,
                                   src,
                                   port,
                                   password,
                                   password,
                                   username,
                                   username,
                                   src_path,
                                   dst_path,
                                   log_filename=log_filename,
                                   timeout=transfer_timeout)
        error.context("Compare original file and transferred file",
                      logging.info)

        cmd1 = "md5sum /tmp/1"
        cmd2 = "md5sum /tmp/3"
        md5sum1 = session.cmd(cmd1).split()[0]
        md5sum2 = session.cmd(cmd2).split()[0]
        if md5sum1 != md5sum2:
            raise error.TestError("File changed after transfer")

    vm_list = []
    session_list = []
    vms = params["vms"].split()
    timeout = float(params.get("login_timeout", 360))
    mac_ip_filter = params["mac_ip_filter"]
    strict_check = params.get("strick_check", "no")
    host_ip = utils_net.get_ip_address_by_interface(params.get("netdst"))
    host_ip = params.get("srchost", host_ip)
    flood_minutes = float(params["flood_minutes"])
    for vm_name in vms:
        vm = utils_test.get_living_vm(env, vm_name)
        vm_list.append(vm)
        session_list.append(vm.wait_for_login(timeout=timeout))

    ip_list = []

    error.context("Check all the nics available or not", logging.info)
    count_nics = len(params.get("nics").split())
    for i in session_list:
        ips = []
        cmd = params.get("net_check_cmd")
        end_time = time.time() + timeout
        while time.time() < end_time:
            status, output = i.get_command_status_output(cmd)
            if status:
                err_msg = "Can not get ip from guest."
                err_msg += " Cmd '%s' fail with output: %s" % (cmd, output)
                logging.error(err_msg)
            ips = re.findall(mac_ip_filter, output, re.S)
            if count_nics == len(ips):
                break
            time.sleep(2)
        else:
            err_log = "Not all nics get ip.  Set '%s' nics." % count_nics
            err_log += " Guest only get '%s' ip(s). " % len(ips)
            err_log += " Command '%s' output in guest:\n%s" % (cmd, output)
            raise error.TestFail(err_log)
        for ip in ips:
            ip_list.append(ip + (i, ))
    ip_list_len = len(ip_list)
    # ping and file transfer test
    for src_ip_index in range(ip_list_len):
        error.context("Ping test from guest to host", logging.info)
        src_ip_info = ip_list[src_ip_index]
        ping(src_ip_info[3], src_ip_info[0], host_ip, strict_check,
             flood_minutes)
        error.context("File transfer test between guest and host",
                      logging.info)
        file_transfer(src_ip_info[3], src_ip_info[2], host_ip)
        for dst_ip in ip_list[src_ip_index:]:
            txt = "Ping test between %s and %s" % (src_ip_info[2], dst_ip[2])
            error.context(txt, logging.info)
            ping(src_ip_info[3], src_ip_info[0], dst_ip[2], strict_check,
                 flood_minutes)
            txt = "File transfer test between %s " % src_ip_info[2]
            txt += "and %s" % dst_ip[2]
            error.context(txt, logging.info)
            file_transfer(src_ip_info[3], src_ip_info[2], dst_ip[2])
Exemplo n.º 12
0
            utils.run(cmd)
        finally:
            utils.run("umount %s" % mem_path)


    test_config = test_setup.TransparentHugePageConfig(test, params)
    logging.info("Defrag test start")
    login_timeout = float(params.get("login_timeout", 360))
    mem_path = os.path.join("/tmp", "thp_space")

    try:
        error.context("deactivating khugepaged defrag functionality")
        change_feature_status("off", "khugepaged/defrag", test_config)
        change_feature_status("off", "defrag", test_config)

        vm = utils_test.get_living_vm(env, params.get("main_vm"))
        session = utils_test.wait_for_login(vm, timeout=login_timeout)

        fragment_host_memory(mem_path)

        total = get_mem_stat('MemTotal')
        hugepagesize = get_mem_stat('Hugepagesize')
        nr_full = int(0.8 * (total / hugepagesize))

        nr_hp_before = set_libhugetlbfs(nr_full)

        error.context("activating khugepaged defrag functionality")
        change_feature_status("on", "khugepaged/defrag", test_config)
        change_feature_status("on", "defrag", test_config)

        sleep_time = 10
Exemplo n.º 13
0
def run_netperf(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 env_setup(session, ip, user, port, password):
        error.context("Setup env for %s" % ip)
        ssh_cmd(session, "iptables -F; true")
        ssh_cmd(session, "service iptables stop; true")
        ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore")

        download_link = params.get("netperf_download_link")
        download_dir = data_dir.get_download_dir()
        md5sum = params.get("pkg_md5sum")
        pkg = utils.unmap_url_cache(download_dir, download_link, md5sum)
        remote.scp_to_remote(ip, shell_port, username, password, pkg, "/tmp")
        ssh_cmd(session, params.get("setup_cmd"))

        agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py")
        remote.scp_to_remote(ip, shell_port, username, password, agent_path, "/tmp")

    def _pin_vm_threads(vm, node):
        if node:
            if not isinstance(node, utils_misc.NumaNode):
                node = utils_misc.NumaNode(int(node))
            utils_test.pin_vm_threads(vm, node)

        return node

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

    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)
                    raise error.TestError(msg)
        if params.get("reboot_after_config", "yes") == "yes":
            session = vm.reboot(session=session, timeout=login_timeout)

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

    server_ip = vm.get_address()
    server_ctl = vm.wait_for_login(timeout=login_timeout)
    server_ctl_ip = server_ip
    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

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

    logging.debug(commands.getoutput("numactl --hardware"))
    logging.debug(commands.getoutput("numactl --show"))
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = _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 = utils_test.get_living_vm(env, client)
            tmp = vm_client.wait_for_login(timeout=login_timeout)
            client_ip = vm_client.get_address()
        elif client != "localhost":
            tmp = remote.wait_for_login(
                params.get("shell_client_client"),
                client_ip,
                params.get("shell_port_client"),
                params.get("username_client"),
                params.get("password_client"),
                params.get("shell_prompt_client"),
            )
        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()
        _pin_vm_threads(vm2, numa_node)

    error.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_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"]
            env_setup(i, ip_dict[i], username, shell_port, password)

    if "tcpdump" in env and env["tcpdump"].is_alive():
        # Stop the background tcpdump process
        try:
            logging.debug("Stopping the background tcpdump")
            env["tcpdump"].close()
        except Exception:
            pass

    error.context("Start netperf testing", logging.info)
    start_test(
        server_ip,
        server_ctl,
        host,
        clients,
        test.resultsdir,
        l=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"),
        ver_cmd=params.get("ver_cmd", "rpm -q qemu-kvm"),
        netserver_port=params.get("netserver_port", "12865"),
        params=params,
        server_cyg=server_cyg,
        test=test,
    )
Exemplo n.º 14
0
def run_netperf(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 env_setup(session, ip, user, port, password):
        error.context("Setup env for %s" % ip)
        ssh_cmd(session, "iptables -F; true")
        ssh_cmd(session, "service iptables stop; true")
        ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore")

        download_link = params.get("netperf_download_link")
        download_dir = data_dir.get_download_dir()
        md5sum = params.get("pkg_md5sum")
        pkg = utils.unmap_url_cache(download_dir, download_link, md5sum)
        remote.scp_to_remote(ip, shell_port, username, password, pkg, "/tmp")
        ssh_cmd(session, params.get("setup_cmd"))

        agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py")
        remote.scp_to_remote(ip, shell_port, username, password,
                             agent_path, "/tmp")

    def _pin_vm_threads(vm, node):
        if node:
            if not isinstance(node, utils_misc.NumaNode):
                node = utils_misc.NumaNode(int(node))
            utils_test.pin_vm_threads(vm, node)

        return node

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

    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)
                    raise error.TestError(msg)
        if params.get("reboot_after_config", "yes") == "yes":
            session = vm.reboot(session=session, timeout=login_timeout)

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

    server_ip = vm.get_address()
    server_ctl = vm.wait_for_login(timeout=login_timeout)
    server_ctl_ip = server_ip
    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

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

    logging.debug(commands.getoutput("numactl --hardware"))
    logging.debug(commands.getoutput("numactl --show"))
    # pin guest vcpus/memory/vhost threads to last numa node of host by default
    numa_node = _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 = utils_test.get_living_vm(env, client)
            tmp = vm_client.wait_for_login(timeout=login_timeout)
            client_ip = vm_client.get_address()
        elif client != "localhost":
            tmp = remote.wait_for_login(params.get("shell_client_client"),
                                        client_ip,
                                        params.get("shell_port_client"),
                                        params.get("username_client"),
                                        params.get("password_client"),
                                        params.get("shell_prompt_client"))
        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()
        _pin_vm_threads(vm2, numa_node)

    error.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_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"]
            env_setup(i, ip_dict[i], username, shell_port, password)

    if "tcpdump" in env and env["tcpdump"].is_alive():
        # Stop the background tcpdump process
        try:
            logging.debug("Stopping the background tcpdump")
            env["tcpdump"].close()
        except Exception:
            pass

    error.context("Start netperf testing", logging.info)
    start_test(server_ip, server_ctl, host, clients, test.resultsdir,
               l=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'),
               ver_cmd=params.get('ver_cmd', "rpm -q qemu-kvm"),
               netserver_port=params.get('netserver_port', "12865"),
               params=params, server_cyg=server_cyg, test=test)
Exemplo n.º 15
0
                   "bs=4K count=1 & done" % mem_path)
            utils.run(cmd)
        finally:
            utils.run("umount %s" % mem_path)

    test_config = test_setup.TransparentHugePageConfig(test, params)
    logging.info("Defrag test start")
    login_timeout = float(params.get("login_timeout", 360))
    mem_path = os.path.join("/tmp", "thp_space")

    try:
        error.context("deactivating khugepaged defrag functionality")
        change_feature_status("off", "khugepaged/defrag", test_config)
        change_feature_status("off", "defrag", test_config)

        vm = utils_test.get_living_vm(env, params.get("main_vm"))
        session = utils_test.wait_for_login(vm, timeout=login_timeout)

        fragment_host_memory(mem_path)

        total = get_mem_stat('MemTotal')
        hugepagesize = get_mem_stat('Hugepagesize')
        nr_full = int(0.8 * (total / hugepagesize))

        nr_hp_before = set_libhugetlbfs(nr_full)

        error.context("activating khugepaged defrag functionality")
        change_feature_status("on", "khugepaged/defrag", test_config)
        change_feature_status("on", "defrag", test_config)

        sleep_time = 10
Exemplo n.º 16
0
def run_set_link(test, params, env):
    """
    KVM guest link test:
    1) Boot up guest with one nic
    2) Disable guest link by set_link
    3) Ping guest from host
    4) Re-enable guest link by set_link
    5) Ping guest from host
    6) Call utils_test.run_file_transfer function to test file transfer.
       It will do following steps:
       6.1) Create a large file by dd on host.
       6.2) Copy this file from host to guest.
       6.3) Copy this file from guest to host.
       6.4) Check if file transfers ended good.

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = utils_test.get_living_vm(env, params.get("main_vm"))
    timeout = float(params.get("login_timeout", 360))
    # Waiting for guest boot up.
    session = vm.wait_for_login(timeout=timeout)
    session.close()

    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))

    netdev_id = vm.virtnet[0].netdev_id
    device_id = vm.virtnet[0].device_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)

    utils_test.run_file_transfer(test, params, env)