コード例 #1
0
ファイル: balloon_service.py プロジェクト: dagrh/tp-qemu
    def balloon_memory(session, device_path):
        """
        Doing memory balloon in a loop and check memory status during balloon.

        :param session: VM session.
        :param device_path: balloon polling path.
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d" % repeat_times)
        balloon_test = BallooningTestWin(test, params, env)

        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                min_sz, max_sz = balloon_test.get_memory_boundary(balloon_type)
                expect_mem = int(random.uniform(min_sz, max_sz))

                quit_after_test = balloon_test.run_ballooning_test(expect_mem, tag)
                get_polling_output = vm.monitor.qom_get(device_path, get_balloon_property)
                memory_check(vm, get_polling_output, 'stat-free-memory')
                if quit_after_test:
                    return

            balloon_test.reset_memory()
            repeat_times -= 1
コード例 #2
0
ファイル: balloon_minimum.py プロジェクト: ldoktor/tp-qemu
def run(test, params, env):
    """
    Balloon negative test, balloon windows guest memory to very small value.
    1) boot a guest with balloon device.
    2) enable and check driver verifier in guest.
    3) evict guest memory to 10M.
    4) repeat step 3 for many times.
    5) check guest free memory.

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

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()
    driver_name = params.get("driver_name", "balloon")
    session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                            test, driver_name)
    balloon_test = BallooningTestWin(test, params, env)
    expect_mem = int(params["expect_memory"])
    repeat_times = int(params.get("repeat_times", 10))

    while repeat_times:
        try:
            balloon_test.vm.balloon(expect_mem)
        except QMPEventError:
            pass
        balloon_test._balloon_post_action()
        time.sleep(30)
        repeat_times -= 1
    ballooned_memory = balloon_test.ori_mem - expect_mem
    balloon_test.memory_check("after balloon guest memory 10 times", ballooned_memory)
    session.close()
コード例 #3
0
ファイル: balloon_stress.py プロジェクト: CongLi/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play online video in guest
    6) balloon memory in monitor in loop
    7) check vm alive

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

    error.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    default_memory = int(params.get("default_memory", params['mem']))
    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)
    # for media player configuration
    if params.get("pre_cmd"):
        session.cmd(params.get("pre_cmd"))

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)
    balloon_test = BallooningTestWin(test, params, env)

    error.context("Play video in guest", logging.info)
    play_video_cmd = params["play_video_cmd"]
    session.sendline(play_video_cmd)
    # need to wait for wmplayer loading remote video
    time.sleep(float(params.get("loading_timeout", 60)))
    check_playing_cmd = params["check_playing_cmd"]
    running = utils_misc.wait_for(lambda: utils_misc.get_guest_cmd_status_output(
        vm, check_playing_cmd)[0] == 0, first=5.0, timeout=600)
    if not running:
        raise error.TestError("Video is not playing")

    #for case:balloon_in_use to call
    env["balloon_test"] = 0
    error.context("balloon vm memory in loop", logging.info)
    repeat_times = int(params.get("repeat_times", 10))
    logging.info("repeat times: %d" % repeat_times)
    min_sz, max_sz = balloon_test.get_memory_boundary()
    while repeat_times:
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
        env["balloon_test"] = 1
        repeat_times -= 1

    error.context("verify guest still alive", logging.info)
    session.cmd(params["stop_player_cmd"])
    vm.verify_alive()
    if session:
        session.close()
コード例 #4
0
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play online video in guest
    6) balloon memory in monitor in loop
    7) check vm alive

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

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)
    balloon_test = BallooningTestWin(test, params, env)

    video_play = utils_misc.InterruptedThread(
        utils_test.run_virt_sub_test, (test, params, env),
        {"sub_type": params.get("sub_test")})
    video_play.start()
    error_context.context("Run video background", logging.info)
    check_playing_cmd = params["check_playing_cmd"]
    running = utils_misc.wait_for(
        lambda: utils_misc.get_guest_cmd_status_output(vm, check_playing_cmd)[
            0] == 0,
        first=60,
        timeout=600)
    if not running:
        raise exceptions.TestError("Video is not playing")

    error_context.context("balloon vm memory in loop", logging.info)
    repeat_times = int(params.get("repeat_times", 10))
    logging.info("repeat times: %d" % repeat_times)
    min_sz, max_sz = balloon_test.get_memory_boundary()
    while repeat_times:
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
        repeat_times -= 1

    error_context.context("verify guest still alive", logging.info)
    vm.verify_alive()
    if session:
        session.close()
コード例 #5
0
ファイル: balloon_stress.py プロジェクト: EIChaoYang/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play video in background repeatly
    6) balloon memory in monitor in loop

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

    def run_video():
        """
        Run video in background
        """
        while True:
            utils_test.run_virt_sub_test(test, params, env,
                                         params.get("video_test"))

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)

    error_context.context("Run video background", logging.info)
    bg = utils_misc.InterruptedThread(run_video)
    bg.start()

    repeat_times = int(params.get("repeat_times", 500))
    balloon_test = BallooningTestWin(test, params, env)
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in xrange(1, int(repeat_times+1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not bg.is_alive():
                test.error("Background video process is not playing")
    finally:
        if session:
            session.close()
コード例 #6
0
ファイル: balloon_stress.py プロジェクト: PandaWei/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play online video in guest
    6) balloon memory in monitor in loop
    7) check vm alive

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

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)
    balloon_test = BallooningTestWin(test, params, env)

    video_play = utils_misc.InterruptedThread(
        utils_test.run_virt_sub_test, (test, params, env),
        {"sub_type": params.get("sub_test")})
    video_play.start()
    error_context.context("Run video background", logging.info)
    check_playing_cmd = params["check_playing_cmd"]
    running = utils_misc.wait_for(
        lambda: utils_misc.get_guest_cmd_status_output(
            vm, check_playing_cmd)[0] == 0, first=60, timeout=600)
    if not running:
        raise exceptions.TestError("Video is not playing")

    error_context.context("balloon vm memory in loop", logging.info)
    repeat_times = int(params.get("repeat_times", 10))
    logging.info("repeat times: %d" % repeat_times)
    min_sz, max_sz = balloon_test.get_memory_boundary()
    while repeat_times:
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
        repeat_times -= 1

    error_context.context("verify guest still alive", logging.info)
    vm.verify_alive()
    if session:
        session.close()
コード例 #7
0
ファイル: balloon_stress.py プロジェクト: morecache/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play video in background repeatly
    6) balloon memory in monitor in loop

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def run_video():
        """
        Run video in background
        """
        while True:
            utils_test.run_virt_sub_test(test, params, env,
                                         params.get("video_test"))

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)

    error_context.context("Run video background", logging.info)
    bg = utils_misc.InterruptedThread(run_video)
    bg.start()

    repeat_times = int(params.get("repeat_times", 500))
    balloon_test = BallooningTestWin(test, params, env)
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in xrange(1, int(repeat_times + 1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not bg.is_alive():
                test.error("Background video process is not playing")
    finally:
        if session:
            session.close()
コード例 #8
0
def run(test, params, env):
    """
    Balloon service should be in running status after sc interrogate it.
    1) boot a guest with balloon device.
    2) check balloon driver installation status.
    3) enable and check driver verifier in guest.
    4) install and start balloon service in guest.
    5) send INTERROGATE signal to balloon service.
    6) check balloon service status again.
    """
    def interrogate_balloon_service(session):
        """
        Sending INTERROGATE to balloon service.
        :param session: VM session.
        """
        logging.info("Send INTERROGATE to balloon service")
        sc_interrogate_cmd = params["sc_interrogate_cmd"]
        status, output = session.cmd_status_output(sc_interrogate_cmd)
        if status:
            test.error(output)

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()
    driver_name = params.get("driver_name", "balloon")

    session = utils_test.qemu.windrv_check_running_verifier(
        session, vm, test, driver_name)
    balloon_test = BallooningTestWin(test, params, env)
    err = None
    try:
        # Install and start balloon service in guest
        balloon_test.configure_balloon_service(session)

        # Send INTERROGATE signal to balloon service
        interrogate_balloon_service(session)

        # Check ballloon serivce status again
        output = balloon_test.operate_balloon_service(session, "status")
        if not re.search("running", output.lower(), re.M):
            test.fail("Balloon service is not running after sc interrogate!"
                      "Output is: \n %s" % output)
    except Exception as err:
        pass

    finally:
        try:
            error_context.context("Clear balloon service in guest",
                                  logging.info)
            balloon_test.operate_balloon_service(session, "uninstall")
        except Exception as uninst_err:
            if not err:
                err = uninst_err
            else:
                logging.error(uninst_err)
        session.close()
        if err:
            raise err  # pylint: disable=E0702
コード例 #9
0
    def enable_balloon_service():
        """
        Install balloon service and check its status in windows guests
        """
        if params['os_type'] != 'windows':
            return
        error_context.context("Install and check balloon service in windows "
                              "guest", logging.info)
        session = vm.wait_for_login()
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(session,
                                                                vm, test,
                                                                driver_name)
        balloon_test = BallooningTestWin(test, params, env)
        balloon_test.configure_balloon_service(session)

        output = balloon_test.operate_balloon_service(session, "status")
        if not re.search(r"running", output.lower(), re.M):
            test.error("Ballooon service status is not running")
        session.close()
コード例 #10
0
    def balloon_memory(session, device_path):
        """
        Doing memory balloon in a loop and check memory status during balloon.

        :param session: VM session.
        :param device_path: balloon polling path.
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d" % repeat_times)
        balloon_test = BallooningTestWin(test, params, env)

        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                min_sz, max_sz = balloon_test.get_memory_boundary(balloon_type)
                expect_mem = int(random.uniform(min_sz, max_sz))

                quit_after_test = balloon_test.run_ballooning_test(expect_mem,
                                                                   tag)
                get_polling_output = vm.monitor.qom_get(device_path,
                                                        get_balloon_property)
                memory_check(vm, get_polling_output, 'stat-free-memory')
                if quit_after_test:
                    return

            balloon_test.reset_memory()
            repeat_times -= 1
コード例 #11
0
def run(test, params, env):
    """
    Balloon service should be in running status after sc interrogate it.
    1) boot a guest with balloon device.
    2) check balloon driver installation status.
    3) enable and check driver verifier in guest.
    4) install and start balloon service in guest.
    5) send INTERROGATE signal to balloon service.
    6) check balloon service status again.
    """

    def interrogate_balloon_service(session):
        """
        Sending INTERROGATE to balloon service.
        :param session: VM session.
        """
        logging.info("Send INTERROGATE to balloon service")
        sc_interrogate_cmd = params["sc_interrogate_cmd"]
        status, output = session.cmd_status_output(sc_interrogate_cmd)
        if status:
            test.error(output)

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()
    driver_name = params.get("driver_name", "balloon")

    session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                            test, driver_name)
    balloon_test = BallooningTestWin(test, params, env)
    err = None
    try:
        # Install and start balloon service in guest
        balloon_test.configure_balloon_service(session)

        # Send INTERROGATE signal to balloon service
        interrogate_balloon_service(session)

        # Check ballloon serivce status again
        output = balloon_test.operate_balloon_service(session, "status")
        if not re.search("running", output.lower(), re.M):
            test.fail("Balloon service is not running after sc interrogate!"
                      "Output is: \n %s" % output)
    except Exception as err:
        pass

    finally:
        try:
            error_context.context("Clear balloon service in guest", logging.info)
            balloon_test.operate_balloon_service(session, "uninstall")
        except Exception as uninst_err:
            if not err:
                err = uninst_err
            else:
                logging.error(uninst_err)
        session.close()
        if err:
            raise err   # pylint: disable=E0702
コード例 #12
0
ファイル: balloon_stress.py プロジェクト: prudmirya/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest (Windows only)
    3) run stress in background repeatly
    4) balloon memory in monitor in loop

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

    def run_stress(test, params, env, vm):
        """
        Run stress in background
        """
        while True:
            if params['os_type'] == 'windows':
                utils_test.run_virt_sub_test(test, params, env,
                                             params.get("stress_test"))
            else:
                stress_bg = utils_test.VMStress(vm, "stress", params)
                stress_bg.load_stress_tool()

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    if params['os_type'] == 'windows':
        driver_name = params["driver_name"]
        session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                                test, driver_name,
                                                                timeout)
        balloon_test = BallooningTestWin(test, params, env)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    error_context.context("Run stress background", logging.info)
    bg = utils_misc.InterruptedThread(run_stress, (test, params, env, vm))
    bg.start()

    repeat_times = int(params.get("repeat_times", 1000))
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in range(1, int(repeat_times+1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not bg.is_alive():
                test.error("Background stress process is not alive")
    finally:
        if session:
            session.close()
コード例 #13
0
ファイル: balloon_minimum.py プロジェクト: liuyd96/tp-qemu
def run(test, params, env):
    """
    Balloon negative test, balloon windows guest memory to very small value.
    1) boot a guest with balloon device.
    2) enable and check driver verifier in guest.
    3) evict guest memory to 10M.
    4) repeat step 3 for many times.
    5) check guest free memory.

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

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()
    driver_name = params.get("driver_name", "balloon")
    session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                            test, driver_name)
    balloon_test = BallooningTestWin(test, params, env)
    expect_mem = int(params["expect_memory"])
    balloon_test.pre_mem = balloon_test.get_ballooned_memory()
    balloon_test.pre_gmem = balloon_test.get_memory_status()
    repeat_times = int(params.get("repeat_times", 10))

    while repeat_times:
        try:
            balloon_test.vm.balloon(expect_mem)
        except QMPEventError:
            pass
        balloon_test._balloon_post_action()
        time.sleep(30)
        repeat_times -= 1

    ballooned_memory = expect_mem - balloon_test.pre_mem
    balloon_test.memory_check("after balloon guest memory 10 times", ballooned_memory)
    session.close()
コード例 #14
0
    def balloon_memory(vm, device_path, mem_check):
        """
        Doing memory balloon in a loop and check memory status during balloon.

        :param vm: VM object.
        :param device_path: balloon polling path.
        :param mem_check: need to do memory check if param mem_check is 'yes'
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d" % repeat_times)

        if params['os_type'] == 'windows':
            balloon_test = BallooningTestWin(test, params, env)
        else:
            balloon_test = BallooningTestLinux(test, params, env)
        min_sz, max_sz = balloon_test.get_memory_boundary()
        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                if balloon_type == 'evict':
                    expect_mem = int(
                        random.uniform(min_sz,
                                       balloon_test.get_ballooned_memory()))
                else:
                    expect_mem = int(
                        random.uniform(balloon_test.get_ballooned_memory(),
                                       max_sz))

                quit_after_test = balloon_test.run_ballooning_test(
                    expect_mem, tag)
                time.sleep(20)
                get_polling_output = vm.monitor.qom_get(
                    device_path, get_balloon_property)
                time.sleep(20)
                if mem_check == "yes":
                    memory_check(vm, get_polling_output, 'stat-free-memory')
                if quit_after_test:
                    return

            repeat_times -= 1
コード例 #15
0
ファイル: balloon_service.py プロジェクト: Zhengtong/tp-qemu
    def balloon_memory(vm, device_path, mem_check):
        """
        Doing memory balloon in a loop and check memory status during balloon.

        :param vm: VM object.
        :param device_path: balloon polling path.
        :param mem_check: need to do memory check if param mem_check is 'yes'
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d" % repeat_times)

        if params['os_type'] == 'windows':
            balloon_test = BallooningTestWin(test, params, env)
        else:
            balloon_test = BallooningTestLinux(test, params, env)
        min_sz, max_sz = balloon_test.get_memory_boundary()
        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                if balloon_type == 'evict':
                    expect_mem = int(random.uniform(min_sz,
                                                    balloon_test.get_ballooned_memory()))
                else:
                    expect_mem = int(random.uniform(
                        balloon_test.get_ballooned_memory(), max_sz))

                quit_after_test = balloon_test.run_ballooning_test(expect_mem,
                                                                   tag)
                time.sleep(20)
                get_polling_output = vm.monitor.qom_get(device_path,
                                                        get_balloon_property)
                time.sleep(20)
                if mem_check == "yes":
                    memory_check(vm, get_polling_output, 'stat-free-memory')
                if quit_after_test:
                    return

            repeat_times -= 1
コード例 #16
0
ファイル: balloon_stress.py プロジェクト: ldoktor/tp-qemu
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest (Windows only)
    3) run stress in background repeatly
    4) balloon memory in monitor in loop

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

    def check_bg_running():
        """
        Check the background test status in guest.
        :return: return True if find the process name; otherwise False
        """
        if params['os_type'] == 'windows':
            list_cmd = params.get("list_cmd", "wmic process get name")
            output = session.cmd_output_safe(list_cmd, timeout=60)
            process = re.findall("mplayer", output, re.M | re.I)
            return bool(process)
        else:
            return stress_bg.app_running()

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    if params['os_type'] == 'windows':
        driver_name = params["driver_name"]
        session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                                test, driver_name,
                                                                timeout)
        balloon_test = BallooningTestWin(test, params, env)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    error_context.context("Run stress background", logging.info)
    stress_test = params.get("stress_test")
    if params['os_type'] == 'windows':
        utils_test.run_virt_sub_test(test, params, env, stress_test)
        if not utils_misc.wait_for(check_bg_running, first=2.0,
                                   text="wait for stress app to start",
                                   step=1.0, timeout=60):
            test.error("Run stress background failed")
    else:
        stress_bg = utils_test.VMStress(vm, "stress", params)
        stress_bg.load_stress_tool()

    repeat_times = int(params.get("repeat_times", 1000))
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in range(1, int(repeat_times+1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not check_bg_running():
                test.error("Background stress process is not alive")
    finally:
        if session:
            session.close()
コード例 #17
0
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest
    3) reboot guest (optional)
    4) check device using right driver in guest.
    5) play online video in guest
    6) balloon memory in monitor in loop
    7) check vm alive

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

    error.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    default_memory = int(params.get("default_memory", params['mem']))
    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)
    # for media player configuration
    if params.get("pre_cmd"):
        session.cmd(params.get("pre_cmd"))

    driver_name = params["driver_name"]
    utils_test.qemu.setup_win_driver_verifier(driver_name, vm, timeout)
    balloon_test = BallooningTestWin(test, params, env)

    error.context("Play video in guest", logging.info)
    play_video_cmd = params["play_video_cmd"]
    session.sendline(play_video_cmd)
    # need to wait for wmplayer loading remote video
    time.sleep(float(params.get("loading_timeout", 60)))
    check_playing_cmd = params["check_playing_cmd"]
    running = utils_misc.wait_for(
        lambda: utils_misc.get_guest_cmd_status_output(vm, check_playing_cmd)[
            0] == 0,
        first=5.0,
        timeout=600)
    if not running:
        raise error.TestError("Video is not playing")

    #for case:balloon_in_use to call
    env["balloon_test"] = 0
    error.context("balloon vm memory in loop", logging.info)
    repeat_times = int(params.get("repeat_times", 10))
    logging.info("repeat times: %d" % repeat_times)
    min_sz, max_sz = balloon_test.get_memory_boundary()
    while repeat_times:
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
        env["balloon_test"] = 1
        repeat_times -= 1

    error.context("verify guest still alive", logging.info)
    session.cmd(params["stop_player_cmd"])
    vm.verify_alive()
    if session:
        session.close()
コード例 #18
0
ファイル: balloon_memhp.py プロジェクト: zixi-chen/tp-qemu
def run(test, params, env):
    """
    Balloon and memory hotplug test:
    1) boot a guest with balloon device
    2) enable and check driver verifier in guest(only for windows guest)
    3) install balloon service in guest(only for windows guest)
    4) evict balloon
    5) hotplug memory to guest
    6) check balloon and guest memory
    7) enlarge balloon to maxium value
    8) evict balloon
    9) check balloon and guest memory
    10) uninstall balloon service and clear driver verifier(only for
       windows guest)
    """
    def check_memory():
        """
        Check guest memory
        """
        if params['os_type'] == 'windows':
            memhp_test.check_memory(vm)
        else:
            expected_mem = new_mem + mem_dev_sz
            guest_mem_size = memhp_test.get_guest_total_mem(vm)
            threshold = float(params.get("threshold", 0.1))
            if expected_mem - guest_mem_size > guest_mem_size * threshold:
                msg = ("Assigned '%s MB' memory to '%s', "
                       "but '%s MB' memory detect by OS" %
                       (expected_mem, vm.name, guest_mem_size))
                test.fail(msg)

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()

    if params['os_type'] == 'linux':
        balloon_test = BallooningTestLinux(test, params, env)
    else:
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name)
        balloon_test = BallooningTestWin(test, params, env)
        error_context.context("Config balloon service in guest", logging.info)
        balloon_test.configure_balloon_service(session)

    memhp_test = MemoryHotplugTest(test, params, env)

    mem_dev_sz = params["size_mem"]
    mem_dev_sz = int(utils_numeric.normalize_data_size(mem_dev_sz, "M"))
    target_mem = params["target_mem"]

    try:
        min_sz, max_sz = balloon_test.get_memory_boundary()
        new_mem = int(random.uniform(min_sz, max_sz))
        balloon_test.balloon_memory(new_mem)
        memhp_test.hotplug_memory(vm, target_mem)
        check_memory()
        balloon_test.ori_mem += mem_dev_sz
        balloon_test.balloon_memory(balloon_test.ori_mem)
        min_sz, max_sz = balloon_test.get_memory_boundary()
        new_mem = int(random.uniform(min_sz, max_sz))
        balloon_test.balloon_memory(new_mem)

    finally:
        if params['os_type'] == 'windows':
            error_context.context("Clear balloon service in guest",
                                  logging.info)
            balloon_test.operate_balloon_service(session, "uninstall")
        session.close()
コード例 #19
0
def run(test, params, env):
    """
    Test hotplug of balloon devices.

    1) Boot up guest w/o balloon device.
    2) Hoplug balloon device and check hotplug successfully or not.
    3) Install balloon service and check its status in windows guests.
    4) Do memory balloon.
    5) Reboot/shutdown guest after hotplug balloon device(option)
    6) Do memory balloon after guest reboot(option)
    7) Unplug balloon device and check unplug successfully or not.
    8) Reboot/shutdown guest after unplug balloon device(option)

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    def run_pm_test(pm_test, plug_type):
        """
        Run pm(reboot/system_reset/shutdown) related test after balloon
        device is hot-plug or hot-unplug
        :param pm_test: power management test name,e.g. reboot/shutdown
        :param plug_type:balloon device plug operation,e.g.hot_plug or hot_unplug
        """
        error_context.context(
            "Run %s test after %s balloon device" % (pm_test, plug_type),
            logging.info)
        utils_test.run_virt_sub_test(test, params, env, pm_test)

    def enable_balloon_service():
        """
        Install balloon service and check its status in windows guests
        """
        if params['os_type'] != 'windows':
            return
        error_context.context(
            "Install and check balloon service in windows "
            "guest", logging.info)
        session = vm.wait_for_login()
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name)
        balloon_test.configure_balloon_service(session)

        output = balloon_test.operate_balloon_service(session, "status")
        if not re.search(r"running", output.lower(), re.M):
            test.error("Ballooon service status is not running")
        session.close()

    pm_test_after_plug = params.get("pm_test_after_plug")
    pm_test_after_unplug = params.get("pm_test_after_unplug")
    unplug_timeout = params.get("unplug_timeout", 30)
    idx = 0
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    balloon_device = params.get("balloon_device", "virtio-balloon-pci")
    error_context.context("Hotplug and unplug balloon device in a loop",
                          logging.info)
    for i in range(int(params.get("balloon_repeats", 3))):
        vm.devices.set_dirty()
        new_dev = qdevices.QDevice(
            balloon_device, {'id': 'balloon%d' % idx},
            parent_bus={'aobject': params.get("balloon_bus", 'pci.0')})

        error_context.context("Hotplug balloon device for %d times" % (i + 1),
                              logging.info)
        out = vm.devices.simple_hotplug(new_dev, vm.monitor)
        if out[1] is False:
            test.fail("Failed to hotplug balloon in iteration %s, %s" %
                      (i, out[0]))

        # temporary workaround for migration
        vm.params["balloon"] = "balloon%d" % idx
        vm.params["balloon_dev_devid"] = "balloon%d" % idx
        vm.params["balloon_dev_add_bus"] = "yes"
        devs = vm.devices.get_by_params({"id": 'balloon%d' % idx})
        vm.params["balloon_pci_bus"] = devs[0]["bus"]

        if params['os_type'] == 'windows':
            balloon_test = BallooningTestWin(test, params, env)
        else:
            balloon_test = BallooningTestLinux(test, params, env)
        min_sz, max_sz = balloon_test.get_memory_boundary()

        enable_balloon_service()

        error_context.context(
            "Check whether balloon device work after hotplug", logging.info)
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))

        if pm_test_after_plug:
            run_pm_test(pm_test_after_plug, "hot-plug")
            # run balloon test after reboot,skip followed test if
            # pm_test_after_plug is shutdown
            if vm.is_alive():
                balloon_test.balloon_memory(int(random.uniform(min_sz,
                                                               max_sz)))
            else:
                return

        if params['os_type'] == 'windows':
            time.sleep(10)

        error_context.context("Unplug balloon device for %d times" % (i + 1),
                              logging.info)

        out = vm.devices.simple_unplug(devs[0].get_aid(),
                                       vm.monitor,
                                       timeout=unplug_timeout)
        if out[1] is False:
            test.fail("Failed to unplug balloon in iteration %s, %s" %
                      (i, out[0]))
        time.sleep(2)

        if params.get("migrate_after_unplug", "no") == "yes":
            error_context.context("Migrate after hotunplug balloon device",
                                  logging.info)
            # temporary workaround for migration
            del vm.params["balloon"]
            del vm.params["balloon_dev_devid"]
            del vm.params["balloon_dev_add_bus"]
            del vm.params["balloon_pci_bus"]
            vm.migrate(float(params.get("mig_timeout", "3600")))

        if pm_test_after_unplug:
            run_pm_test(pm_test_after_unplug, "hot-unplug")
            if not vm.is_alive():
                return

    error_context.context("Verify guest alive!", logging.info)
    vm.verify_kernel_crash()
コード例 #20
0
def run(test, params, env):
    """
    Qemu balloon device stress test:
    1) boot guest with balloon device
    2) enable driver verifier in guest (Windows only)
    3) run stress in background repeatly
    4) balloon memory in monitor in loop

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def check_bg_running():
        """
        Check the background test status in guest.
        :return: return True if find the process name; otherwise False
        """
        if params['os_type'] == 'windows':
            list_cmd = params.get("list_cmd", "wmic process get name")
            output = session.cmd_output_safe(list_cmd, timeout=60)
            process = re.findall("mplayer", output, re.M | re.I)
            return bool(process)
        else:
            return stress_bg.app_running()

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = float(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)

    if params['os_type'] == 'windows':
        driver_name = params["driver_name"]
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name, timeout)
        balloon_test = BallooningTestWin(test, params, env)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    error_context.context("Run stress background", logging.info)
    stress_test = params.get("stress_test")
    if params['os_type'] == 'windows':
        utils_test.run_virt_sub_test(test, params, env, stress_test)
        if not utils_misc.wait_for(check_bg_running,
                                   first=2.0,
                                   text="wait for stress app to start",
                                   step=1.0,
                                   timeout=60):
            test.error("Run stress background failed")
    else:
        stress_bg = utils_test.VMStress(vm, "stress", params)
        stress_bg.load_stress_tool()

    repeat_times = int(params.get("repeat_times", 1000))
    min_sz, max_sz = balloon_test.get_memory_boundary()

    error_context.context("balloon vm memory in loop", logging.info)
    try:
        for i in range(1, int(repeat_times + 1)):
            logging.info("repeat times: %d" % i)
            balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            if not check_bg_running():
                test.error("Background stress process is not alive")
    finally:
        if session:
            session.close()
コード例 #21
0
ファイル: balloon_service.py プロジェクト: ldoktor/tp-qemu
def run(test, params, env):
    """
    Balloon service test, i.e. guest-stats-polling-interval test.
    1) boot a guest with balloon device.
    2) enable and check driver verifier in guest(only for windows guest).
    3) install balloon service in guest(only for windows guest).
    4) evict / enlarge balloon.
    5) get polling value in qmp, then do memory check if necessary.
    6) uninstall or stop balloon service(optional)
    7) check memory status(optional)
    8) install or run balloon service(optional)
    9) check memory status(optional)
    10) uninstall balloon service and clear driver verifier(only for
       windows guest).
    """

    def balloon_memory(vm, mem_check, min_sz, max_sz):
        """
        Doing memory balloon in a loop and check memory statistics during balloon.

        :param vm: VM object.
        :param mem_check: need to do memory check if param mem_check is 'yes'
        :param min_sz: guest minimal memory size
        :param max_sz: guest maximal memory size
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d" % repeat_times)

        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                if balloon_type == 'evict':
                    expect_mem = int(random.uniform(
                        min_sz, balloon_test.get_ballooned_memory()))
                else:
                    expect_mem = int(random.uniform(
                        balloon_test.get_ballooned_memory(), max_sz))

                quit_after_test = balloon_test.run_ballooning_test(expect_mem,
                                                                   tag)
                time.sleep(20)
                if mem_check == "yes":
                    balloon_test.memory_stats_check('stat-free-memory', mem_stat_working)
                if quit_after_test:
                    return

            repeat_times -= 1

    mem_check = params.get("mem_check", "yes")
    mem_stat_working = True

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login()
    if params['os_type'] == 'windows':
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(session, vm,
                                                                test, driver_name)
        balloon_test = BallooningTestWin(test, params, env)
        error_context.context("Config balloon service in guest",
                              logging.info)
        balloon_test.configure_balloon_service(session)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    try:
        min_sz, max_sz = balloon_test.get_memory_boundary()
        balloon_memory(vm, mem_check, min_sz, max_sz)
        blnsrv_operation = params.objects("blnsrv_operation")
        mem_stat_working = False
        for bln_oper in blnsrv_operation:
            error_context.context("%s balloon service" % bln_oper, logging.info)
            balloon_test.operate_balloon_service(session, bln_oper)

            error_context.context("Balloon vm memory after %s balloon service"
                                  % bln_oper, logging.info)
            balloon_memory(vm, mem_check, min_sz, max_sz)
            mem_stat_working = True

    finally:
        if params['os_type'] == 'windows':
            error_context.context("Clear balloon service in guest",
                                  logging.info)
            balloon_test.operate_balloon_service(session, "uninstall")
        session.close()
コード例 #22
0
def run(test, params, env):
    """
    Balloon service test, i.e. guest-stats-polling-interval test.
    1) boot a guest with balloon device.
    2) enable and check driver verifier in guest(only for windows guest).
    3) install balloon service in guest(only for windows guest).
    4) evict / enlarge balloon.
    5) get polling value in qmp, then do memory check if necessary.
    6) uninstall or stop balloon service(optional)
    7) check memory status(optional)
    8) install or run balloon service(optional)
    9) check memory status(optional)
    10) uninstall balloon service and clear driver verifier(only for
       windows guest).
    """
    def balloon_memory(vm, mem_check, min_sz, max_sz):
        """
        Doing memory balloon in a loop and check memory statistics during balloon.

        :param vm: VM object.
        :param mem_check: need to do memory check if param mem_check is 'yes'
        :param min_sz: guest minimal memory size
        :param max_sz: guest maximal memory size
        """
        repeat_times = int(params.get("repeat_times", 5))
        logging.info("repeat times: %d", repeat_times)

        while repeat_times:
            for tag in params.objects('test_tags'):
                error_context.context("Running %s test" % tag, logging.info)
                params_tag = params.object_params(tag)
                balloon_type = params_tag['balloon_type']
                if balloon_type == 'evict':
                    expect_mem = int(
                        random.uniform(min_sz,
                                       balloon_test.get_ballooned_memory()))
                else:
                    expect_mem = int(
                        random.uniform(balloon_test.get_ballooned_memory(),
                                       max_sz))

                quit_after_test = balloon_test.run_ballooning_test(
                    expect_mem, tag)
                time.sleep(20)
                if mem_check == "yes":
                    check_list = params["mem_stat_check_list"].split()
                    for mem_check_name in check_list:
                        balloon_test.memory_stats_check(
                            mem_check_name, mem_stat_working)
                if quit_after_test:
                    return

            repeat_times -= 1

    mem_check = params.get("mem_check", "yes")
    mem_stat_working = True

    error_context.context("Boot guest with balloon device", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login()
    if params['os_type'] == 'windows':
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, driver_name)
        balloon_test = BallooningTestWin(test, params, env)
        error_context.context("Config balloon service in guest", logging.info)
        balloon_test.configure_balloon_service(session)
    else:
        balloon_test = BallooningTestLinux(test, params, env)

    try:
        min_sz, max_sz = balloon_test.get_memory_boundary()
        balloon_memory(vm, mem_check, min_sz, max_sz)
        blnsrv_operation = params.objects("blnsrv_operation")
        mem_stat_working = False
        for bln_oper in blnsrv_operation:
            error_context.context("%s balloon service" % bln_oper,
                                  logging.info)
            balloon_test.operate_balloon_service(session, bln_oper)

            error_context.context(
                "Balloon vm memory after %s balloon service" % bln_oper,
                logging.info)
            balloon_memory(vm, mem_check, min_sz, max_sz)
            mem_stat_working = True

    finally:
        if params['os_type'] == 'windows':
            error_context.context("Clear balloon service in guest",
                                  logging.info)
            balloon_test.operate_balloon_service(session, "uninstall")
        session.close()
コード例 #23
0
ファイル: balloon_hotplug.py プロジェクト: ldoktor/tp-qemu
def run(test, params, env):
    """
    Test hotplug of balloon devices.

    1) Boot up guest w/o balloon device.
    2) Hoplug balloon device and check hotplug successfully or not.
    3) Install balloon service and check its status in windows guests.
    4) Do memory balloon.
    5) Reboot/shutdown guest after hotplug balloon device(option)
    6) Do memory balloon after guest reboot(option)
    7) Unplug balloon device and check unplug successfully or not.
    8) Reboot/shutdown guest after unplug balloon device(option)

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

    def run_pm_test(pm_test, plug_type):
        """
        Run pm(reboot/system_reset/shutdown) related test after balloon
        device is hot-plug or hot-unplug
        :param pm_test: power management test name,e.g. reboot/shutdown
        :param plug_type:balloon device plug operation,e.g.hot_plug or hot_unplug
        """
        error_context.context("Run %s test after %s balloon device"
                              % (pm_test, plug_type), logging.info)
        utils_test.run_virt_sub_test(test, params, env, pm_test)

    def enable_balloon_service():
        """
        Install balloon service and check its status in windows guests
        """
        if params['os_type'] != 'windows':
            return
        error_context.context("Install and check balloon service in windows "
                              "guest", logging.info)
        session = vm.wait_for_login()
        driver_name = params.get("driver_name", "balloon")
        session = utils_test.qemu.windrv_check_running_verifier(session,
                                                                vm, test,
                                                                driver_name)
        balloon_test.configure_balloon_service(session)

        output = balloon_test.operate_balloon_service(session, "status")
        if not re.search(r"running", output.lower(), re.M):
            test.error("Ballooon service status is not running")
        session.close()

    pm_test_after_plug = params.get("pm_test_after_plug")
    pm_test_after_unplug = params.get("pm_test_after_unplug")
    idx = 0
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    balloon_device = params.get("ballon_device", "virtio-balloon-pci")
    error_context.context("Hotplug and unplug balloon device in a loop",
                          logging.info)
    for i in range(int(params.get("balloon_repeats", 3))):
        vm.devices.set_dirty()
        new_dev = qdevices.QDevice(balloon_device,
                                   {'id': 'balloon%d' % idx},
                                   parent_bus={'aobject': 'pci.0'})

        error_context.context("Hotplug balloon device for %d times" % (i+1),
                              logging.info)
        out = vm.devices.simple_hotplug(new_dev, vm.monitor)
        if out[1] is False:
            test.fail("Failed to hotplug balloon in iteration %s, %s"
                      % (i, out[0]))

        # temporary workaround for migration
        vm.params["balloon"] = "balloon%d" % idx
        vm.params["balloon_dev_devid"] = "balloon%d" % idx
        vm.params["balloon_dev_add_bus"] = "yes"
        devs = vm.devices.get_by_params({"id": 'balloon%d' % idx})
        vm.params["balloon_pci_bus"] = devs[0]["bus"]

        if params['os_type'] == 'windows':
            balloon_test = BallooningTestWin(test, params, env)
        else:
            balloon_test = BallooningTestLinux(test, params, env)
        min_sz, max_sz = balloon_test.get_memory_boundary()

        enable_balloon_service()

        error_context.context("Check whether balloon device work after hotplug",
                              logging.info)
        balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))

        if pm_test_after_plug:
            run_pm_test(pm_test_after_plug, "hot-plug")
            # run balloon test after reboot,skip followed test if
            # pm_test_after_plug is shutdown
            if vm.is_alive():
                balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
            else:
                return

        if params['os_type'] == 'windows':
            time.sleep(10)

        error_context.context("Unplug balloon device for %d times" % (i+1),
                              logging.info)

        out = vm.devices.simple_unplug(devs[0].get_aid(), vm.monitor)
        if out[1] is False:
            test.fail("Failed to hotplug balloon in iteration %s, %s"
                      % (i, out[0]))

        if params.get("migrate_after_unplug", "no") == "yes":
            error_context.context("Migrate after hotunplug balloon device",
                                  logging.info)
            # temporary workaround for migration
            del vm.params["balloon"]
            del vm.params["balloon_dev_devid"]
            del vm.params["balloon_dev_add_bus"]
            del vm.params["balloon_pci_bus"]
            vm.migrate(float(params.get("mig_timeout", "3600")))

        if pm_test_after_unplug:
            run_pm_test(pm_test_after_unplug, "hot-unplug")
            if not vm.is_alive():
                return

    error_context.context("Verify guest alive!", logging.info)
    vm.verify_kernel_crash()