Beispiel #1
0
 def _output_logger_handler(self, line):
     try:
         log_line(self._logfile, line)
     except Exception as e:
         logging.warn("Can't log ip sniffer output: '%s'", e)
     if self._output_handler(line):
         return
     # We can check whether the process is terminated unexpectedly
     # here since the terminated status is a line of the output
     match = self._re_sniffer_finished.match(line)
     if match:
         if match.group(1) != "0":
             logging.error("IP sniffer (%s) terminated unexpectedly! "
                           "please check the log to get the details "
                           "(status: %s)", self.command, match.group(1))
Beispiel #2
0
def run_whql_env_setup(test, params, env):
    """
    KVM whql env setup test:
    1) Log into a guest
    2) Update Windows kernel to the newest version
    3) Un-check Automatically restart in system failure
    4) Disable UAC
    5) Get the symbol files
    6) Set VM to physical memory + 100M
    7) Update the nic configuration
    8) Install debug view and make it auto run

    @param test: QEMU test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    log_path = "%s/../debug" % test.resultsdir
    # Prepare the tools iso
    error.context("Prepare the tools iso", logging.info)
    src_list = params.get("src_list")
    src_path = params.get("src_path", "%s/whql_src" % test.tmpdir)
    if not os.path.exists(src_path):
        os.makedirs(src_path)
    if src_list is not None:
        for i in re.split(",", src_list):
            utils.unmap_url(src_path, i, src_path)

    # Make iso for src
    cdrom_whql = params.get("cdrom_whql")
    cdrom_whql = utils_misc.get_path(data_dir.get_data_dir(), cdrom_whql)
    cdrom_whql_dir = os.path.split(cdrom_whql)[0]
    if not os.path.exists(cdrom_whql_dir):
        os.makedirs(cdrom_whql_dir)
    cmd = "mkisofs -J -o %s %s" % (cdrom_whql, src_path)
    utils.system(cmd)
    params["cdroms"] += " whql"

    vm = "vm1"
    vm_params = params.object_params(vm)
    env_process.preprocess_vm(test, vm_params, env, vm)
    vm = env.get_vm(vm)

    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    error_log = utils_misc.get_path(log_path, "whql_setup_error_log")
    run_guest_log = params.get("run_guest_log",
                               "%s/whql_qemu_comman" % test.tmpdir)

    # Record qmmu command line in a log file
    error.context("Record qemu command line", logging.info)
    if os.path.isfile(run_guest_log):
        fd = open(run_guest_log, "r+")
        fd.read()
    else:
        fd = open(run_guest_log, "w")
    fd.write("%s\n" % vm.qemu_command)
    fd.close()

    # Get set up commands
    update_cmd = params.get("update_cmd", "")
    timezone_cmd = params.get("timezone_cmd", "")
    auto_restart = params.get("auto_restart", "")
    qxl_install = params.get("qxl_install", "")
    debuggers_install = params.get("debuggers_install", "")
    disable_uas = params.get("disable_uas", "")
    symbol_files = params.get("symbol_files", "")
    vm_size = int(params.get("mem")) + 100
    nic_cmd = params.get("nic_config_cmd", "")
    dbgview_cmd = params.get("dbgview_cmd", "")
    format_cmd = params.get("format_cmd", "")
    disable_firewall = params.get("disable_firewall", "")
    disable_update = params.get("disable_update", "")
    setup_timeout = int(params.get("setup_timeout", "7200"))
    disk_init_cmd = params.get("disk_init_cmd", "")
    disk_driver_install = params.get("disk_driver_install", "")

    vm_ma_cmd = "wmic computersystem set AutomaticManagedPagefile=False"
    vm_cmd = "wmic pagefileset where name=\"C:\\\\pagefile.sys\" set "
    vm_cmd += "InitialSize=%s,MaximumSize=%s" % (vm_size, vm_size)
    vm_ma_cmd = ""
    vm_cmd = ""
    if symbol_files:
        symbol_cmd = "del  C:\\\\symbols &&"
        symbol_cmd += "git clone %s C:\\\\symbol_files C:\\\\symbols" % \
                      symbol_files
    else:
        symbol_cmd = ""
    wmic_prepare_cmd = "echo exit > cmd && cmd /s wmic"

    error.context("Configure guest system", logging.info)
    cmd_list = [
        wmic_prepare_cmd, auto_restart, disable_uas, symbol_cmd, vm_ma_cmd,
        vm_cmd, dbgview_cmd, qxl_install, disable_firewall, timezone_cmd
    ]
    if nic_cmd:
        for index, nic in enumerate(re.split("\s+", params.get("nics"))):
            setup_params = params.get("nic_setup_params_%s" % nic, "")
            if params.get("platform", "") == "x86_64":
                nic_cmd = re.sub("set", "set_64", nic_cmd)
            cmd_list.append("%s %s %s" %
                            (nic_cmd, str(index + 1), setup_params))
    if disk_init_cmd:
        disk_num = len(re.split("\s+", params.get("images")))
        if disk_driver_install:
            cmd_list.append(disk_driver_install + str(disk_num - 1))
        labels = "IJKLMNOPQRSTUVWXYZ"
        for index, images in enumerate(re.split("\s+", params.get("images"))):
            if index > 0:
                cmd_list.append(disk_init_cmd %
                                (str(index), labels[index - 1]))
                format_cmd_image = format_cmd % (
                    labels[index - 1], params.get("win_format_%s" % images))
                if params.get("win_extra_%s" % images):
                    format_cmd_image += " %s" % params.get(
                        "win_extra_%s" % images)
                cmd_list.append(format_cmd_image)

    cmd_list += [update_cmd, disable_update]

    failed_flag = 0

    # Check symbol files in guest
    if symbol_files:
        error.context("Update symbol files", logging.info)
        install_check_tool = False
        check_tool_chk = params.get("check_tool_chk",
                                    "C:\debuggers\symchk.exe")
        output = session.cmd_output(check_tool_chk)
        if "cannot find" in output:
            install_check_tool = True

        if install_check_tool:
            output = session.cmd_output(debuggers_install)
        symbol_file_check = params.get("symbol_file_check")
        symbol_file_download = params.get("symbol_file_download")

        symbol_check_pattern = params.get("symbol_check_pattern")
        symbol_pid_pattern = params.get("symbol_pid_pattern")
        download = utils_test.BackgroundTest(
            session.cmd, (symbol_file_download, setup_timeout))

        sessioncheck = vm.wait_for_login(timeout=timeout)
        download.start()
        while download.is_alive():
            o = sessioncheck.cmd_output(symbol_file_check, setup_timeout)
            if symbol_check_pattern in o:
                # Check is done kill download process
                cmd = "tasklist /FO list"
                s, o = sessioncheck.cmd_status_output(cmd)
                pid = re.findall(symbol_pid_pattern, o, re.S)
                if pid:
                    cmd = "taskkill /PID %s /F" % pid[0]
                    try:
                        sessioncheck.cmd(cmd)
                    except Exception:
                        pass
                    break
            time.sleep(5)
        sessioncheck.close()
        download.join()

    for cmd in cmd_list:
        if len(cmd) > 0:
            s = 0
            try:
                s, o = session.cmd_status_output(cmd, timeout=setup_timeout)
            except Exception, err:
                failed_flag += 1
                utils_misc.log_line(error_log,
                                    "Unexpected exception: %s" % err)
            if s != 0:
                failed_flag += 1
                utils_misc.log_line(error_log, o)
Beispiel #3
0
def run(test, params, env):
    """
    SR-IOV devices sanity test:
    1) Bring up VFs by following instructions How To in Setup.
    2) Configure all VFs in host.
    3) Check whether all VFs get ip in host.
    4) Unbind PFs/VFs from host kernel driver to sr-iov driver.
    5) Bind PFs/VFs back to host kernel driver.
    6) Repeat step 4, 5.
    7) Try to boot up guest(s) with VF(s).

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

    device_driver = params.get("device_driver", "pci-assign")
    repeat_time = int(params.get("bind_repeat_time", 1))
    pci_assignable = test_setup.PciAssignable(
        driver=params.get("driver"),
        driver_option=params.get("driver_option"),
        host_set_flag=1,
        kvm_params=params.get("kvm_default"),
        vf_filter_re=params.get("vf_filter_re"),
        pf_filter_re=params.get("pf_filter_re"),
        device_driver=device_driver)

    devices = []
    device_type = params.get("device_type", "vf")
    if device_type == "vf":
        device_num = pci_assignable.get_vfs_count()
        if device_num == 0:
            msg = " No VF device found even after running SR-IOV setup"
            raise error.TestFail(msg)
    elif device_type == "pf":
        device_num = len(pci_assignable.get_pf_vf_info())
    else:
        msg = "Unsupport device type '%s'." % device_type
        msg += " Please set device_type to 'vf' or 'pf'."
        raise error.TestError(msg)

    for i in xrange(device_num):
        device = {}
        device["type"] = device_type
        if device_type == "vf":
            device['mac'] = utils_net.generate_mac_address_simple()
        if params.get("device_name"):
            device["name"] = params.get("device_name")
        devices.append(device)

    pci_assignable.devices = devices
    vf_pci_id = []
    pf_vf_dict = pci_assignable.get_pf_vf_info()
    for pf_dict in pf_vf_dict:
        vf_pci_id.extend(pf_dict["vf_ids"])

    ethname_dict = []
    ips = {}

    msg = "Configure all VFs in host."
    error.context(msg, logging.info)
    for pci_id in vf_pci_id:
        cmd = "ls /sys/bus/pci/devices/%s/net/" % pci_id
        ethname = utils.system_output(cmd).strip()
        ethname_dict.append(ethname)
        network_script = os.path.join("/etc/sysconfig/network-scripts",
                                      "ifcfg-%s" % ethname)
        if not os.path.exists(network_script):
            error.context("Create %s file." % network_script, logging.info)
            txt = "DEVICE=%s\nONBOOT=yes\nBOOTPROTO=dhcp\n" % ethname
            file(network_script, "w").write(txt)

    msg = "Check whether VFs could get ip in host."
    error.context(msg, logging.info)
    for ethname in ethname_dict:
        ifup_down_interface(ethname)
        _ip = check_network_interface_ip(ethname)
        if not _ip:
            msg = "Interface '%s' could not get IP." % ethname
            logging.error(msg)
        else:
            ips[ethname] = _ip
            logging.info("Interface '%s' get IP '%s'", ethname, _ip)

    for i in xrange(repeat_time):
        msg = "Bind/unbind device from host. Repeat %s/%s" % (i + 1,
                                                              repeat_time)
        error.context(msg, logging.info)
        bind_device_num = random.randint(1, device_num)
        pci_assignable.request_devs(devices[:bind_device_num])
        logging.info("Sleep 3s before releasing vf to host.")
        time.sleep(3)
        pci_assignable.release_devs()
        logging.info("Sleep 3s after releasing vf to host.")
        time.sleep(3)
        if device_type == "vf":
            post_device_num = pci_assignable.get_vfs_count()
        else:
            post_device_num = len(pci_assignable.get_pf_vf_info())
        if post_device_num != device_num:
            msg = "lspci cannot report the correct PF/VF number."
            msg += " Correct number is '%s'" % device_num
            msg += " lspci report '%s'" % post_device_num
            raise error.TestFail(msg)
    dmesg = utils.system_output("dmesg")
    file_name = "host_dmesg_after_unbind_device.txt"
    logging.info("Log dmesg after bind/unbing device to '%s'.", file_name)
    utils_misc.log_line(file_name, dmesg)
    msg = "Check whether VFs still get ip in host."
    error.context(msg, logging.info)
    for ethname in ips:
        ifup_down_interface(ethname, action="up")
        _ip = check_network_interface_ip(ethname)
        if not _ip:
            msg = "Interface '%s' could not get IP." % ethname
            msg += "Before bind/unbind it have IP '%s'." % ips[ethname]
            logging.error(msg)
        else:
            logging.info("Interface '%s' get IP '%s'", ethname, _ip)

    msg = "Try to boot up guest(s) with VF(s)."
    error.context(msg, logging.info)
    for vm_name in params["vms"].split(" "):
        params["start_vm"] = "yes"
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        vm.verify_alive()
        vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
Beispiel #4
0
def run(test, params, env):
    """
    SR-IOV devices sanity test:
    1) Bring up VFs by following instructions How To in Setup.
    2) Configure all VFs in host.
    3) Check whether all VFs get ip in host.
    4) Unbind PFs/VFs from host kernel driver to sr-iov driver.
    5) Bind PFs/VFs back to host kernel driver.
    6) Repeat step 4, 5.
    7) Try to boot up guest(s) with VF(s).

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

    device_driver = params.get("device_driver", "pci-assign")
    repeat_time = int(params.get("bind_repeat_time", 1))
    pci_assignable = test_setup.PciAssignable(
        driver=params.get("driver"),
        driver_option=params.get("driver_option"),
        host_set_flag=1,
        kvm_params=params.get("kvm_default"),
        vf_filter_re=params.get("vf_filter_re"),
        pf_filter_re=params.get("pf_filter_re"),
        device_driver=device_driver)

    devices = []
    device_type = params.get("device_type", "vf")
    if device_type == "vf":
        device_num = pci_assignable.get_vfs_count()
        if device_num == 0:
            msg = " No VF device found even after running SR-IOV setup"
            raise error.TestFail(msg)
    elif device_type == "pf":
        device_num = len(pci_assignable.get_pf_vf_info())
    else:
        msg = "Unsupport device type '%s'." % device_type
        msg += " Please set device_type to 'vf' or 'pf'."
        raise error.TestError(msg)

    for i in xrange(device_num):
        device = {}
        device["type"] = device_type
        if device_type == "vf":
            device['mac'] = utils_net.generate_mac_address_simple()
        if params.get("device_name"):
            device["name"] = params.get("device_name")
        devices.append(device)

    pci_assignable.devices = devices
    vf_pci_id = []
    pf_vf_dict = pci_assignable.get_pf_vf_info()
    for pf_dict in pf_vf_dict:
        vf_pci_id.extend(pf_dict["vf_ids"])

    ethname_dict = []
    ips = {}

    msg = "Configure all VFs in host."
    error.context(msg, logging.info)
    for pci_id in vf_pci_id:
        cmd = "ls /sys/bus/pci/devices/%s/net/" % pci_id
        ethname = utils.system_output(cmd).strip()
        ethname_dict.append(ethname)
        network_script = os.path.join("/etc/sysconfig/network-scripts",
                                      "ifcfg-%s" % ethname)
        if not os.path.exists(network_script):
            error.context("Create %s file." % network_script, logging.info)
            txt = "DEVICE=%s\nONBOOT=yes\nBOOTPROTO=dhcp\n" % ethname
            file(network_script, "w").write(txt)

    msg = "Check whether VFs could get ip in host."
    error.context(msg, logging.info)
    for ethname in ethname_dict:
        ifup_down_interface(ethname)
        _ip = check_network_interface_ip(ethname)
        if not _ip:
            msg = "Interface '%s' could not get IP." % ethname
            logging.error(msg)
        else:
            ips[ethname] = _ip
            logging.info("Interface '%s' get IP '%s'", ethname, _ip)

    for i in xrange(repeat_time):
        msg = "Bind/unbind device from host. Repeat %s/%s" % (i + 1,
                                                              repeat_time)
        error.context(msg, logging.info)
        bind_device_num = random.randint(1, device_num)
        pci_assignable.request_devs(devices[:bind_device_num])
        logging.info("Sleep 3s before releasing vf to host.")
        time.sleep(3)
        pci_assignable.release_devs()
        logging.info("Sleep 3s after releasing vf to host.")
        time.sleep(3)
        if device_type == "vf":
            post_device_num = pci_assignable.get_vfs_count()
        else:
            post_device_num = len(pci_assignable.get_pf_vf_info())
        if post_device_num != device_num:
            msg = "lspci cannot report the correct PF/VF number."
            msg += " Correct number is '%s'" % device_num
            msg += " lspci report '%s'" % post_device_num
            raise error.TestFail(msg)
    dmesg = utils.system_output("dmesg")
    file_name = "host_dmesg_after_unbind_device.txt"
    logging.info("Log dmesg after bind/unbing device to '%s'.", file_name)
    utils_misc.log_line(file_name, dmesg)
    msg = "Check whether VFs still get ip in host."
    error.context(msg, logging.info)
    for ethname in ips:
        ifup_down_interface(ethname, action="up")
        _ip = check_network_interface_ip(ethname)
        if not _ip:
            msg = "Interface '%s' could not get IP." % ethname
            msg += "Before bind/unbind it have IP '%s'." % ips[ethname]
            logging.error(msg)
        else:
            logging.info("Interface '%s' get IP '%s'", ethname, _ip)

    msg = "Try to boot up guest(s) with VF(s)."
    error.context(msg, logging.info)
    for vm_name in params["vms"].split(" "):
        params["start_vm"] = "yes"
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        vm.verify_alive()
        vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
Beispiel #5
0
def run(test, params, env):
    """
    KVM whql env setup test:
    1) Log into a guest
    2) Update Windows kernel to the newest version
    3) Un-check Automatically restart in system failure
    4) Disable UAC
    5) Get the symbol files
    6) Set VM to physical memory + 100M
    7) Update the nic configuration
    8) Install debug view and make it auto run

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    log_path = "%s/../debug" % test.resultsdir
    # Prepare the tools iso
    error.context("Prepare the tools iso", logging.info)
    src_list = params.get("src_list")
    src_path = params.get("src_path", "%s/whql_src" % test.tmpdir)
    if not os.path.exists(src_path):
        os.makedirs(src_path)
    if src_list is not None:
        for i in re.split(",", src_list):
            utils.unmap_url(src_path, i, src_path)

    # Make iso for src
    cdrom_whql = params.get("cdrom_whql")
    cdrom_whql = utils_misc.get_path(data_dir.get_data_dir(), cdrom_whql)
    cdrom_whql_dir = os.path.split(cdrom_whql)[0]
    if not os.path.exists(cdrom_whql_dir):
        os.makedirs(cdrom_whql_dir)
    cmd = "mkisofs -J -o %s %s" % (cdrom_whql, src_path)
    utils.system(cmd)
    params["cdroms"] += " whql"

    vm = "vm1"
    vm_params = params.object_params(vm)
    env_process.preprocess_vm(test, vm_params, env, vm)
    vm = env.get_vm(vm)

    timeout = float(params.get("login_timeout", 240))
    session = vm.wait_for_login(timeout=timeout)
    error_log = utils_misc.get_path(log_path, "whql_setup_error_log")
    run_guest_log = params.get(
        "run_guest_log", "%s/whql_qemu_comman" % test.tmpdir)

    # Record qmmu command line in a log file
    error.context("Record qemu command line", logging.info)
    if os.path.isfile(run_guest_log):
        fd = open(run_guest_log, "r+")
        fd.read()
    else:
        fd = open(run_guest_log, "w")
    fd.write("%s\n" % vm.qemu_command)
    fd.close()

    # Get set up commands
    update_cmd = params.get("update_cmd", "")
    timezone_cmd = params.get("timezone_cmd", "")
    auto_restart = params.get("auto_restart", "")
    qxl_install = params.get("qxl_install", "")
    debuggers_install = params.get("debuggers_install", "")
    disable_uas = params.get("disable_uas", "")
    symbol_files = params.get("symbol_files", "")
    vm_size = int(params.get("mem")) + 100
    nic_cmd = params.get("nic_config_cmd", "")
    dbgview_cmd = params.get("dbgview_cmd", "")
    format_cmd = params.get("format_cmd", "")
    disable_firewall = params.get("disable_firewall", "")
    disable_update = params.get("disable_update", "")
    setup_timeout = int(params.get("setup_timeout", "7200"))
    disk_init_cmd = params.get("disk_init_cmd", "")
    disk_driver_install = params.get("disk_driver_install", "")

    vm_ma_cmd = "wmic computersystem set AutomaticManagedPagefile=False"
    vm_cmd = "wmic pagefileset where name=\"C:\\\\pagefile.sys\" set "
    vm_cmd += "InitialSize=%s,MaximumSize=%s" % (vm_size, vm_size)
    vm_ma_cmd = ""
    vm_cmd = ""
    if symbol_files:
        symbol_cmd = "del  C:\\\\symbols &&"
        symbol_cmd += "git clone %s C:\\\\symbol_files C:\\\\symbols" % \
                      symbol_files
    else:
        symbol_cmd = ""
    wmic_prepare_cmd = "echo exit > cmd && cmd /s wmic"

    error.context("Configure guest system", logging.info)
    cmd_list = [wmic_prepare_cmd, auto_restart, disable_uas, symbol_cmd,
                vm_ma_cmd, vm_cmd, dbgview_cmd, qxl_install, disable_firewall,
                timezone_cmd]
    if nic_cmd:
        for index, nic in enumerate(re.split("\s+", params.get("nics"))):
            setup_params = params.get("nic_setup_params_%s" % nic, "")
            if params.get("vm_arch_name", "") == "x86_64":
                nic_cmd = re.sub("set", "set_64", nic_cmd)
            cmd_list.append("%s %s %s" % (nic_cmd, str(index + 1),
                                          setup_params))
    if disk_init_cmd:
        disk_num = len(re.split("\s+", params.get("images")))
        if disk_driver_install:
            cmd_list.append(disk_driver_install + str(disk_num - 1))
        labels = "IJKLMNOPQRSTUVWXYZ"
        for index, images in enumerate(re.split("\s+", params.get("images"))):
            if index > 0:
                cmd_list.append(disk_init_cmd % (str(index),
                                                 labels[index - 1]))
                format_cmd_image = format_cmd % (labels[index - 1],
                                                 params.get("win_format_%s" % images))
                if params.get("win_extra_%s" % images):
                    format_cmd_image += " %s" % params.get(
                        "win_extra_%s" % images)
                cmd_list.append(format_cmd_image)

    cmd_list += [update_cmd, disable_update]

    failed_flag = 0

    # Check symbol files in guest
    if symbol_files:
        error.context("Update symbol files", logging.info)
        install_check_tool = False
        check_tool_chk = params.get("check_tool_chk",
                                    "C:\debuggers\symchk.exe")
        output = session.cmd_output(check_tool_chk)
        if "cannot find" in output:
            install_check_tool = True

        if install_check_tool:
            output = session.cmd_output(debuggers_install)
        symbol_file_check = params.get("symbol_file_check")
        symbol_file_download = params.get("symbol_file_download")

        symbol_check_pattern = params.get("symbol_check_pattern")
        symbol_pid_pattern = params.get("symbol_pid_pattern")
        download = utils_test.BackgroundTest(session.cmd,
                                            (symbol_file_download,
                                             setup_timeout))

        sessioncheck = vm.wait_for_login(timeout=timeout)
        download.start()
        while download.is_alive():
            o = sessioncheck.cmd_output(symbol_file_check, setup_timeout)
            if symbol_check_pattern in o:
                # Check is done kill download process
                cmd = "tasklist /FO list"
                s, o = sessioncheck.cmd_status_output(cmd)
                pid = re.findall(symbol_pid_pattern, o, re.S)
                if pid:
                    cmd = "taskkill /PID %s /F" % pid[0]
                    try:
                        sessioncheck.cmd(cmd)
                    except Exception:
                        pass
                    break
            time.sleep(5)
        sessioncheck.close()
        download.join()

    for cmd in cmd_list:
        if len(cmd) > 0:
            s = 0
            try:
                s, o = session.cmd_status_output(cmd, timeout=setup_timeout)
            except Exception, err:
                failed_flag += 1
                utils_misc.log_line(
                    error_log, "Unexpected exception: %s" % err)
            if s != 0:
                failed_flag += 1
                utils_misc.log_line(error_log, o)