예제 #1
0
파일: node.py 프로젝트: vrautela/treadmill
    def benchmark(benchmark_publish_file, vg_name, underlying_device_name,
                  underlying_image_path, benchmark_volume, rw_type, job_number,
                  thread_number, iops_block_size, bps_block_size, max_seconds):
        """Benchmark node IO performance"""
        try:
            if underlying_device_name is not None:
                # LVM is based on physical device,
                # benchmark VG directly
                underlying_device_uuid = fs_linux.blk_uuid(
                    underlying_device_name)
                max_iops_result = diskbenchmark.benchmark_vg(
                    vg_name, benchmark_volume, rw_type, job_number,
                    thread_number, iops_block_size, max_seconds)
                max_bps_result = diskbenchmark.benchmark_vg(
                    vg_name, benchmark_volume, rw_type, job_number,
                    thread_number, bps_block_size, max_seconds)
            elif underlying_image_path is not None:
                # LVM is based on loop device,
                # benchmark underlying physical device of image file
                underlying_device_uuid = fs_linux.blk_uuid(
                    fs_linux.maj_min_to_blk(
                        *fs_linux.maj_min_from_path(underlying_image_path)))
                benchmark_path = os.path.join(underlying_image_path,
                                              'benchmark')
                max_iops_result = diskbenchmark.benchmark(
                    benchmark_path, benchmark_volume, rw_type, job_number,
                    thread_number, iops_block_size, max_seconds)
                max_bps_result = diskbenchmark.benchmark(
                    benchmark_path, benchmark_volume, rw_type, job_number,
                    thread_number, bps_block_size, max_seconds)
                if os.path.isdir(benchmark_path):
                    shutil.rmtree(benchmark_path)
            else:
                _LOGGER.error('No underlying device, please specify '
                              '--underlying-device-name/'
                              '--underlying-image-path')
                return

            diskbenchmark.write(
                benchmark_publish_file, {
                    underlying_device_uuid: {
                        'read_bps': max_bps_result['read_bps'],
                        'write_bps': max_bps_result['write_bps'],
                        'read_iops': max_iops_result['read_iops'],
                        'write_iops': max_iops_result['write_iops']
                    }
                })
        except subproc.CommandAliasError:
            _LOGGER.error(_ALIAS_ERROR_MESSAGE)
예제 #2
0
    def localdisk(img_location, img_size, block_dev, vg_name,
                  block_dev_configuration, block_dev_read_bps,
                  block_dev_write_bps, block_dev_read_iops,
                  block_dev_write_iops, default_read_bps, default_write_bps,
                  default_read_iops, default_write_iops):
        """Runs localdisk service."""

        root_dir = local_ctx['root-dir']
        watchdogs_dir = local_ctx['watchdogs-dir']

        svc = services.ResourceService(service_dir=os.path.join(
            root_dir, 'localdisk_svc'),
                                       impl='localdisk')

        block_dev_params = [
            block_dev_read_bps, block_dev_write_bps, block_dev_read_iops,
            block_dev_write_iops
        ]
        if img_location is None:
            img_location = root_dir

        # prepare block device
        if block_dev is not None:
            underlying_device_uuid = fs_linux.blk_uuid(block_dev)
        else:
            underlying_device_uuid = fs_linux.blk_uuid(
                fs_linux.maj_min_to_blk(
                    *fs_linux.maj_min_from_path(img_location)))
            block_dev = localdiskutils.init_block_dev(
                localdiskutils.TREADMILL_IMG, img_location, img_size)

        # prepare block device configuration
        read_bps = None
        write_bps = None
        read_iops = None
        write_iops = None

        # use block device config file
        if block_dev_configuration is not None and all(
                param is None for param in block_dev_params):
            try:
                current_benchmark = diskbenchmark.read(
                    block_dev_configuration)[underlying_device_uuid]
                read_bps = current_benchmark['read_bps']
                write_bps = current_benchmark['write_bps']
                read_iops = int(current_benchmark['read_iops'])
                write_iops = int(current_benchmark['write_iops'])
            except IOError:
                _LOGGER.error('No benchmark found : %s',
                              block_dev_configuration)
            except (KeyError, ValueError):
                _LOGGER.error('Incorrect disk benchmark for device %s in %s',
                              underlying_device_uuid, block_dev_configuration)

        # use block device config parameters
        if all(param is not None for param in
               block_dev_params) and block_dev_configuration is None:
            read_bps = block_dev_read_bps
            write_bps = block_dev_write_bps
            read_iops = block_dev_read_iops
            write_iops = block_dev_write_iops

        if None in [read_bps, write_bps, read_iops, write_iops]:
            _LOGGER.error('Bad block dev configuration')
            read_bps = '200M'
            write_bps = '200M'
            read_iops = 3000
            write_iops = 3000

        svc.run(
            watchdogs_dir=os.path.join(root_dir, watchdogs_dir),
            block_dev=block_dev,
            vg_name=vg_name,
            read_bps=read_bps,
            write_bps=write_bps,
            read_iops=read_iops,
            write_iops=write_iops,
            default_read_bps=default_read_bps,
            default_write_bps=default_write_bps,
            default_read_iops=default_read_iops,
            default_write_iops=default_write_iops,
        )