Ejemplo n.º 1
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_unattended_install(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)
Ejemplo n.º 2
0
def run_check_block_size(test, params, env):
    """
    Check physical block size and logical block size for virtio block device:
    1) Install guest with a new image.
    2) Verify whether physical/logical block size in guest is same as qemu
       parameters.
    TODO: This test only works on Linux guest, should make it work in windows
          guest. (Are there any windows tools to check block size?)

    @param test: QEMU test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    if params.get("need_install") == "yes":
        error.context("Install guest with a new image", logging.info)
        unattended_install.run_unattended_install(test, params, env)

    params["cdroms"] = ""
    params["unattended_file"] = ""
    params["cdrom_unattended"] = ""
    params["kernel"] = ""
    params["initrd"] = ""
    params["kernel_params"] = ""
    params["boot_once"] = "c"

    vm = env.get_vm(params["main_vm"])
    try:
        vm.verify_alive()
    except virt_vm.VMDeadError:
        logging.info("VM is dead, creating...")
        vm.create(params=params)

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

    try:
        # Get virtio block devices in guest.
        cmd = params.get("get_dev_list_cmd", '')
        dev_list = session.cmd_output(cmd).split()
        if dev_list:
            expect_physical = int(params.get("physical_block_size_stg", 0))
            expect_logical = int(params.get("logical_block_size_stg", 0))
            #FIXME: seems we don't have a method to check which virtio
            # device matches device file in guest. So we just check the
            # last device file in guest. Hope it will work correctly.
            # Yep, we need improvement here.
            error.context("Verify physical/Logical block size", logging.info)
            cmd = params.get("chk_phy_blk_cmd") % dev_list[-1]
            logging.debug("Physical block size get via '%s'" % cmd)
            out_physical = int(session.cmd_output(cmd))
            cmd = params.get("chk_log_blk_cmd") % dev_list[-1]
            logging.debug("Logical block size get via '%s'" % cmd)
            out_logical = int(session.cmd_output(cmd))
            if ((out_physical != expect_physical) or
                (out_logical != expect_logical)):
                msg = "Block size in guest doesn't match with qemu parameter\n"
                msg += "Physical block size in guest: %s, " % out_physical
                msg += "expect: %s" % expect_physical
                msg += "\nLogical block size in guest: %s, " % out_logical
                msg += "expect: %s" % expect_logical
                raise error.TestFail(msg)
        else:
            raise error.TestError("Could not find any virtio block device.")
    finally:
        if session:
            session.close()