2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Qemu task
|
|
|
|
"""
|
2012-06-19 21:13:39 +00:00
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
import contextlib
|
|
|
|
import logging
|
|
|
|
import os
|
2016-12-20 00:45:12 +00:00
|
|
|
import yaml
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
|
|
|
from teuthology import contextutil
|
2014-08-07 14:24:59 +00:00
|
|
|
from tasks import rbd
|
|
|
|
from teuthology.orchestra import run
|
2017-01-07 12:45:10 +00:00
|
|
|
from teuthology.config import config as teuth_config
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2016-12-20 14:25:33 +00:00
|
|
|
DEFAULT_NUM_DISKS = 2
|
2017-01-17 03:12:51 +00:00
|
|
|
DEFAULT_IMAGE_URL = 'http://download.ceph.com/qa/ubuntu-12.04.qcow2'
|
2016-12-20 14:25:33 +00:00
|
|
|
DEFAULT_IMAGE_SIZE = 10240 # in megabytes
|
2013-03-12 19:12:58 +00:00
|
|
|
DEFAULT_MEM = 4096 # in megabytes
|
2012-06-19 21:13:39 +00:00
|
|
|
|
2015-10-21 20:27:08 +00:00
|
|
|
def create_images(ctx, config, managers):
|
|
|
|
for client, client_config in config.iteritems():
|
2016-12-20 14:25:33 +00:00
|
|
|
disks = client_config.get('disks', DEFAULT_NUM_DISKS)
|
|
|
|
if not isinstance(disks, list):
|
|
|
|
disks = [{} for n in range(int(disks))]
|
2015-10-21 20:27:08 +00:00
|
|
|
clone = client_config.get('clone', False)
|
2016-12-20 14:25:33 +00:00
|
|
|
assert disks, 'at least one rbd device must be used'
|
|
|
|
for i, disk in enumerate(disks[1:]):
|
2015-10-21 20:27:08 +00:00
|
|
|
create_config = {
|
|
|
|
client: {
|
2016-12-20 14:25:33 +00:00
|
|
|
'image_name': '{client}.{num}'.format(client=client,
|
|
|
|
num=i + 1),
|
2015-10-21 20:27:08 +00:00
|
|
|
'image_format': 2 if clone else 1,
|
2016-12-20 14:25:33 +00:00
|
|
|
'image_size': (disk or {}).get('image_size',
|
|
|
|
DEFAULT_IMAGE_SIZE),
|
2015-10-21 20:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
managers.append(
|
|
|
|
lambda create_config=create_config:
|
|
|
|
rbd.create_image(ctx=ctx, config=create_config)
|
|
|
|
)
|
|
|
|
|
|
|
|
def create_clones(ctx, config, managers):
|
|
|
|
for client, client_config in config.iteritems():
|
|
|
|
clone = client_config.get('clone', False)
|
|
|
|
if clone:
|
2016-12-20 14:25:33 +00:00
|
|
|
num_disks = client_config.get('disks', DEFAULT_NUM_DISKS)
|
|
|
|
if isinstance(num_disks, list):
|
|
|
|
num_disks = len(num_disks)
|
|
|
|
for i in xrange(num_disks):
|
2015-10-21 20:27:08 +00:00
|
|
|
create_config = {
|
|
|
|
client: {
|
|
|
|
'image_name':
|
|
|
|
'{client}.{num}-clone'.format(client=client, num=i),
|
|
|
|
'parent_name':
|
|
|
|
'{client}.{num}'.format(client=client, num=i),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
managers.append(
|
|
|
|
lambda create_config=create_config:
|
|
|
|
rbd.clone_image(ctx=ctx, config=create_config)
|
|
|
|
)
|
|
|
|
|
2012-06-19 21:13:39 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def create_dirs(ctx, config):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Handle directory creation and cleanup
|
|
|
|
"""
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2012-06-19 21:13:39 +00:00
|
|
|
for client, client_config in config.iteritems():
|
|
|
|
assert 'test' in client_config, 'You must specify a test to run'
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'install', '-d', '-m0755', '--',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/qemu'.format(tdir=testdir),
|
|
|
|
'{tdir}/archive/qemu'.format(tdir=testdir),
|
2012-06-19 21:13:39 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
for client, client_config in config.iteritems():
|
|
|
|
assert 'test' in client_config, 'You must specify a test to run'
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
2013-01-23 20:37:39 +00:00
|
|
|
'rmdir', '{tdir}/qemu'.format(tdir=testdir), run.Raw('||'), 'true',
|
2012-06-19 21:13:39 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def generate_iso(ctx, config):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""Execute system commands to generate iso"""
|
2012-06-19 21:13:39 +00:00
|
|
|
log.info('generating iso...')
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2017-01-07 12:45:10 +00:00
|
|
|
|
|
|
|
# use ctx.config instead of config, because config has been
|
|
|
|
# through teuthology.replace_all_with_clients()
|
|
|
|
refspec = ctx.config.get('branch')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = ctx.config.get('tag')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = ctx.config.get('sha1')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = 'HEAD'
|
|
|
|
|
|
|
|
# hack: the git_url is always ceph-ci or ceph
|
|
|
|
git_url = teuth_config.get_ceph_git_url()
|
|
|
|
repo_name = 'ceph.git'
|
|
|
|
if git_url.count('ceph-ci'):
|
|
|
|
repo_name = 'ceph-ci.git'
|
|
|
|
|
2012-06-19 21:13:39 +00:00
|
|
|
for client, client_config in config.iteritems():
|
|
|
|
assert 'test' in client_config, 'You must specify a test to run'
|
2017-01-07 12:45:10 +00:00
|
|
|
test_url = client_config['test'].format(repo=repo_name, branch=refspec)
|
2015-02-19 18:35:25 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2012-06-19 21:13:39 +00:00
|
|
|
src_dir = os.path.dirname(__file__)
|
2013-01-23 20:37:39 +00:00
|
|
|
userdata_path = os.path.join(testdir, 'qemu', 'userdata.' + client)
|
|
|
|
metadata_path = os.path.join(testdir, 'qemu', 'metadata.' + client)
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
with file(os.path.join(src_dir, 'userdata_setup.yaml'), 'rb') as f:
|
|
|
|
test_setup = ''.join(f.readlines())
|
2015-02-19 18:35:25 +00:00
|
|
|
# configuring the commands to setup the nfs mount
|
|
|
|
mnt_dir = "/export/{client}".format(client=client)
|
|
|
|
test_setup = test_setup.format(
|
|
|
|
mnt_dir=mnt_dir
|
|
|
|
)
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
with file(os.path.join(src_dir, 'userdata_teardown.yaml'), 'rb') as f:
|
|
|
|
test_teardown = ''.join(f.readlines())
|
|
|
|
|
|
|
|
user_data = test_setup
|
|
|
|
if client_config.get('type', 'filesystem') == 'filesystem':
|
2016-12-20 14:25:33 +00:00
|
|
|
num_disks = client_config.get('disks', DEFAULT_NUM_DISKS)
|
|
|
|
if isinstance(num_disks, list):
|
|
|
|
num_disks = len(num_disks)
|
|
|
|
for i in xrange(1, num_disks):
|
|
|
|
dev_letter = chr(ord('a') + i)
|
2012-06-19 21:13:39 +00:00
|
|
|
user_data += """
|
|
|
|
- |
|
|
|
|
#!/bin/bash
|
|
|
|
mkdir /mnt/test_{dev_letter}
|
|
|
|
mkfs -t xfs /dev/vd{dev_letter}
|
|
|
|
mount -t xfs /dev/vd{dev_letter} /mnt/test_{dev_letter}
|
|
|
|
""".format(dev_letter=dev_letter)
|
|
|
|
|
2016-12-20 00:45:12 +00:00
|
|
|
cloud_config_archive = client_config.get('cloud_config_archive', [])
|
|
|
|
if cloud_config_archive:
|
|
|
|
user_data += yaml.safe_dump(cloud_config_archive, default_style='|',
|
|
|
|
default_flow_style=False)
|
|
|
|
|
2012-06-19 21:13:39 +00:00
|
|
|
# this may change later to pass the directories as args to the
|
|
|
|
# script or something. xfstests needs that.
|
|
|
|
user_data += """
|
|
|
|
- |
|
|
|
|
#!/bin/bash
|
|
|
|
test -d /mnt/test_b && cd /mnt/test_b
|
|
|
|
/mnt/cdrom/test.sh > /mnt/log/test.log 2>&1 && touch /mnt/log/success
|
|
|
|
""" + test_teardown
|
|
|
|
|
|
|
|
teuthology.write_file(remote, userdata_path, StringIO(user_data))
|
|
|
|
|
|
|
|
with file(os.path.join(src_dir, 'metadata.yaml'), 'rb') as f:
|
|
|
|
teuthology.write_file(remote, metadata_path, f)
|
|
|
|
|
2013-01-23 20:37:39 +00:00
|
|
|
test_file = '{tdir}/qemu/{client}.test.sh'.format(tdir=testdir, client=client)
|
2017-01-07 12:45:10 +00:00
|
|
|
|
|
|
|
log.info('fetching test %s for %s', test_url, client)
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'wget', '-nv', '-O', test_file,
|
2017-01-07 12:45:10 +00:00
|
|
|
test_url,
|
2012-06-19 21:13:39 +00:00
|
|
|
run.Raw('&&'),
|
|
|
|
'chmod', '755', test_file,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'genisoimage', '-quiet', '-input-charset', 'utf-8',
|
|
|
|
'-volid', 'cidata', '-joliet', '-rock',
|
2013-01-23 20:37:39 +00:00
|
|
|
'-o', '{tdir}/qemu/{client}.iso'.format(tdir=testdir, client=client),
|
2012-06-19 21:13:39 +00:00
|
|
|
'-graft-points',
|
|
|
|
'user-data={userdata}'.format(userdata=userdata_path),
|
|
|
|
'meta-data={metadata}'.format(metadata=metadata_path),
|
|
|
|
'test.sh={file}'.format(file=test_file),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
for client in config.iterkeys():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rm', '-f',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/qemu/{client}.iso'.format(tdir=testdir, client=client),
|
|
|
|
os.path.join(testdir, 'qemu', 'userdata.' + client),
|
|
|
|
os.path.join(testdir, 'qemu', 'metadata.' + client),
|
|
|
|
'{tdir}/qemu/{client}.test.sh'.format(tdir=testdir, client=client),
|
2012-06-19 21:13:39 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def download_image(ctx, config):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""Downland base image, remove image file when done"""
|
2012-06-19 21:13:39 +00:00
|
|
|
log.info('downloading base image')
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2012-06-19 21:13:39 +00:00
|
|
|
for client, client_config in config.iteritems():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2013-01-23 20:37:39 +00:00
|
|
|
base_file = '{tdir}/qemu/base.{client}.qcow2'.format(tdir=testdir, client=client)
|
2016-12-20 01:52:06 +00:00
|
|
|
image_url = client_config.get('image_url', DEFAULT_IMAGE_URL)
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
2016-12-20 01:52:06 +00:00
|
|
|
'wget', '-nv', '-O', base_file, image_url,
|
2012-06-19 21:13:39 +00:00
|
|
|
]
|
|
|
|
)
|
2016-12-20 14:25:33 +00:00
|
|
|
|
|
|
|
disks = client_config.get('disks', None)
|
|
|
|
if not isinstance(disks, list):
|
|
|
|
disks = [{}]
|
|
|
|
image_name = '{client}.0'.format(client=client)
|
|
|
|
image_size = (disks[0] or {}).get('image_size', DEFAULT_IMAGE_SIZE)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'qemu-img', 'convert', '-f', 'qcow2', '-O', 'raw',
|
|
|
|
base_file, 'rbd:rbd/{image_name}'.format(image_name=image_name)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rbd', 'resize',
|
|
|
|
'--size={image_size}M'.format(image_size=image_size),
|
|
|
|
image_name,
|
|
|
|
]
|
|
|
|
)
|
2012-06-19 21:13:39 +00:00
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.debug('cleaning up base image files')
|
|
|
|
for client in config.iterkeys():
|
2013-01-23 20:37:39 +00:00
|
|
|
base_file = '{tdir}/qemu/base.{client}.qcow2'.format(
|
|
|
|
tdir=testdir,
|
2012-06-19 21:13:39 +00:00
|
|
|
client=client,
|
|
|
|
)
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rm', '-f', base_file,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2015-02-19 18:35:25 +00:00
|
|
|
|
|
|
|
def _setup_nfs_mount(remote, client, mount_dir):
|
|
|
|
"""
|
|
|
|
Sets up an nfs mount on the remote that the guest can use to
|
|
|
|
store logs. This nfs mount is also used to touch a file
|
|
|
|
at the end of the test to indiciate if the test was successful
|
|
|
|
or not.
|
|
|
|
"""
|
|
|
|
export_dir = "/export/{client}".format(client=client)
|
|
|
|
log.info("Creating the nfs export directory...")
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'mkdir', '-p', export_dir,
|
|
|
|
])
|
|
|
|
log.info("Mounting the test directory...")
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'mount', '--bind', mount_dir, export_dir,
|
|
|
|
])
|
|
|
|
log.info("Adding mount to /etc/exports...")
|
|
|
|
export = "{dir} *(rw,no_root_squash,no_subtree_check,insecure)".format(
|
|
|
|
dir=export_dir
|
|
|
|
)
|
2015-08-31 14:25:53 +00:00
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'sed', '-i', '/^\/export\//d', "/etc/exports",
|
|
|
|
])
|
2015-02-19 18:35:25 +00:00
|
|
|
remote.run(args=[
|
|
|
|
'echo', export, run.Raw("|"),
|
|
|
|
'sudo', 'tee', '-a', "/etc/exports",
|
|
|
|
])
|
|
|
|
log.info("Restarting NFS...")
|
|
|
|
if remote.os.package_type == "deb":
|
|
|
|
remote.run(args=['sudo', 'service', 'nfs-kernel-server', 'restart'])
|
|
|
|
else:
|
2015-03-04 14:57:03 +00:00
|
|
|
remote.run(args=['sudo', 'systemctl', 'restart', 'nfs'])
|
2015-02-19 18:35:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _teardown_nfs_mount(remote, client):
|
|
|
|
"""
|
|
|
|
Tears down the nfs mount on the remote used for logging and reporting the
|
|
|
|
status of the tests being ran in the guest.
|
|
|
|
"""
|
|
|
|
log.info("Tearing down the nfs mount for {remote}".format(remote=remote))
|
|
|
|
export_dir = "/export/{client}".format(client=client)
|
|
|
|
log.info("Stopping NFS...")
|
|
|
|
if remote.os.package_type == "deb":
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'service', 'nfs-kernel-server', 'stop'
|
|
|
|
])
|
|
|
|
else:
|
|
|
|
remote.run(args=[
|
2015-03-04 14:57:03 +00:00
|
|
|
'sudo', 'systemctl', 'stop', 'nfs'
|
2015-02-19 18:35:25 +00:00
|
|
|
])
|
|
|
|
log.info("Unmounting exported directory...")
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'umount', export_dir
|
|
|
|
])
|
|
|
|
log.info("Deleting exported directory...")
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'rm', '-r', '/export'
|
|
|
|
])
|
|
|
|
log.info("Deleting export from /etc/exports...")
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'sed', '-i', '$ d', '/etc/exports'
|
|
|
|
])
|
|
|
|
log.info("Starting NFS...")
|
|
|
|
if remote.os.package_type == "deb":
|
|
|
|
remote.run(args=[
|
|
|
|
'sudo', 'service', 'nfs-kernel-server', 'start'
|
|
|
|
])
|
|
|
|
else:
|
|
|
|
remote.run(args=[
|
2015-03-04 14:57:03 +00:00
|
|
|
'sudo', 'systemctl', 'start', 'nfs'
|
2015-02-19 18:35:25 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
|
2012-06-19 21:13:39 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def run_qemu(ctx, config):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""Setup kvm environment and start qemu"""
|
2012-06-19 21:13:39 +00:00
|
|
|
procs = []
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2012-06-19 21:13:39 +00:00
|
|
|
for client, client_config in config.iteritems():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2013-01-23 20:37:39 +00:00
|
|
|
log_dir = '{tdir}/archive/qemu/{client}'.format(tdir=testdir, client=client)
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
2013-05-13 21:19:59 +00:00
|
|
|
'mkdir', log_dir, run.Raw('&&'),
|
|
|
|
'sudo', 'modprobe', 'kvm',
|
2012-06-19 21:13:39 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2015-02-19 18:35:25 +00:00
|
|
|
# make an nfs mount to use for logging and to
|
|
|
|
# allow to test to tell teuthology the tests outcome
|
|
|
|
_setup_nfs_mount(remote, client, log_dir)
|
|
|
|
|
2016-11-22 16:23:23 +00:00
|
|
|
# Hack to make sure /dev/kvm permissions are set correctly
|
|
|
|
# See http://tracker.ceph.com/issues/17977 and
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1333159
|
|
|
|
remote.run(args='sudo udevadm control --reload')
|
|
|
|
remote.run(args='sudo udevadm trigger /dev/kvm')
|
|
|
|
remote.run(args='ls -l /dev/kvm')
|
|
|
|
|
2014-12-22 16:51:25 +00:00
|
|
|
qemu_cmd = 'qemu-system-x86_64'
|
|
|
|
if remote.os.package_type == "rpm":
|
|
|
|
qemu_cmd = "/usr/libexec/qemu-kvm"
|
2012-06-19 21:13:39 +00:00
|
|
|
args=[
|
2013-09-06 20:08:01 +00:00
|
|
|
'adjust-ulimits',
|
2013-02-06 19:16:52 +00:00
|
|
|
'ceph-coverage',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
2013-09-06 20:08:01 +00:00
|
|
|
'daemon-helper',
|
2012-06-19 21:13:39 +00:00
|
|
|
'term',
|
2014-12-22 16:51:25 +00:00
|
|
|
qemu_cmd, '-enable-kvm', '-nographic',
|
2012-06-19 21:13:39 +00:00
|
|
|
'-m', str(client_config.get('memory', DEFAULT_MEM)),
|
|
|
|
# cd holding metadata for cloud-init
|
2013-01-23 20:37:39 +00:00
|
|
|
'-cdrom', '{tdir}/qemu/{client}.iso'.format(tdir=testdir, client=client),
|
2012-06-19 21:13:39 +00:00
|
|
|
]
|
|
|
|
|
2012-12-05 22:59:27 +00:00
|
|
|
cachemode = 'none'
|
2016-04-06 05:40:17 +00:00
|
|
|
ceph_config = ctx.ceph['ceph'].conf.get('global', {})
|
|
|
|
ceph_config.update(ctx.ceph['ceph'].conf.get('client', {}))
|
|
|
|
ceph_config.update(ctx.ceph['ceph'].conf.get(client, {}))
|
2012-12-05 22:59:27 +00:00
|
|
|
if ceph_config.get('rbd cache'):
|
|
|
|
if ceph_config.get('rbd cache max dirty', 1) > 0:
|
|
|
|
cachemode = 'writeback'
|
|
|
|
else:
|
|
|
|
cachemode = 'writethrough'
|
|
|
|
|
2015-10-21 20:27:08 +00:00
|
|
|
clone = client_config.get('clone', False)
|
2016-12-20 14:25:33 +00:00
|
|
|
num_disks = client_config.get('disks', DEFAULT_NUM_DISKS)
|
|
|
|
if isinstance(num_disks, list):
|
|
|
|
num_disks = len(num_disks)
|
|
|
|
for i in xrange(num_disks):
|
2015-10-21 20:27:08 +00:00
|
|
|
suffix = '-clone' if clone else ''
|
2012-06-19 21:13:39 +00:00
|
|
|
args.extend([
|
|
|
|
'-drive',
|
2014-03-28 23:04:05 +00:00
|
|
|
'file=rbd:rbd/{img}:id={id},format=raw,if=virtio,cache={cachemode}'.format(
|
2015-10-21 20:27:08 +00:00
|
|
|
img='{client}.{num}{suffix}'.format(client=client, num=i,
|
|
|
|
suffix=suffix),
|
2012-06-19 21:13:39 +00:00
|
|
|
id=client[len('client.'):],
|
2012-12-05 22:59:27 +00:00
|
|
|
cachemode=cachemode,
|
2012-06-19 21:13:39 +00:00
|
|
|
),
|
|
|
|
])
|
|
|
|
|
|
|
|
log.info('starting qemu...')
|
|
|
|
procs.append(
|
|
|
|
remote.run(
|
|
|
|
args=args,
|
|
|
|
logger=log.getChild(client),
|
|
|
|
stdin=run.PIPE,
|
|
|
|
wait=False,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.info('waiting for qemu tests to finish...')
|
|
|
|
run.wait(procs)
|
|
|
|
|
|
|
|
log.debug('checking that qemu tests succeeded...')
|
|
|
|
for client in config.iterkeys():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.keys()
|
2015-02-19 18:35:25 +00:00
|
|
|
# teardown nfs mount
|
|
|
|
_teardown_nfs_mount(remote, client)
|
|
|
|
# check for test status
|
2012-06-19 21:13:39 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'test', '-f',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/archive/qemu/{client}/success'.format(
|
|
|
|
tdir=testdir,
|
2012-06-19 21:13:39 +00:00
|
|
|
client=client
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2015-02-19 18:35:25 +00:00
|
|
|
|
2012-06-19 21:13:39 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run a test inside of QEMU on top of rbd. Only one test
|
|
|
|
is supported per client.
|
|
|
|
|
|
|
|
For example, you can specify which clients to run on::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
client.1:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test2.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
Or use the same settings on all clients:
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
all:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
For tests that don't need a filesystem, set type to block::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
type: block
|
|
|
|
|
|
|
|
The test should be configured to run on /dev/vdb and later
|
|
|
|
devices.
|
|
|
|
|
|
|
|
If you want to run a test that uses more than one rbd image,
|
|
|
|
specify how many images to use::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
type: block
|
2016-12-20 14:25:33 +00:00
|
|
|
disks: 2
|
|
|
|
|
|
|
|
- or -
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
|
|
|
test: http://ceph.com/qa/test.sh
|
|
|
|
type: block
|
|
|
|
disks:
|
|
|
|
- image_size: 1024
|
|
|
|
- image_size: 2048
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
You can set the amount of memory the VM has (default is 1024 MB)::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2012-06-19 21:13:39 +00:00
|
|
|
memory: 512 # megabytes
|
2015-10-21 20:27:08 +00:00
|
|
|
|
|
|
|
If you want to run a test against a cloned rbd image, set clone to true::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
2017-01-17 16:12:46 +00:00
|
|
|
test: http://download.ceph.com/qa/test.sh
|
2015-10-21 20:27:08 +00:00
|
|
|
clone: true
|
2016-12-20 00:45:12 +00:00
|
|
|
|
|
|
|
If you need to configure additional cloud-config options, set cloud_config
|
|
|
|
to the required data set::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
|
|
|
test: http://ceph.com/qa/test.sh
|
|
|
|
cloud_config_archive:
|
|
|
|
- |
|
|
|
|
#/bin/bash
|
|
|
|
touch foo1
|
|
|
|
- content: |
|
|
|
|
test data
|
|
|
|
type: text/plain
|
|
|
|
filename: /tmp/data
|
2016-12-20 01:52:06 +00:00
|
|
|
|
|
|
|
If you need to override the default cloud image, set image_url:
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph
|
|
|
|
- qemu:
|
|
|
|
client.0:
|
|
|
|
test: http://ceph.com/qa/test.sh
|
|
|
|
image_url: https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img
|
2012-06-19 21:13:39 +00:00
|
|
|
"""
|
|
|
|
assert isinstance(config, dict), \
|
|
|
|
"task qemu only supports a dictionary for configuration"
|
|
|
|
|
|
|
|
config = teuthology.replace_all_with_clients(ctx.cluster, config)
|
|
|
|
|
|
|
|
managers = []
|
2015-10-21 20:27:08 +00:00
|
|
|
create_images(ctx=ctx, config=config, managers=managers)
|
2012-06-19 21:13:39 +00:00
|
|
|
managers.extend([
|
|
|
|
lambda: create_dirs(ctx=ctx, config=config),
|
|
|
|
lambda: generate_iso(ctx=ctx, config=config),
|
|
|
|
lambda: download_image(ctx=ctx, config=config),
|
|
|
|
])
|
2015-10-21 20:27:08 +00:00
|
|
|
create_clones(ctx=ctx, config=config, managers=managers)
|
|
|
|
managers.append(
|
|
|
|
lambda: run_qemu(ctx=ctx, config=config),
|
|
|
|
)
|
2012-06-19 21:13:39 +00:00
|
|
|
|
|
|
|
with contextutil.nested(*managers):
|
|
|
|
yield
|