예제 #1
0
def run(test, params, env):
    """
    Unattended install test with virtual TPM device:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.
    3) Check TPM device info inside guest.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def search_keywords(patterns, string, flags=re.M, split_string=';'):
        test.log.info(string)
        for pattern in patterns.split(split_string):
            if not re.search(r'%s' % pattern, string, flags):
                test.fail('No Found pattern "%s" from "%s".' %
                          (pattern, string))
            if re.search(r'error', string, re.M | re.A):
                test.error('Found errors from "%s".' % string)

    unattended_install.run(test, params, env)

    vm = env.get_vm(params["main_vm"])
    if vm:
        vm.destroy()

    ovmf_vars_secboot_fd = params.get('ovmf_vars_secboot_fd')
    if ovmf_vars_secboot_fd:
        params['ovmf_vars_filename'] = ovmf_vars_secboot_fd

    params['start_vm'] = 'yes'
    params['cdroms'] = params.get('default_cdrom', '')
    params['force_create_image'] = 'no'
    params['kernel'] = ''
    params['initrd'] = ''
    params['kernel_params'] = ''
    params['boot_once'] = 'c'

    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()

    error_context.context("Check TPM info inside guest.", test.log.info)
    for name in params.get('check_cmd_names').split():
        if name:
            pattern = params.get('pattern_output_%s' % name)
            cmd = params.get('cmd_%s' % name)
            search_keywords(pattern, session.cmd(cmd))

    cmd_check_secure_boot_enabled = params.get('cmd_check_secure_boot_enabled')
    if cmd_check_secure_boot_enabled:
        error_context.context(
            "Check whether secure boot enabled inside guest.", test.log.info)
        status, output = session.cmd_status_output(
            cmd_check_secure_boot_enabled)
        if status:
            test.fail('Secure boot is not enabled, output: %s' % output)
예제 #2
0
def run(test, params, env):
    """
    Unattended install test:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    # use vm name to differentiate among single/multivm
    vms = params.objects("vms")

    if len(vms) < 2:
        unattended_install.run(test, params, env)
        return

    def thread_func(vm):
        """
        Thread Method to trigger the unattended installation

        :param vm: VM name
        """
        global error_flag
        try:
            vm_params = params.object_params(vm)
            vm_params["main_vm"] = vm
            unattended_install.run(test, vm_params, env)
        except Exception as info:
            logging.error(info)
            error_flag = True

    if not params.get("master_images_clone"):
        test.cancel("provide the param `master_images_clone` to clone"
                    "images for vms")

    trigger_time = int(params.get("install_trigger_time", 0))
    random_trigger = params.get("random_trigger", "no") == "yes"
    install_threads = []

    for vm in vms:
        thread = threading.Thread(target=thread_func, args=(vm,))
        install_threads.append(thread)

    for thread in install_threads:
        if trigger_time:
            sleep_time = trigger_time
            if random_trigger:
                sleep_time = random.randint(0, trigger_time)
            time.sleep(sleep_time)
        thread.start()

    for thread in install_threads:
        thread.join()

    if error_flag:
        test.fail("Failed to perform unattended install")
예제 #3
0
def run(test, params, env):
    """
    Unattended install test:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    # use vm name to differentiate among single/multivm
    vms = params.objects("vms")

    if len(vms) < 2:
        unattended_install.run(test, params, env)
        return

    def thread_func(vm):
        """
        Thread Method to trigger the unattended installation

        :param vm: VM name
        """
        global error_flag
        try:
            vm_params = params.object_params(vm)
            vm_params["main_vm"] = vm
            unattended_install.run(test, vm_params, env)
        except Exception as info:
            logging.error(info)
            error_flag = True

    if not params.get("master_images_clone"):
        test.cancel("provide the param `master_images_clone` to clone"
                    "images for vms")

    trigger_time = int(params.get("install_trigger_time", 0))
    random_trigger = params.get("random_trigger", "no") == "yes"
    install_threads = []

    for vm in vms:
        thread = threading.Thread(target=thread_func, args=(vm, ))
        install_threads.append(thread)

    for thread in install_threads:
        if trigger_time:
            sleep_time = trigger_time
            if random_trigger:
                sleep_time = random.randint(0, trigger_time)
            time.sleep(sleep_time)
        thread.start()

    for thread in install_threads:
        thread.join()

    if error_flag:
        test.fail("Failed to perform unattended install")
예제 #4
0
def run(test, params, env):
    """
    Unattended install test:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    unattended_install.run(test, params, env)
예제 #5
0
def run(test, params, env):
    """
    Unattended install test:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    unattended_install.run(test, params, env)
예제 #6
0
    def thread_func(vm):
        """
        Thread Method to trigger the unattended installation

        :param vm: VM name
        """
        global error_flag
        try:
            vm_params = params.object_params(vm)
            vm_params["main_vm"] = vm
            unattended_install.run(test, vm_params, env)
        except Exception as info:
            logging.error(info)
            error_flag = True
예제 #7
0
    def thread_func(vm):
        """
        Thread Method to trigger the unattended installation

        :param vm: VM name
        """
        global error_flag
        try:
            vm_params = params.object_params(vm)
            vm_params["main_vm"] = vm
            unattended_install.run(test, vm_params, env)
        except Exception as info:
            logging.error(info)
            error_flag = True
예제 #8
0
def run(test, params, env):
    """
    Test hot plug and unplug NVMe device.

    Steps:
        1. Install guest with local filesystem.
        2. Hot plug NVMe device to guest.
        3. Check if the NVMe device exists in qemu side.
        4. Check if the NVMe has been successfully added to guest.
        5. Run fio in the hot plugged NVMe device in guest.
        6. Unplug the NVMe device.
        7. Check if the NVMe device still exists.
        8. Check if the NVMe has been successfully removed from guest.
        9. Reboot guest.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    unattended_install.run(test, params, env)

    if params.get('remove_options'):
        for option in params.get('remove_options').split():
            del params[option]
    params['cdroms'] = params.get('default_cdroms')

    params['start_vm'] = 'yes'
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session = vm.wait_for_login()

    plug = BlockDevicesPlug(vm)
    plug.hotplug_devs_serial()
    target = '/dev/%s' % plug[0]
    os_type = params['os_type']
    data_img_size = params.get('image_size_%s' % params.get('data_img_tag'))
    if os_type == 'windows':
        utils_disk.update_windows_disk_attributes(session, plug[0])
        drive_letter = utils_disk.configure_empty_disk(session, plug[0],
                                                       data_img_size,
                                                       os_type)[0]
        target = r'%s\:\\%s' % (drive_letter, params.get('fio_filename'))
    fio = generate_instance(params, vm, 'fio')
    for option in params['fio_options'].split(';'):
        fio.run('--filename=%s %s' % (target, option))
    plug.unplug_devs_serial()
    vm.reboot(session)
예제 #9
0
def run(test, params, env):
    """
    Test to install the guest OS on the 4k disk.
    Steps:
        1) Setup iSCSI server with fileio backend and enable 4k sector.
        2) Discovery and login the above iSCSI target.
        3) Mount the iscsi disk and create raw image on it.
        4) Install a guest on the raw image as blk device and enable iothread .

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

    def _prepare():
        cmd_prepare = params['cmd_prepare'].format(dev_name)
        process.run(cmd_prepare, 600, shell=True)

    def _cleanup():
        if vm and vm.is_alive():
            vm.destroy()
        cmd_cleanup = params['cmd_cleanup'] % base_dir
        process.run(cmd_cleanup, 600, shell=True)

    try:
        vm = None
        params['image_size'] = params['emulated_image_size']
        base_dir = data_dir.get_data_dir()
        iscsi = Iscsi.create_iSCSI(params, base_dir)
        iscsi.login()
        dev_name = utils_misc.wait_for(lambda: iscsi.get_device_name(), 60)
        if not dev_name:
            test.error('Can not get the iSCSI device.')

        logging.info('Prepare env on: %s', dev_name)
        _prepare()
        logging.info('Start to install ...')
        vm = env.get_vm(params["main_vm"])
        unattended_install.run(test, params, env)
        logging.info('Install completed')
        vm.destroy()
        vm = None
    finally:
        _cleanup()
        iscsi.cleanup()
예제 #10
0
def run(test, params, env):
    """
    Test svirt in virt-install.

    (1). Init variables.
    (2). Set selinux on host.
    (3). Set label of image.
    (4). run unattended install.
    (5). clean up.
    """
    # Get general variables.
    status_error = ('yes' == params.get("status_error", 'no'))
    host_sestatus = params.get("host_selinux", "enforcing")

    # Set selinux status on host.
    backup_sestatus = utils_selinux.get_status()
    utils_selinux.set_status(host_sestatus)

    # Set the image label.
    disk_label = params.get("disk_label", None)
    vm_name = params.get("main_vm", None)
    vm_params = params.object_params(vm_name)
    base_dir = params.get("images_base_dir", data_dir.get_data_dir())
    image_filename = storage.get_image_filename(vm_params, base_dir)
    utils_selinux.set_context_of_file(image_filename, disk_label)

    try:
        try:
            unattended_install.run(test, params, env)
            # Install completed.
            if status_error:
                raise error.TestFail('Test successed in negative case.')
        except error.CmdError, e:
            # Install failed.
            if not status_error:
                raise error.TestFail("Test failed in positive case."
                                     "error: %s" % e)
    finally:
        # cleanup
        utils_selinux.set_status(backup_sestatus)
        if virsh.domain_exists(vm_name):
            virsh.remove_domain(vm_name)
예제 #11
0
def run(test, params, env):
    """
    Test to install the guest OS on the lvm device which is created
    on an iSCSI target.
    Steps:
        1) Setup iSCSI initiator on local host.
        2) Discovery and login the above iSCSI target.
        3) Create a partition on the iSCSI target.
        4) Create a lvm on the partition.
        5) Install a guest from ISO with the logical volume.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    params['image_size'] = params['emulated_image_size']
    post_commands = []
    try:
        iscsi = Iscsi.create_iSCSI(params, data_dir.get_data_dir())
        post_commands.extend((params['post_commands_iscsi'] %
                              (iscsi.emulated_image, iscsi.id)).split(','))
        lvm = LVM(params)
        iscsi.login()
        dev_name = utils_misc.wait_for(lambda: iscsi.get_device_name(), 60)
        if not dev_name:
            test.error('Can not get the iSCSI device.')
        process.run(params['cmd_fdisk'] % dev_name, 600, shell=True)
        params['pv_name'] = process.system_output(
            params['cmd_get_partition'].format(dev_name), 60,
            shell=True).decode().strip()
        post_commands.extend(
            (params['post_commands_lvm'] % params['pv_name']).split(','))
        lvm.setup()
        preprocess_vm(test, params, env, params["main_vm"])
        unattended_install.run(test, params, env)
    finally:
        params['post_command'] = ' ; '.join(post_commands[::-1])
def run(test, params, env):
    """
    Unattended install test:
    1) Starts a VM with an appropriated setup to start an unattended OS install.
    2) Wait until the install reports to the install watcher its end.

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

    params["cpu_model_flags"] = ""
    unattended_install.run(test, params, env)
    vm = env.get_vm(params.get("main_vm"))
    vm.destroy()

    params["cdroms"] = "winutils"
    params["start_vm"] = "yes"
    env_process.preprocess_vm(test, params, env, params.get("main_vm"))
    vm = env.get_vm(params.get("main_vm"))
    session = vm.wait_for_login()

    session = vm.reboot(session)
    session.close()
def run(test, params, env):
    """
    Test storage pool and volumes with applications such as:
    install vms, attached to vms...
    """
    pool_type = params.get("pool_type")
    pool_name = "test_%s_app" % pool_type
    pool_target = params.get("pool_target")
    emulated_img = params.get("emulated_image", "emulated-image")
    volume_count = int(params.get("volume_count", 1))
    volume_size = params.get("volume_size", "1G")
    emulated_size = "%sG" % (volume_count * int(volume_size[:-1]) + 1)
    application = params.get("application", "install")
    disk_target = params.get("disk_target", "vdb")
    test_message = params.get("test_message", "")
    vm_name = params.get("main_vm", "avocado-vt-vm1")
    block_device = params.get("block_device", "/DEV/EXAMPLE")
    if application == "install":
        cdrom_path = os.path.join(data_dir.get_data_dir(),
                                  params.get("cdrom_cd1"))
        if not os.path.exists(cdrom_path):
            raise error.TestNAError("Can't find installation cdrom:%s"
                                    % cdrom_path)
        # Get a nonexist domain name
        vm_name = "vol_install_test"

    try:
        pvtest = utlv.PoolVolumeTest(test, params)
        pvtest.pre_pool(pool_name, pool_type, pool_target, emulated_img,
                        image_size=emulated_size, pre_disk_vol=[volume_size],
                        device_name=block_device)

        logging.debug("Current pools:\n%s",
                      libvirt_storage.StoragePool().list_pools())

        new_pool = libvirt_storage.PoolVolume(pool_name)
        if pool_type == "disk":
            volumes = new_pool.list_volumes()
            logging.debug("Current volumes:%s", volumes)
        else:
            volumes = create_volumes(new_pool, volume_count, volume_size)
        if application == "attach":
            vm = env.get_vm(vm_name)
            session = vm.wait_for_login()
            virsh.attach_disk(vm_name, volumes.values()[volume_count - 1],
                              disk_target)
            vm_attach_device = "/dev/%s" % disk_target
            if session.cmd_status("which parted"):
                # No parted command, check device only
                if session.cmd_status("ls %s" % vm_attach_device):
                    raise error.TestFail("Didn't find attached device:%s"
                                         % vm_attach_device)
                return
            # Test if attached disk can be used normally
            utlv.mk_part(vm_attach_device, session=session)
            session.cmd("mkfs.ext4 %s1" % vm_attach_device)
            session.cmd("mount %s1 /mnt" % vm_attach_device)
            session.cmd("echo %s > /mnt/test" % test_message)
            output = session.cmd_output("cat /mnt/test").strip()
            if output != test_message:
                raise error.TestFail("%s cannot be used normally!"
                                     % vm_attach_device)
        elif application == "install":
            # Get a nonexist domain name anyway
            while virsh.domain_exists(vm_name):
                vm_name += "_test"
            # Prepare installation parameters
            params["main_vm"] = vm_name
            vm = env.create_vm("libvirt", None, vm_name, params,
                               test.bindir)
            env.register_vm(vm_name, vm)
            params["image_name"] = volumes.values()[volume_count - 1]
            params["image_format"] = "raw"
            params['force_create_image'] = "yes"
            params['remove_image'] = "yes"
            params['shutdown_cleanly'] = "yes"
            params['shutdown_cleanly_timeout'] = 120
            params['guest_port_unattended_install'] = 12323
            params['inactivity_watcher'] = "error"
            params['inactivity_treshold'] = 1800
            params['image_verify_bootable'] = "no"
            params['unattended_delivery_method'] = "cdrom"
            params['drive_index_unattended'] = 1
            params['drive_index_cd1'] = 2
            params['boot_once'] = "d"
            params['medium'] = "cdrom"
            params['wait_no_ack'] = "yes"
            params['image_raw_device'] = "yes"
            params['backup_image_before_testing'] = "no"
            params['kernel_params'] = ("ks=cdrom nicdelay=60 "
                                       "console=ttyS0,115200 console=tty0")
            params['cdroms'] = "unattended cd1"
            params['redirs'] += " unattended_install"
            selinux_mode = None
            try:
                selinux_mode = utils_selinux.get_status()
                utils_selinux.set_status("permissive")
                try:
                    unattended_install.run(test, params, env)
                except process.CmdError, detail:
                    raise error.TestFail("Guest install failed:%s" % detail)
            finally:
                if selinux_mode is not None:
                    utils_selinux.set_status(selinux_mode)
                env.unregister_vm(vm_name)
    finally:
        try:
            if application == "install":
                if virsh.domain_exists(vm_name):
                    virsh.remove_domain(vm_name)
            elif application == "attach":
                virsh.detach_disk(vm_name, disk_target)
        finally:
            pvtest.cleanup_pool(pool_name, pool_type,
                                pool_target, emulated_img,
                                device_name=block_device)
예제 #14
0
def run(test, params, env):
    """
    Verify file OVMF_VARS.secboot.fd, boot released OS with Secure boot by default.

    1. Install guest by OVMF environment(With OVMF_VARS.fd)
    2. Boot guest and check if the guest is signed
    3. Shutdown and reboot the guest with file OVMF_VARS.secboot.fd
    4. Check if secure boot is enabled inside guest
    5. If *unreleased* OS boot up with secure boot, test fail

    :param test: Kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    def _check_signed():
        """ Check and return if guest is signed """
        if os_type == 'linux':
            return True if re.search(sign_keyword, sign_info) else False
        for device_line in sign_info.strip().splitlines()[2:]:
            if re.match(sign_keyword, device_line):
                return False
        return True

    unattended_install.run(test, params, env)
    os_type = params['os_type']
    params['cdroms'] = ''
    params['boot_once'] = ''
    params['force_create_image'] = 'no'
    params['start_vm'] = 'yes'
    params['kernel'] = ''
    params['initrd'] = ''
    params['kernel_params'] = ''
    params['image_boot'] = 'yes'
    vm = env.get_vm(params['main_vm'])
    if vm:
        vm.destroy()
    env_process.preprocess_vm(test, params, env, params['main_vm'])
    vm = env.get_vm(params['main_vm'])
    session = vm.wait_for_login()
    check_sign_cmd = params['check_sign_cmd']
    sign_keyword = params['sign_keyword']
    os_type = params['os_type']
    if os_type == 'linux':
        check_pesign_cmd = 'which pesign'
        if session.cmd_status(check_pesign_cmd) != 0:
            install_cmd = params['pesign_install_cmd']
            s, o = session.cmd_status_output(install_cmd)
            if s != 0:
                test.cancel('Install pesign failed with output: "%s". '
                            'Please define proper source for guest' % o)
        vmlinuz = '/boot/vmlinuz-%s' % session.cmd_output('uname -r')
        check_sign_cmd = check_sign_cmd % vmlinuz
    sign_info = session.cmd_output(check_sign_cmd)
    signed = _check_signed()
    error_context.context(
        'Guest signed status is %s, shutdown and reboot '
        'guest with secure boot' % signed, logging.info)
    session.close()
    vm.destroy()
    if utils_misc.wait_for(vm.is_dead, 180, 1, 1):
        logging.info("Guest managed to shutdown cleanly")
    params['ovmf_vars_filename'] = 'OVMF_VARS.secboot.fd'
    env_process.preprocess_vm(test, params, env, params['main_vm'])
    vm = env.get_vm(params['main_vm'])
    try:
        session = vm.wait_for_serial_login()
    except remote.LoginTimeoutError:
        if signed:
            test.fail('The guest is signed,'
                      ' but boot failed under secure mode.')
    else:
        check_cmd = params['check_secure_boot_enabled_cmd']
        status, output = session.cmd_status_output(check_cmd)
        if status != 0:
            test.fail('Secure boot is not enabled')
        if not signed:
            test.fail('The guest is not signed,'
                      ' but boot succeed under secure mode.')
    finally:
        vm.destroy()
def run(test, params, env):
    """
    Test storage pool and volumes with applications such as:
    install vms, attached to vms...
    """
    pool_type = params.get("pool_type")
    pool_name = "test_%s_app" % pool_type
    pool_target = params.get("pool_target")
    emulated_img = params.get("emulated_img", "emulated_img")
    volume_count = int(params.get("volume_count", 1))
    volume_size = params.get("volume_size", "1G")
    emulated_size = "%sG" % (volume_count * int(volume_size[:-1]) + 1)
    application = params.get("application", "install")
    disk_target = params.get("disk_target", "vdb")
    test_message = params.get("test_message", "")
    vm_name = params.get("main_vm", "virt-tests-vm1")
    if application == "install":
        vm_name = params.get("vm_name", "vm1")

    try:
        pvtest = utlv.PoolVolumeTest(test, params)
        pvtest.pre_pool(pool_name, pool_type, pool_target, emulated_img,
                        emulated_size)

        logging.debug("Current pools:\n%s",
                      libvirt_storage.StoragePool().list_pools())

        new_pool = libvirt_storage.PoolVolume(pool_name)
        volumes = create_volumes(new_pool, volume_count, volume_size)
        if application == "attach":
            vm = env.get_vm(vm_name)
            session = vm.wait_for_login()
            # The attach-disk action based on running guest,
            # so no need to recover the guest, it will be
            # recovered automatically after shutdown/reboot
            virsh.attach_disk(vm_name, volumes.values()[volume_count-1],
                              disk_target)
            vm_attach_device = "/dev/%s" % disk_target
            # Test if attached disk can be used normally
            utlv.mk_part(vm_attach_device, session=session)
            session.cmd("mkfs.ext4 %s1" % vm_attach_device)
            session.cmd("mount %s1 /mnt" % vm_attach_device)
            session.cmd("echo %s > /mnt/test" % test_message)
            output = session.cmd_output("cat /mnt/test").strip()
            if output != test_message:
                raise error.TestFail("%s cannot be used normally!"
                                     % vm_attach_device)
        elif application == "install":
            # Get a nonexist domain name
            while virsh.domain_exists(vm_name):
                vm_name += "_test"
            params["image_name"] = volumes.values()[volume_count-1]
            params["image_format"] = "raw"
            try:
                unattended_install.run(test, params, env)
            except error.CmdError, detail:
                raise error.TestFail("Guest install failed:%s" % detail)
    finally:
        try:
            if application == "install":
                if virsh.domain_exists(vm_name):
                    virsh.remove_domain(vm_name)
        finally:
            pvtest.cleanup_pool(pool_name, pool_type,
                                pool_target, emulated_img)
예제 #16
0
def run(test, params, env):
    """
    Test storage pool and volumes with applications such as:
    install vms, attached to vms...
    """
    pool_type = params.get("pool_type")
    pool_name = "test_%s_app" % pool_type
    pool_target = params.get("pool_target")
    emulated_img = params.get("emulated_img", "emulated_img")
    volume_count = int(params.get("volume_count", 1))
    volume_size = params.get("volume_size", "1G")
    emulated_size = "%sG" % (volume_count * int(volume_size[:-1]) + 1)
    application = params.get("application", "install")
    disk_target = params.get("disk_target", "vdb")
    test_message = params.get("test_message", "")
    vm_name = params.get("main_vm", "virt-tests-vm1")
    if application == "install":
        vm_name = params.get("vm_name", "vm1")

    try:
        pvtest = utlv.PoolVolumeTest(test, params)
        pvtest.pre_pool(pool_name, pool_type, pool_target, emulated_img,
                        emulated_size)

        logging.debug("Current pools:\n%s",
                      libvirt_storage.StoragePool().list_pools())

        new_pool = libvirt_storage.PoolVolume(pool_name)
        volumes = create_volumes(new_pool, volume_count, volume_size)
        if application == "attach":
            vm = env.get_vm(vm_name)
            session = vm.wait_for_login()
            # The attach-disk action based on running guest,
            # so no need to recover the guest, it will be
            # recovered automatically after shutdown/reboot
            virsh.attach_disk(vm_name,
                              volumes.values()[volume_count - 1], disk_target)
            vm_attach_device = "/dev/%s" % disk_target
            # Test if attached disk can be used normally
            utlv.mk_part(vm_attach_device, session=session)
            session.cmd("mkfs.ext4 %s1" % vm_attach_device)
            session.cmd("mount %s1 /mnt" % vm_attach_device)
            session.cmd("echo %s > /mnt/test" % test_message)
            output = session.cmd_output("cat /mnt/test").strip()
            if output != test_message:
                raise error.TestFail("%s cannot be used normally!" %
                                     vm_attach_device)
        elif application == "install":
            # Get a nonexist domain name
            while virsh.domain_exists(vm_name):
                vm_name += "_test"
            params["image_name"] = volumes.values()[volume_count - 1]
            params["image_format"] = "raw"
            try:
                unattended_install.run(test, params, env)
            except error.CmdError, detail:
                raise error.TestFail("Guest install failed:%s" % detail)
    finally:
        try:
            if application == "install":
                if virsh.domain_exists(vm_name):
                    virsh.remove_domain(vm_name)
        finally:
            pvtest.cleanup_pool(pool_name, pool_type, pool_target,
                                emulated_img)