def _initial_win_drives():
     size = params['stg_image_size']
     disks = utils_disk.get_windows_disks_index(session, size)
     if not utils_disk.update_windows_disk_attributes(session, disks):
         test.fail("Failed to update windows disk attributes.")
     for disk in disks[1:24]:
         yield utils_disk.configure_empty_windows_disk(session, disk, size)[0]
Beispiel #2
0
 def format_disk_win():
     """ Format disk in windows. """
     error_context.context("Format disk %s in windows." % new_disk,
                           logging.info)
     session = vm.wait_for_login(timeout=timeout)
     if disk_index is None and disk_letter is None:
         drive_letters.append(
             utils_disk.configure_empty_windows_disk(
                 session, new_disk, params['image_size_%s' % img])[0])
     elif disk_index and disk_letter:
         utils_misc.format_windows_disk(session, disk_index[index],
                                        disk_letter[index])
         drive_letters.append(disk_letter[index])
     session.close()
Beispiel #3
0
    def _format_tmpfs_disk():
        """
        Format the new tmpfs disk in guest

        return: the formatted drive letter of the disk
        """
        logging.info("Boot the guest to setup tmpfs disk")
        vm, session = _boot_guest_with_cpu_flag(cpu_model_flags)
        logging.info("Format tmpfs disk")
        disk_size = params["image_size_" + params["tmpfs_image_name"]]
        disk_id = utils_disk.get_windows_disks_index(session, disk_size)[0]
        drive_letter = utils_disk.configure_empty_windows_disk(
            session, disk_id, disk_size)[0]
        vm.graceful_shutdown(timeout=timeout)
        return drive_letter
Beispiel #4
0
    def get_windows_drive_letters(session, index_sizes):
        """
        Format windows disk and get drive_letter for empty disks

        :param session: A shell session object.
        :param index_sizes: List for hotplug disk's index_size
        """
        drive_indexs = []
        for item in index_sizes:
            drive_indexs.append(item.split()[0])
        if not utils_disk.update_windows_disk_attributes(session, drive_indexs):
            test.fail("Failed to clear readonly for all disks and online "
                      "them in guest")
        error_context.context("Format disk", logging.info)
        for item in index_sizes:
            did, size = item.split()
            drive_letter = utils_disk.configure_empty_windows_disk(session,
                                                                   did, size + "B")
            windows_drive_letters.extend(drive_letter)
    def get_windows_drive_letters(session, index_sizes):
        """
        Format windows disk and get drive_letter for empty disks

        :param session: A shell session object.
        :param index_sizes: List for hotplug disk's index_size
        """
        drive_indexs = []
        for item in index_sizes:
            drive_indexs.append(item.split()[0])
        if not utils_disk.update_windows_disk_attributes(session, drive_indexs):
            test.fail("Failed to clear readonly for all disks and online "
                      "them in guest")
        error_context.context("Format disk", logging.info)
        for item in index_sizes:
            did, size = item.split()
            drive_letter = utils_disk.configure_empty_windows_disk(session,
                                                                   did, size + "B")
            windows_drive_letters.extend(drive_letter)
Beispiel #6
0
 def _get_mount_points():
     """ Get data disk mount point(s) """
     mount_points = []
     os_type = params["os_type"]
     if os_type == "linux":
         mounts = session.cmd_output_safe('cat /proc/mounts | grep /dev/')
         for img in image_list:
             size = params["image_size_%s" % img]
             img_param = params["blk_extra_params_%s" % img].split('=')[1]
             drive_path = utils_misc.get_linux_drive_path(
                 session, img_param)
             if not drive_path:
                 test.error("Failed to get drive path of '%s'" % img)
             did = drive_path[5:]
             for mp in re.finditer(r'/dev/%s\d+\s+(\S+)\s+' % did, mounts):
                 mount_points.append(mp.group(1))
             else:
                 mp = utils_disk.configure_empty_linux_disk(
                     session, did, size)
                 mount_points.extend(mp)
     elif os_type == "windows":
         size_record = []
         for img in image_list:
             size = params["image_size_%s" % img]
             if size in size_record:
                 continue
             size_record.append(size)
             disks = utils_disk.get_windows_disks_index(session, size)
             if not disks:
                 test.fail("Fail to list image %s" % img)
             if not utils_disk.update_windows_disk_attributes(
                     session, disks):
                 test.fail("Failed to update windows disk attributes")
             for disk in disks:
                 d_letter = utils_disk.configure_empty_windows_disk(
                     session, disk, size)
             if not d_letter:
                 test.fail("Fail to format disks")
             mount_points.extend(d_letter)
     else:
         test.cancel("Unsupported OS type '%s'" % os_type)
     return mount_points
Beispiel #7
0
 def configure_data_disk(self):
     os_type = self.params["os_type"]
     disk_params = self.params.object_params(self.snapshot_tag)
     disk_size = disk_params["image_size"]
     session = self.main_vm.wait_for_login()
     try:
         if os_type != "windows":
             disk_id = self.get_linux_disk_path(session, disk_size)
             assert disk_id, "Disk not found in guest!"
             mount_point = utils_disk.configure_empty_linux_disk(
                 session, disk_id, disk_size)[0]
             self.disks_info.append([r"/dev/%s1" % disk_id, mount_point])
         else:
             disk_id = utils_disk.get_windows_disks_index(
                 session, disk_size)
             driver_letter = utils_disk.configure_empty_windows_disk(
                 session, disk_id, disk_size)[0]
             mount_point = r"%s:\\" % driver_letter
             self.disks_info.append([disk_id, mount_point])
     finally:
         session.close()
def io_test(session, disk_op_cmd, disks, windows=False, image_size=None):
    """
    Perform io test on disks
    :param session: vm session
    :param disk_op_cmd: The disk operation command
    :param plug_disks: The list of disks
    :param windows: If it is windows guest
    :param image_size: The size of images, only for windows
    """
    for index, disk in enumerate(disks):
        if windows:
            if not utils_disk.update_windows_disk_attributes(session, disk):
                raise exceptions.TestError("Failed to clear readonly for all"
                                           " disks and online them in guest")
            partition = utils_disk.configure_empty_windows_disk(
                session, disk, image_size)
            test_cmd = disk_op_cmd % (partition[0], partition[0])
            test_cmd = utils_misc.set_winutils_letter(session, test_cmd)
        else:
            test_cmd = disk_op_cmd % (disk, disk)
        session.cmd(test_cmd, timeout=360)
 def get_disk_op_cmd(disk_op_cmd, disk_size):
     """
     Find the disk driver letter and format the disk, and get
     disk driver letter,return disk_op_command
     """
     if os_type == "windows":
         disk_op_cmd = utils_misc.set_winutils_letter(session, disk_op_cmd)
         logging.info("Get windows disk index that to be formatted")
         disk_id = utils_disk.get_windows_disks_index(session, disk_size)
         if not utils_disk.update_windows_disk_attributes(session, disk_id):
             test.error("Failed to enable data disk %s" % disk_id)
         d_letter = utils_disk.configure_empty_windows_disk(session,
                                                            disk_id[0],
                                                            disk_size)[0]
         output_path = d_letter + ":\\test.dat"
     else:
         disks = utils_disk.get_linux_disks(session)
         for key, value in disks.items():
             if value[1] == disk_size and value[2] == "disk":
                 output_path = key
     if not output_path:
         test.fail("Can not get output file path in guest.")
     disk_op_cmd %= output_path
     return disk_op_cmd
def run(test, params, env):
    """
    Test the block write threshold for block devices.
    Steps:
        1. Create a data disk.
        2. Boot up the guest with a data disk attached.
        3. Set block write threshold for the data block drive in QMP.
        4. Login to guest then do stress io to trigger the threshold.
        5. Verify the event 'BLOCK_WRITE_THRESHOLD' in QMP.
        6. Set block write threshold to 0 for the data block drive in QMP
           which will not trigger the threshold.
        7. Login to guest then do stress io.
        8. Verify event 'BLOCK_WRITE_THRESHOLD' in QMP which should not be
           triggered.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    def get_node_name(image_tag):
        """ Get the node name. """
        img_params = params.object_params(image_tag)
        file = storage.get_image_filename(img_params, data_dir.get_data_dir())
        for block in vm.monitor.info("block"):
            if file == block['inserted']['file']:
                return block['inserted']['node-name']

    def set_block_write_threshold(monitor, node_name, size):
        """ Set block write threshold for the block drive. """
        error_context.context(
            "Set block write threshold to %s for the block "
            "drive in QMP." % size, logging.info)
        monitor.cmd('block-set-write-threshold', {
            "node-name": node_name,
            "write-threshold": size
        })

    def verify_block_write_threshold_event(monitor):
        """ Verify the event 'BLOCK_WRITE_THRESHOLD' in QMP. """
        return wait_for(lambda: monitor.get_event('BLOCK_WRITE_THRESHOLD'), 30)

    def get_data_disk(session):
        """ Get the data disk. """
        if is_linux:
            extra_params = params["blk_extra_params_%s" % data_img_tag]
            drive_id = re.search(r"(serial|wwn)=(\w+)", extra_params,
                                 re.M).group(2)
            return utils_misc.get_linux_drive_path(session, drive_id)
        return sorted(session.cmd('wmic diskdrive get index').split()[1:])[-1]

    def _io_stress_linux(target):
        session.cmd(params['dd_cmd'] % target, 180)

    def _io_stress_windows(target):
        fio = generate_instance(params, vm, 'fio')
        try:
            fio.run(params['fio_opts'] % target)
        finally:
            fio.clean()

    def run_io_stress(stress_func, target):
        """ Run io stress inside guest. """
        error_context.context("Run io stress inside guest.", logging.info)
        stress_func(target)

    is_linux = params['os_type'] == 'linux'
    data_img_tag = params['images'].split()[-1]
    data_img_size = params['image_size_%s' % data_img_tag]
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login(timeout=360)
    target = get_data_disk(session)
    if not is_linux:
        session = utils_test.qemu.windrv_check_running_verifier(
            session, vm, test, params['driver_name'])
        utils_disk.update_windows_disk_attributes(session, target)
        target = utils_disk.configure_empty_windows_disk(
            session, target, data_img_size)[-1]

    qmp_monitor = vm.monitors[0]
    node_name = get_node_name(data_img_tag)
    set_block_write_threshold(qmp_monitor, node_name,
                              int(params['threshold_size']))
    stress_func = locals()['_io_stress_%s' %
                           ('linux' if is_linux else 'windows')]
    run_io_stress(stress_func, target)
    if not verify_block_write_threshold_event(qmp_monitor):
        test.fail('Failed to get the event \'BLOCK_WRITE_THRESHOLD\'.')

    qmp_monitor.clear_event('BLOCK_WRITE_THRESHOLD')
    set_block_write_threshold(qmp_monitor, node_name, 0)
    run_io_stress(stress_func, target)
    if verify_block_write_threshold_event(qmp_monitor):
        test.fail('Failed to disable threshold.')
Beispiel #11
0
def run(test, params, env):
    """
    Test disk trimming in windows guest
    1) boot the vm with a data disk
    2) format the data disk without quick mode
    3) check the disk file size in host, and record for compare
    4) trim the data disk in guest
    5) check the disk file again in host, the file size should shrink

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    def _get_size_value(size_str):
        """
        Get size value form size string

        :param size_str: data size string
        :return: the size numeric value, measured by MB
        """
        size_str = utils_misc.normalize_data_size(size_str)
        size = float(size_str)
        return size

    def _disk_size_smaller(ori_size):
        """
        Check till the disk size becomes smaller than ori_size
        :param ori_size: original size to compare to
        :return: new size if it smaller than ori_size, else None
        """
        output = process.system_output(host_check_cmd, shell=True).decode()
        new_size = _get_size_value(str(output))
        logging.info("Current data disk size: %sMB", new_size)
        if new_size < ori_size:
            return new_size
        return None

    def query_system_events(filter_options):
        """Query the system events in filter options."""
        logging.info("Query the system event log.")
        cmd = params.get("query_cmd") % filter_options
        return params.get("searched_keywords") in session.cmd(cmd).strip()

    host_check_cmd = params.get("host_check_cmd")
    image_dir = os.path.join(data_dir.get_data_dir(), 'images')
    host_check_cmd %= image_dir
    image_name = params["stg_name"]
    stg_param = params.object_params(image_name)
    image_size_str = stg_param["image_size"]
    guest_trim_cmd = params["guest_trim_cmd"]
    driver_verifier = params["driver_verifier"]
    event_id = params.get("event_id")

    timeout = float(params.get("timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login(timeout=timeout)
    error_context.context("Check if the driver is installed and verified",
                          logging.info)
    session = utils_test.qemu.windrv_check_running_verifier(
        session, vm, test, driver_verifier, timeout)

    error_context.context("Format data disk", logging.info)
    disk_index = utils_misc.wait_for(
        lambda: utils_disk.get_windows_disks_index(session, image_size_str),
        120)
    if not disk_index:
        test.error("Failed to get the disk index of size %s" % image_size_str)
    if not utils_disk.update_windows_disk_attributes(session, disk_index):
        test.error("Failed to enable data disk %s" % disk_index)
    drive_letter_list = utils_disk.configure_empty_windows_disk(
        session, disk_index[0], image_size_str, quick_format=False)
    if not drive_letter_list:
        test.error("Failed to format the data disk")
    drive_letter = drive_letter_list[0]

    error_context.context("Check size from host before disk trimming")
    output = process.system_output(host_check_cmd, shell=True).decode()
    ori_size = _get_size_value(output)
    logging.info("Data disk size: %sMB", ori_size)

    error_context.context("Trim data disk in guest")
    status, output = session.cmd_status_output(guest_trim_cmd % drive_letter,
                                               timeout=timeout)
    if status:
        test.error("Error when trim the volume, status=%s, output=%s" %
                   (status, output))
    if event_id:
        time.sleep(10)
        session = vm.reboot(session)
        if query_system_events(params['filter_options']):
            test.fail("Disk corruption after trim for %s" %
                      params.get("block_size"))

    error_context.context("Check size from host after disk trimming")
    new_size = utils_misc.wait_for(lambda: _disk_size_smaller(ori_size), 20,
                                   10, 1)

    if new_size is None:
        test.error("Data disk size is not smaller than: %sMB" % ori_size)
def run(test, params, env):
    """
    Test to check the size of data disk increased can be detected
    automatically inside windows guest.

    Steps:
        1) Start a windows guest with a data disk and format it.
        2) Increase this data disk by qmp command.
        3) Copy a file to this data disk.
        4) The guest can detect the data disk size increased
           automatically.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    def increase_block_device(dev):
        """Increase the block device."""
        logging.info("Start to increase image '%s' to %s.", img,
                     img_resize_size)
        resize_size = int(
            float(
                normalize_data_size(
                    re.search(r'(\d+\.?(\d+)?\w)', img_resize_size).group(1),
                    "B")))
        args = (dev, resize_size)
        if vm.check_capability(Flags.BLOCKDEV):
            args = (None, resize_size, dev)
        vm.monitor.block_resize(*args)
        return resize_size

    def get_disk_size_by_diskpart(index):
        """Get the disk size by the diskpart."""
        cmd = ' && '.join(
            ("echo list disk > {0}", "echo exit >> {0}", "diskpart /s {0}",
             "del /f {0}")).format('disk_script')
        pattern = r'Disk\s+%s\s+Online\s+(\d+\s+\w+)\s+\d+\s+\w+' % index
        return re.search(pattern, session.cmd_output(cmd), re.M).group(1)

    def check_disk_size(index):
        """Check the disk size after increasing inside guest."""
        logging.info(
            'Check whether the size of disk %s is equal to %s after '
            'increasing inside guest.', index, img_resize_size)
        v, u = re.search(r"(\d+\.?\d*)\s*(\w?)", img_resize_size).groups()
        size = get_disk_size_by_diskpart(index)
        logging.info('The size of disk %s is %s', index, size)
        if normalize_data_size(size, u) != v:
            test.fail('The size of disk %s is not equal to %s' %
                      (index, img_resize_size))

    img = params.get("images").split()[-1]
    img_params = params.object_params(img)
    img_size = img_params.get("image_size")
    img_resize_size = img_params.get('image_resize_size')
    img_filename = storage.get_image_filename(img_params,
                                              data_dir.get_data_dir())

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = utils_test.qemu.windrv_check_running_verifier(
        vm.wait_for_login(), vm, test, 'viostor', 300)
    indices = utils_disk.get_windows_disks_index(session, img_size)
    utils_disk.update_windows_disk_attributes(session, indices)
    index = indices[0]
    mpoint = utils_disk.configure_empty_windows_disk(session, index,
                                                     img_size)[0]
    increase_block_device(vm.get_block({'file': img_filename}))
    vm.copy_files_to('/home/dd_file', "%s:\\dd_file" % mpoint)
    check_disk_size(index)