def create_encrypted_devices(ctx, config, managers): for client, client_config in config.items(): disks = client_config['disks'] for disk in disks: if disk['encryption_format'] == 'none' or \ 'device_letter' not in disk: continue dev_config = {client: disk} managers.append(lambda dev_config=dev_config: rbd.dev_create( ctx=ctx, config=dev_config))
def download_image(ctx, config): """Downland base image, remove image file when done""" log.info('downloading base image') testdir = teuthology.get_testdir(ctx) client_base_files = {} for client, client_config in config.items(): (remote, ) = ctx.cluster.only(client).remotes.keys() client_base_files[client] = [] disks = client_config['disks'] for disk in disks: if disk['action'] != 'create' or 'image_url' not in disk: continue base_file = '{tdir}/qemu/base.{name}.qcow2'.format( tdir=testdir, name=disk['image_name']) client_base_files[client].append(base_file) remote.run(args=[ 'wget', '-nv', '-O', base_file, disk['image_url'], ]) if disk['encryption_format'] == 'none': remote.run(args=[ 'qemu-img', 'convert', '-f', 'qcow2', '-O', 'raw', base_file, 'rbd:rbd/{image_name}'.format( image_name=disk['image_name']) ]) else: dev_config = { client: { 'image_name': disk['image_name'], 'encryption_format': disk['encryption_format'] } } raw_file = '{tdir}/qemu/base.{name}.raw'.format( tdir=testdir, name=disk['image_name']) client_base_files[client].append(raw_file) remote.run(args=[ 'qemu-img', 'convert', '-f', 'qcow2', '-O', 'raw', base_file, raw_file ]) with rbd.dev_create(ctx, dev_config): remote.run(args=[ 'dd', 'if={name}'.format( name=raw_file), 'of={name}'.format( name=dev_config[client]['device_path']), 'bs=4M', 'conv=fdatasync' ]) for disk in disks: if disk['action'] == 'clone' or \ disk['encryption_format'] != 'none' or \ (disk['action'] == 'create' and 'image_url' not in disk): continue remote.run(args=[ 'rbd', 'resize', '--size={image_size}M'.format( image_size=disk['image_size']), disk['image_name'], run.Raw('||'), 'true' ]) try: yield finally: log.debug('cleaning up base image files') for client, base_files in client_base_files.items(): (remote, ) = ctx.cluster.only(client).remotes.keys() for base_file in base_files: remote.run(args=[ 'rm', '-f', base_file, ], )