live_snapshot.py 3.4 KB
Newer Older
S
Suqin Huang 已提交
1
from autotest_lib.client.virt import virt_utils, virt_test_utils
2
from autotest_lib.client.virt.tests import file_transfer
S
Suqin Huang 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
import time, logging

def run_live_snapshot(test, params, env):
    """
    live_snapshot test:
    1). Create live snapshot during big file creating
    2). Create live snapshot when guest reboot
    3). Check if live snapshot is created
    4). Shutdown guest

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

    def create_snapshot(vm):
        """
        Create live snapshot:
        1). Check which monitor is used
        2). Get device info
        3). Create snapshot
        """

        cmd = params.get("create_sn_cmd")

        block_info = vm.monitor.info("block")
        if virt_utils.has_option("qmp") and params.get("monitor_type") == "qmp":
            device = block_info[0]["device"]
        else:
            string = ""
            device = string.join(block_info).split(":")[0]
        cmd += " %s" % device

        snapshot_name = params.get("snapshot_name")
        cmd += " %s" % snapshot_name

        format = params.get("snapshot_format")
        if format:
            cmd += " %s" % format
        logging.info("Creating live snapshot ...")
        vm.monitor.send_args_cmd(cmd)

        logging.info("Check snapshot is created ...")
        snapshot_info = str(vm.monitor.info("block"))
        if snapshot_name not in snapshot_info:
            logging.error(snapshot_info)
            raise error.TestFail("Snapshot doesn't exist")

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    dd_timeout = int(params.get("dd_timeout", 900))
    session = vm.wait_for_login(timeout=timeout)

    def runtime_test():
        try:
            clean_cmd = params.get("clean_cmd")
            file_create = params.get("file_create")
            clean_cmd += " %s" % file_create
            logging.info("Clean file before creation")
            session.cmd(clean_cmd)

            logging.info("Creating big file...")
            create_cmd = params.get("create_cmd") % file_create

            args = (create_cmd, dd_timeout)
            bg = virt_test_utils.BackgroundTest(session.cmd_output, args)
            bg.start()
            time.sleep(5)
            create_snapshot(vm)
            if bg.is_alive():
                try:
                    bg.join()
                except:
                    raise
        finally:
            session.close()

    def reboot_test():
        try:
            bg = virt_test_utils.BackgroundTest(vm.reboot, (session,))
            logging.info("Rebooting guest ...")
            bg.start()
            sleep_time = int(params.get("sleep_time"))
            time.sleep(sleep_time)
            create_snapshot(vm)
        finally:
            bg.join()

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    def file_transfer_test():
        try:
            bg_cmd = file_transfer.run_file_transfer
            args = (test, params, env)
            bg = virt_test_utils.BackgroundTest(bg_cmd, args)
            bg.start()
            sleep_time = int(params.get("sleep_time"))
            time.sleep(sleep_time)
            create_snapshot(vm)
            if bg.is_alive():
                try:
                    bg.join()
                except:
                    raise
        finally:
            session.close()
S
Suqin Huang 已提交
108 109
    subcommand = params.get("subcommand")
    eval("%s_test()" % subcommand)