コード例 #1
0
ファイル: instance.py プロジェクト: GrammaB/treadmill
def _validate(rsrc):
    """Validate instance manifest."""
    memory_mb = utils.megabytes(rsrc['memory'])
    if memory_mb < 100:
        raise exc.TreadmillError(
            'memory size should be larger than or equal to 100M')

    disk_mb = utils.megabytes(rsrc['disk'])
    if disk_mb < 100:
        raise exc.TreadmillError(
            'disk size should be larger than or equal to 100M')
コード例 #2
0
def benchmark_vg(vg_name,
                 volume=BENCHMARK_VOLUME,
                 rw_type=BENCHMARK_RW_TYPE,
                 job_number=BENCHMARK_JOB_NUMBER,
                 thread_number=BENCHMARK_THREAD_NUMBER,
                 block_size=BENCHMARK_IOPS_BLOCK_SIZE,
                 max_seconds=BENCHMARK_MAX_SECONDS,
                 base_path=None,
                 sys_reserve_volume='500M',
                 benchmark_lv='benchmarklv'):
    """Benchmark IO performance of the specified VG

    :param vg_name:
        vg to benchmark
    :param volume:
        small volume leads to inaccurate benchmark,
        large volume takes too much time
    :param rw_type:
        fio rw option
    :param job_number:
        fio numjobs option
    :param thread_number:
        fio iodepth option
    :param block_size:
        fio bs option
    :param max_seconds:
        fio runtime option
    :param base_path:
        benchmark lv mount point
    :param sys_reserve_volume:
        reserved space for system usage like mke2fs
    :param benchmark_lv:
        benchmark lv name
    """

    device = os.path.join('/dev', vg_name, benchmark_lv)
    if base_path is None:
        base_path = tempfile.mkdtemp()
        is_temp_base = True
    else:
        is_temp_base = False
    total_volume = '{}M'.format(
        utils.megabytes(volume) * int(job_number) +
        utils.megabytes(sys_reserve_volume))

    def check_available_volume():
        """Check if we have enough space for benchmark.
        """
        vg_status = localdiskutils.refresh_vg_status(vg_name)
        available_volume = vg_status['extent_size'] * \
            vg_status['extent_free']
        return available_volume > utils.size_to_bytes(total_volume)

    def setup_benchmark_env():
        """Prepare environment for benchmark.
        """
        lvm.lvcreate(volume=benchmark_lv,
                     group=vg_name,
                     size_in_bytes=utils.size_to_bytes(total_volume))
        fs_linux.blk_fs_create(device)
        fs_linux.mount_filesystem(device, base_path, fs_type='ext4')

    def cleanup_benchmark_env():
        """Cleanup environment after benchmark.
        """
        try:
            fs_linux.umount_filesystem(base_path)
        except OSError:
            _LOGGER.exception('umount error')
        if is_temp_base and os.path.isdir(base_path):
            shutil.rmtree(base_path)
        try:
            lvm.lvremove(benchmark_lv, group=vg_name)
        except subproc.CalledProcessError:
            _LOGGER.exception('lvremove error')

    if not check_available_volume():
        _LOGGER.error('Space not enough for benchmark,'
                      'need at least %s', total_volume)
        return None

    try:
        _LOGGER.info('Setup benchmark env')
        setup_benchmark_env()
        _LOGGER.info('Start benchmark')
        return benchmark(base_path, volume, rw_type, job_number, thread_number,
                         block_size, max_seconds)
    except Exception:  # pylint: disable=W0703
        _LOGGER.exception('Benchmark failed')
        raise
    finally:
        _LOGGER.info('Cleanup benchmark env')
        cleanup_benchmark_env()