Example #1
0
 def run_background_test(self):
     """Run virt sub test in backgroup"""
     wait_time = float(self.params.get("sub_test_wait_time", 0))
     args = (self.test, self.params, self.env, self.params["sub_type"])
     bg_test = BackgroundTest(run_virt_sub_test, args)
     bg_test.start()
     wait_for(bg_test.is_alive, first=wait_time, step=3, timeout=240)
     return bg_test
Example #2
0
 def run_background_test(self):
     """Run virt sub test in backgroup"""
     wait_time = float(self.params.get("sub_test_wait_time", 0))
     args = (self.test, self.params, self.env, self.params["sub_type"])
     bg_test = BackgroundTest(run_virt_sub_test, args)
     bg_test.start()
     wait_for(bg_test.is_alive, first=wait_time, step=3, timeout=240)
     return bg_test
Example #3
0
 def _usb_stick_io(mount_point, bg=False):
     """
     Do I/O operations on passthrough usb stick
     """
     error_context.context("Read and write on usb stick ", logging.info)
     testfile = os.path.join(mount_point, 'testfile')
     if bg:
         iozone_cmd = params.get("iozone_cmd_bg", " -az -I -g 1g -f %s")
         iozone_thread = BackgroundTest(iozone_test.run,
                                        (iozone_cmd % testfile, ))
         iozone_thread.start()
         if not utils_misc.wait_for(iozone_thread.is_alive, timeout=10):
             test.fail("Fail to start the iozone background test.")
         time.sleep(10)
     else:
         iozone_cmd = params.get("iozone_cmd",
                                 " -a -I -r 64k -s 1m -i 0 -i 1 -f %s")
         iozone_test.run(iozone_cmd % testfile)
Example #4
0
 def run_stress():
     """
     Run stress inside guest, return guest cpu usage
     """
     error_context.context("Run stress in guest and get cpu usage",
                           logging.info)
     if os_type == "linux":
         stress_args = params["stress_args"]
         stress_test = utils_test.VMStress(vm,
                                           "stress",
                                           params,
                                           stress_args=stress_args)
         try:
             stress_test.load_stress_tool()
             time.sleep(stress_duration / 2)
             output = session.cmd_output_safe(params["get_cpu_usage_cmd"])
             utils_misc.wait_for(lambda: (stress_test.app_running is False),
                                 30)
             stress_test.unload_stress()
             cpu_usage = re.findall(r":\s*(\d+.?\d+)\s*us", output)
             cpu_usage = [float(x) for x in cpu_usage]
             logging.info("Guest cpu usage is %s", cpu_usage)
             unloaded_cpu = [x for x in cpu_usage if x < 20]
             if unloaded_cpu:
                 test.fail("CPU(s) load percentage is less than 20%")
         finally:
             stress_test.clean()
     else:
         install_path = params["install_path"]
         heavyload_install(install_path)
         error_context.context("Run heavyload inside guest.", logging.info)
         heavyload_bin = r'"%s\heavyload.exe" ' % install_path
         heavyload_options = [
             "/CPU %d" % vm.cpuinfo.smp,
             "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
         ]
         start_cmd = heavyload_bin + " ".join(heavyload_options)
         stress_tool = BackgroundTest(
             session.cmd, (start_cmd, stress_duration, stress_duration))
         stress_tool.start()
         if not utils_misc.wait_for(stress_tool.is_alive, stress_duration):
             test.error("Failed to start heavyload process.")
         stress_tool.join(stress_duration)
Example #5
0
    def run_stress():
        def heavyload_install():
            if session.cmd_status(test_install_cmd) != 0:
                logging.warning("Could not find installed heavyload in guest, "
                                "will install it via winutils.iso ")
                winutil_drive = utils_misc.get_winutils_vol(session)
                if not winutil_drive:
                    test.cancel("WIN_UTILS CDROM not found.")
                install_cmd = params["install_cmd"] % winutil_drive
                session.cmd(install_cmd)

        logging.info('Loading stress on guest.')
        stress_duration = params.get("stress_duration", 60)
        if params["os_type"] == "linux":
            params['stress_args'] = '--vm %s --vm-bytes 256M --timeout %s' % (
                mem // 512, stress_duration)
            stress = utils_test.VMStress(vm, 'stress', params)
            stress.load_stress_tool()
            time.sleep(stress_duration)
            stress.unload_stress()
        else:
            session = vm.wait_for_login()
            install_path = params["install_path"]
            test_install_cmd = 'dir "%s" | findstr /I heavyload' % install_path
            heavyload_install()
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = [
                "/MEMORY 100",
                "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
            ]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(
                session.cmd, (start_cmd, stress_duration, stress_duration))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, 30):
                test.error("Failed to start heavyload process")
            stress_tool.join(stress_duration)
Example #6
0
 def run_background_test(self):
     args = (self.test, self.params, self.env, self.params["sub_type"])
     bg_test = BackgroundTest(run_virt_sub_test, args)
     bg_test.start()
     wait_for(bg_test.is_alive, first=10, step=3, timeout=100)
     return bg_test
Example #7
0
def run(test, params, env):
    """
    Qemu hugepage memory stress test.
    Steps:
    1) System setup hugepages on host.
    2) Mount this hugepage to /mnt/kvm_hugepage.
    3) HugePages didn't leak when using non-existent mem-path.
    4) Run memory heavy stress inside guest.
    5) Check guest call trace in dmesg log.
    :params test: QEMU test object.
    :params params: Dictionary with the test parameters.
    :params env: Dictionary with test environment.
    """
    def heavyload_install():
        if session.cmd_status(test_installed_cmd) != 0:
            logging.warning("Could not find installed heavyload in guest, will"
                            " install it via winutils.iso ")
            winutil_drive = utils_misc.get_winutils_vol(session)
            if not winutil_drive:
                test.cancel("WIN_UTILS CDROM not found.")
            install_cmd = params["install_cmd"] % winutil_drive
            session.cmd(install_cmd)

    if params.get_boolean("non_existent_point"):
        dir = tempfile.mkdtemp(prefix='hugepage_')
        error_context.context("This path %s, doesn't mount hugepage." %
                              dir, logging.info)
        params["extra_params"] = " -mem-path %s" % dir
        params["start_vm"] = "yes"
        env_process.preprocess_vm(test, params, env, params["main_vm"])

    os_type = params["os_type"]
    stress_duration = params.get_numeric("stress_duration", 60)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()

    try:
        error_context.context("Run memory heavy stress in guest", logging.info)
        if os_type == "linux":
            stress_args = params["stress_custom_args"] % (
                    params.get_numeric("mem") / 512)
            stress_test = utils_test.VMStress(vm, "stress",
                                              params, stress_args=stress_args)
            try:
                stress_test.load_stress_tool()
                utils_misc.wait_for(lambda: (stress_test.app_running is False), 30)
                stress_test.unload_stress()
                utils_misc.verify_dmesg(session=session)
            finally:
                stress_test.clean()
        else:
            install_path = params["install_path"]
            test_installed_cmd = 'dir "%s" | findstr /I heavyload' % install_path
            heavyload_install()
            error_context.context("Run heavyload inside guest.", logging.info)
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = ["/MEMORY %d" % (params.get_numeric("mem") / 512),
                                 "/DURATION %d" % (stress_duration // 60),
                                 "/AUTOEXIT",
                                 "/START"]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(session.cmd, (start_cmd,
                                                       stress_duration, stress_duration))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, stress_duration):
                test.error("Failed to start heavyload process.")
            stress_tool.join(stress_duration)

        if params.get_boolean("non_existent_point"):
            error_context.context("Check large memory pages free on host.",
                                  logging.info)
            if utils_memory.get_num_huge_pages() != utils_memory.get_num_huge_pages_free():
                test.fail("HugePages leaked.")
    finally:
        session.close()
Example #8
0
    def check_ksm(mem, threshold_reached=False):
        """
        :param mem: Boot guest with given memory, in KB
        :ksmtuned_enabled: ksmtuned threshold is reached or not
        """
        def heavyload_install():
            if session.cmd_status(test_install_cmd) != 0:
                logging.warning("Could not find installed heavyload in guest, "
                                "will install it via winutils.iso ")
                winutil_drive = utils_misc.get_winutils_vol(session)
                if not winutil_drive:
                    test.cancel("WIN_UTILS CDROM not found.")
                install_cmd = params["install_cmd"] % winutil_drive
                session.cmd(install_cmd)

        def check_qemu_used_mem(qemu_pid, mem):
            qemu_used_page = process.getoutput(get_qemu_used_mem % qemu_pid,
                                               shell=True)
            qemu_used_mem = float(qemu_used_page) * pagesize
            if qemu_used_mem < mem * mem_thres:
                return False
            return True

        params['mem'] = mem // 1024
        params['start_vm'] = 'yes'
        vm_name = params['main_vm']
        env_process.preprocess_vm(test, params, env, vm_name)
        vm = env.get_vm(vm_name)
        session = vm.wait_for_login()
        qemu_pid = vm.get_pid()
        if params["os_type"] == "linux":
            params['stress_args'] = ('--cpu 4 --io 4 --vm 2 --vm-bytes %sM' %
                                     (int(params['mem']) // 2))
            stress_test = VMStress(vm, "stress", params)
            stress_test.load_stress_tool()
        else:
            install_path = params["install_path"]
            test_install_cmd = 'dir "%s" | findstr /I heavyload' % install_path
            heavyload_install()
            heavyload_bin = r'"%s\heavyload.exe" ' % install_path
            heavyload_options = ["/MEMORY 100", "/START"]
            start_cmd = heavyload_bin + " ".join(heavyload_options)
            stress_tool = BackgroundTest(
                session.cmd, (start_cmd, stress_timeout, stress_timeout))
            stress_tool.start()
            if not utils_misc.wait_for(stress_tool.is_alive, stress_timeout):
                test.error("Failed to start heavyload process")
        if not utils_misc.wait_for(lambda: check_qemu_used_mem(qemu_pid, mem),
                                   stress_timeout, 10, 10):
            test.error("QEMU used memory doesn't reach %s of guest mem %sM in "
                       "%ss" % (mem_thres, mem // 1024, stress_timeout))
        time.sleep(30)
        free_mem_host = utils_memory.freememtotal()
        ksm_status = process.getoutput(params['cmd_check_ksm_status'])
        vm.destroy()
        logging.info(
            "The ksm threshold is %sM, QEMU used memory is %sM, "
            "and the total free memory on host is %sM", ksm_thres // 1024,
            mem // 1024, free_mem_host // 1024)
        if threshold_reached:
            if free_mem_host > ksm_thres:
                test.error("Host memory is not consumed as much as expected")
            if ksm_status == '0':
                test.fail("KSM should be running")
        else:
            if free_mem_host < ksm_thres:
                test.error("Host memory is consumed too much more than "
                           "expected")
            if ksm_status != '0':
                test.fail("KSM should not be running")
Example #9
0
 def run_background_test(self):
     args = (self.test, self.params, self.env, self.params["sub_type"])
     bg_test = BackgroundTest(run_virt_sub_test, args)
     bg_test.start()
     wait_for(bg_test.is_alive, first=10, step=3, timeout=100)
     return bg_test
def run(test, params, env):
    """
    Test hotplug vcpu devices and execute stress test.

    1) Boot up guest without vcpu device.
    2) Hotplug vcpu devices and check successfully or not. (qemu side)
    3) Check if the number of CPUs in guest changes accordingly. (guest side)
    4) Execute stress test on all hotplugged vcpu devices
    5) Hotunplug vcpu devices during stress test
    6) Recheck the number of CPUs in guest.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    def heavyload_install():
        if session.cmd_status(test_installed_cmd) != 0:
            logging.warning("Could not find installed heavyload in guest, will"
                            " install it via winutils.iso ")
            winutil_drive = utils_misc.get_winutils_vol(session)
            if not winutil_drive:
                test.cancel("WIN_UTILS CDROM not found.")
            install_cmd = params["install_cmd"] % winutil_drive
            session.cmd(install_cmd)

    os_type = params["os_type"]
    vm_arch_name = params.get('vm_arch_name', arch.ARCH)
    login_timeout = params.get_numeric("login_timeout", 360)
    stress_duration = params.get_numeric("stress_duration", 180)
    verify_wait_timeout = params.get_numeric("verify_wait_timeout", 60)
    vcpu_devices = params.objects("vcpu_devices")
    vcpus_count = params.get_numeric("vcpus_count", 1)
    pluggable_count = len(vcpu_devices) * vcpus_count

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login(timeout=login_timeout)
    if not cpu_utils.check_if_vm_vcpu_match(vm.cpuinfo.smp, vm):
        test.error("The number of guest CPUs is not equal to the qemu command "
                   "line configuration")

    cpu_count_before_test = vm.get_cpu_count()
    expected_count = pluggable_count + cpu_count_before_test
    guest_cpu_ids = cpu_utils.get_guest_cpu_ids(session, os_type)
    for vcpu_dev in vcpu_devices:
        error_context.context("Hotplug vcpu device: %s" % vcpu_dev,
                              logging.info)
        vm.hotplug_vcpu_device(vcpu_dev)
    if not utils_misc.wait_for(
            lambda: cpu_utils.check_if_vm_vcpu_match(expected_count, vm),
            verify_wait_timeout):
        test.fail("Actual number of guest CPUs is not equal to expected")

    if os_type == "linux":
        stress_args = params["stress_args"]
        stress_tool = cpu_utils.VMStressBinding(vm,
                                                params,
                                                stress_args=stress_args)
        current_guest_cpu_ids = cpu_utils.get_guest_cpu_ids(session, os_type)
        plugged_cpu_ids = list(current_guest_cpu_ids - guest_cpu_ids)
        plugged_cpu_ids.sort()
        for cpu_id in plugged_cpu_ids:
            error_context.context(
                "Run stress on vCPU(%d) inside guest." % cpu_id, logging.info)
            stress_tool.load_stress_tool(cpu_id)
        error_context.context(
            "Successfully launched stress sessions, execute "
            "stress test for %d seconds" % stress_duration, logging.info)
        time.sleep(stress_duration)
        if utils_package.package_install("sysstat", session):
            error_context.context("Check usage of guest CPUs", logging.info)
            mpstat_cmd = "mpstat 1 5 -P %s | cat" % ",".join(
                map(str, plugged_cpu_ids))
            mpstat_out = session.cmd_output(mpstat_cmd)
            cpu_stat = dict(
                re.findall(r"Average:\s+(\d+)\s+(\d+\.\d+)", mpstat_out, re.M))
            for cpu_id in plugged_cpu_ids:
                cpu_usage_rate = float(cpu_stat[str(cpu_id)])
                if cpu_usage_rate < 50:
                    test.error("Stress test on vCPU(%s) failed, usage rate: "
                               "%.2f%%" % (cpu_id, cpu_usage_rate))
                logging.info("Usage rate of vCPU(%s) is: %.2f%%", cpu_id,
                             cpu_usage_rate)
        if not vm_arch_name.startswith("s390"):
            for vcpu_dev in vcpu_devices:
                error_context.context("Hotunplug vcpu device: %s" % vcpu_dev,
                                      logging.info)
                vm.hotunplug_vcpu_device(vcpu_dev)
                # Drift the running stress task to other vCPUs
                time.sleep(random.randint(5, 10))
            if not cpu_utils.check_if_vm_vcpu_match(cpu_count_before_test, vm):
                test.fail("Actual number of guest CPUs is not equal to "
                          "expected")
        stress_tool.unload_stress()
        stress_tool.clean()
    else:
        install_path = params["install_path"]
        test_installed_cmd = 'dir "%s" | findstr /I heavyload' % install_path
        heavyload_install()
        error_context.context("Run heavyload inside guest.", logging.info)
        heavyload_bin = r'"%s\heavyload.exe" ' % install_path
        heavyload_options = [
            "/CPU %d" % expected_count,
            "/DURATION %d" % (stress_duration // 60), "/AUTOEXIT", "/START"
        ]
        start_cmd = heavyload_bin + " ".join(heavyload_options)
        stress_tool = BackgroundTest(
            session.cmd, (start_cmd, stress_duration, stress_duration))
        stress_tool.start()
        if not utils_misc.wait_for(
                stress_tool.is_alive, verify_wait_timeout, first=5):
            test.error("Failed to start heavyload process.")
        stress_tool.join(stress_duration)

    session.close()