Ejemplo n.º 1
0
 def wrapped(self, *args, **dargs):
     try:
         return f(self, *args, **dargs)
     finally:
         if self._logger.global_filename == 'status':
             self.harness.run_test_complete()
             if self.drop_caches:
                 utils.drop_caches()
Ejemplo n.º 2
0
 def wrapped(self, *args, **dargs):
     try:
         return f(self, *args, **dargs)
     finally:
         if self._logger.global_filename == 'status':
             self.harness.run_test_complete()
             if self.drop_caches:
                 utils.drop_caches()
Ejemplo n.º 3
0
def run_boot_time(test, params, env):
    """
    KVM boot time test:
    1) Set init run level to 1
    2) Send a shutdown command to the guest, or issue a system_powerdown
       monitor command (depending on the value of shutdown_method)
    3) Boot up the guest and measure the boot time
    4) set init run level back to the old one

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

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

    error.context("Set guest run level to 1", logging.info)
    single_user_cmd = params['single_user_cmd']
    session.cmd(single_user_cmd)

    try:
        error.context("Shut down guest", logging.info)
        session.cmd('sync')
        vm.destroy()

        error.context("Boot up guest and measure the boot time", logging.info)
        utils.drop_caches()
        vm.create()
        vm.verify_alive()
        session = vm.wait_for_serial_login(timeout=timeout)
        boot_time = time.time() - vm.start_time
        expect_time = int(params.get("expect_bootup_time", "17"))
        logging.info("Boot up time: %ss" % boot_time)

    finally:
        try:
            error.context("Restore guest run level", logging.info)
            restore_level_cmd = params['restore_level_cmd']
            session.cmd(restore_level_cmd)
            session.cmd('sync')
            vm.destroy()
            vm.create()
            vm.verify_alive()
            vm.wait_for_login(timeout=timeout)
        except Exception:
            logging.Warn("Can not restore guest run level, "
                         "need restore the image")
            params["restore_image_after_testing"] = "yes"

    if boot_time > expect_time:
        raise error.TestFail("Guest boot up is taking too long: %ss" % boot_time)

    session.close()
Ejemplo n.º 4
0
 def _init_drop_caches(self, drop_caches):
     """
     Perform the drop caches initialization.
     """
     self.drop_caches_between_iterations = (settings.get_value('CLIENT',
                                            'drop_caches_between_iterations',
                                            type=bool, default=True))
     self.drop_caches = drop_caches
     if self.drop_caches:
         utils.drop_caches()
Ejemplo n.º 5
0
 def _init_drop_caches(self, drop_caches):
     """
     Perform the drop caches initialization.
     """
     self.drop_caches_between_iterations = (
                                 GLOBAL_CONFIG.get_config_value('CLIENT',
                                 'drop_caches_between_iterations',
                                 type=bool, default=True))
     self.drop_caches = drop_caches
     if self.drop_caches:
         utils.drop_caches()
Ejemplo n.º 6
0
        except Exception, info:
            raise Exception("mount failed: exception = %s, args = %s" %
                                             (type(info), info.args))

        # If we skipped mkfs we need to wipe the partition clean
        if skip_mkfs:
            fs.wipe()

        # Record the new file system type and options in the disk list
        disk["mounted"] = True
        disk["fs_type"] = fs_type
        disk["fs_mkfs"] = fs_makeopt
        disk["fs_opts"] = fs_mnt_opt

    # Try to wipe the file system slate clean
    utils.drop_caches()


# XXX(gps): Remove this code once refactoring is complete to get rid of these
# nasty test description strings.
def _legacy_str_to_test_flags(fs_desc_string):
    """Convert a legacy FS_LIST string into a partition.FsOptions instance."""
    match = re.search('(.*?)/(.*?)/(.*?)/(.*)$', fs_desc_string.strip())
    if not match:
        raise ValueError('unrecognized FS list entry %r' % fs_desc_string)

    flags_obj = partition.FsOptions(fstype=match.group(1).strip(),
                                    mkfs_flags=match.group(2).strip(),
                                    mount_options=match.group(3).strip(),
                                    fs_tag=match.group(4).strip())
    return flags_obj
Ejemplo n.º 7
0
 def drop_caches_between_iterations(self):
     if self.job.drop_caches_between_iterations:
         utils.drop_caches()
Ejemplo n.º 8
0
 def drop_caches_between_iterations(self):
     if self.job.drop_caches_between_iterations:
         utils.drop_caches()
Ejemplo n.º 9
0
    def run_once(self, mount_point, file_count, write_size,
                 max_flush_time=1, file_system=None, remove_previous=False,
                 sparse_file=os.path.join(os.getcwd(),'sparse_file'),
                 old_cleanup=False):
        """
        Control execution of the test.

        @param mount_point: the absolute path to the mount point.
        @param file_count: the number of files to write.
        @param write_size: the size of each file in MB.
        @param max_flush_time: the maximum time to wait for the writeback to
                flush dirty data to disk. Default = 1 minute.
        @param file_system: the new file system to be mounted, if any.
                Default = None.
        @param remove_previous: boolean that allows the removal of previous
                files before creating a new one. Default = False.
        @param sparse_file: the absolute path to the sparse file.
        @param old_cleanup: removes previous mount_point if it exists and is
                not mounted. Default is False.
        """
        # Check validity of parameters.
        self._check_parameters(mount_point, write_size, file_count,
                               old_cleanup)

        # Initialize class variables.
        self.mount_point = mount_point
        self.sparse_file = sparse_file
        self.file_system = file_system

        # Initialize partition values.
        self._create_partition()

        # Flush read and write cache.
        utils.drop_caches()

        # Start iterations.
        logging.info('Starting test operations.')
        test_start_time = datetime.datetime.now()
        counter = 1

        # Run test until file_count files are successfully written to disk.
        while counter < file_count:
            logging.info('Iteration %s.', counter)

            # Write data to disk.
            write_completion_time = self._write_data(self.mount_point, counter,
                                                     write_size)
            logging.debug('Write time:%s',
                          write_completion_time.strftime("%H:%M:%S"))

            # Wait until data get synced to disk.
            time_taken = self._wait_until_data_flushed(write_completion_time,
                                                       max_flush_time)

            # Log time statistics.
            logging.info('Time taken to flush data: %s seconds.',
                         time_taken.seconds)

            # Check if there is a need to remove the previously written file.
            if remove_previous:
                logging.debug('Removing previous file instance.')
                os.remove(sparse_file)
            else:
                logging.debug('Not removing previous file instance.')

            # Flush cache.
            logging.debug('Flush cache between iterations.')
            utils.drop_caches()

           # Update the result map.
            self.result_map[counter] = time_taken.seconds

            # Increment the counter.
            counter += 1
Ejemplo n.º 10
0
    def run_once(self,
                 mount_point,
                 file_count,
                 write_size,
                 max_flush_time=1,
                 file_system=None,
                 remove_previous=False,
                 sparse_file=os.path.join(os.getcwd(), 'sparse_file'),
                 old_cleanup=False):
        """
        Control execution of the test.

        @param mount_point: the absolute path to the mount point.
        @param file_count: the number of files to write.
        @param write_size: the size of each file in MB.
        @param max_flush_time: the maximum time to wait for the writeback to
                flush dirty data to disk. Default = 1 minute.
        @param file_system: the new file system to be mounted, if any.
                Default = None.
        @param remove_previous: boolean that allows the removal of previous
                files before creating a new one. Default = False.
        @param sparse_file: the absolute path to the sparse file.
        @param old_cleanup: removes previous mount_point if it exists and is
                not mounted. Default is False.
        """
        # Check validity of parameters.
        self._check_parameters(mount_point, write_size, file_count,
                               old_cleanup)

        # Initialize class variables.
        self.mount_point = mount_point
        self.sparse_file = sparse_file
        self.file_system = file_system

        # Initialize partition values.
        self._create_partition()

        # Flush read and write cache.
        utils.drop_caches()

        # Start iterations.
        logging.info('Starting test operations.')
        test_start_time = datetime.datetime.now()
        counter = 1

        # Run test until file_count files are successfully written to disk.
        while counter < file_count:
            logging.info('Iteration %s.', counter)

            # Write data to disk.
            write_completion_time = self._write_data(self.mount_point, counter,
                                                     write_size)
            logging.debug('Write time:%s',
                          write_completion_time.strftime("%H:%M:%S"))

            # Wait until data get synced to disk.
            time_taken = self._wait_until_data_flushed(write_completion_time,
                                                       max_flush_time)

            # Log time statistics.
            logging.info('Time taken to flush data: %s seconds.',
                         time_taken.seconds)

            # Check if there is a need to remove the previously written file.
            if remove_previous:
                logging.debug('Removing previous file instance.')
                os.remove(sparse_file)
            else:
                logging.debug('Not removing previous file instance.')

            # Flush cache.
            logging.debug('Flush cache between iterations.')
            utils.drop_caches()

            # Update the result map.
            self.result_map[counter] = time_taken.seconds

            # Increment the counter.
            counter += 1
Ejemplo n.º 11
0
        except Exception, info:
            raise Exception("mount failed: exception = %s, args = %s" %
                           (type(info), info.args))

        # If we skipped mkfs we need to wipe the partition clean
        if skip_mkfs:
            fs.wipe()

        # Record the new file system type and options in the disk list
        disk["mounted"] = True
        disk["fs_type"] = fs_type
        disk["fs_mkfs"] = fs_makeopt
        disk["fs_opts"] = fs_mnt_opt

    # Try to wipe the file system slate clean
    utils.drop_caches()


# XXX(gps): Remove this code once refactoring is complete to get rid of these
# nasty test description strings.
def _legacy_str_to_test_flags(fs_desc_string):
    """Convert a legacy FS_LIST string into a partition.FsOptions instance."""
    match = re.search('(.*?)/(.*?)/(.*?)/(.*)$', fs_desc_string.strip())
    if not match:
        raise ValueError('unrecognized FS list entry %r' % fs_desc_string)

    flags_obj = partition.FsOptions(fstype=match.group(1).strip(),
                                    mkfs_flags=match.group(2).strip(),
                                    mount_options=match.group(3).strip(),
                                    fs_tag=match.group(4).strip())
    return flags_obj
Ejemplo n.º 12
0
def mkfs_all_disks(job, disk_list, fs_type, fs_makeopt, fs_mnt_opt):
    """
    Prepare all the drives in 'disk_list' for testing. For each disk this means
    unmounting any mount points that use the disk, running mkfs with 'fs_type'
    as the file system type and 'fs_makeopt' as the 'mkfs' options, and finally
    remounting the freshly formatted drive using the flags in 'fs_mnt_opt'.
    """

    for disk in disk_list:

        # For now, ext4 isn't quite ready for prime time
        if fs_type == "ext4":
            fs_type = "ext4dev"

        # Grab the device and mount paths for the drive
        dev_path = os.path.join('/dev', disk["device"])
        mnt_path = disk['mountpt']

        # Create a file system instance
        try:
            fs = job.filesystem(device=dev_path, mountpoint=mnt_path)
        except Exception:
            raise Exception("Could not create a filesystem on '%s'" % dev_path)

        # Make sure the volume is unmounted
        if disk["mounted"]:
            try:
                fs.unmount(mnt_path)
            except Exception as info:
                raise Exception("umount failed: exception = %s, args = %s" %
                                (sys.exc_info()[0], info.args))
            except Exception:
                raise Exception("Could not unmount device ", dev_path)

        # Is the drive already formatted with the right file system?
        skip_mkfs = match_fs(disk, dev_path, fs_type, fs_makeopt)

        # Next step is to create a fresh file system (if we need to)
        try:
            if not skip_mkfs:
                fs.mkfs(fstype=fs_type, args=fs_makeopt)
        except Exception:
            raise Exception("Could not 'mkfs " + "-t " + fs_type + " " +
                            fs_makeopt + " " + dev_path + "'")

        # Mount the drive with the appropriate FS options
        try:
            opts = ""
            if fs_mnt_opt != "":
                opts += " -o " + fs_mnt_opt
            fs.mount(mountpoint=mnt_path, fstype=fs_type, args=opts)
        except NameError as info:
            raise Exception("mount name error: %s" % info)
        except Exception as info:
            raise Exception("mount failed: exception = %s, args = %s" %
                            (type(info), info.args))

        # If we skipped mkfs we need to wipe the partition clean
        if skip_mkfs:
            fs.wipe()

        # Record the new file system type and options in the disk list
        disk["mounted"] = True
        disk["fs_type"] = fs_type
        disk["fs_mkfs"] = fs_makeopt
        disk["fs_opts"] = fs_mnt_opt

    # Try to wipe the file system slate clean
    utils.drop_caches()