2011-06-15 18:59:57 +00:00
|
|
|
import logging
|
2012-06-11 01:43:35 +00:00
|
|
|
import pipes
|
2011-06-15 18:59:57 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from teuthology import misc as teuthology
|
2011-07-14 20:57:07 +00:00
|
|
|
from teuthology.parallel import parallel
|
2011-09-13 21:53:02 +00:00
|
|
|
from ..orchestra import run
|
2011-06-15 18:59:57 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run ceph all workunits found under the specified path.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
2013-02-17 07:53:23 +00:00
|
|
|
- ceph-fuse: [client.0]
|
2011-06-15 18:59:57 +00:00
|
|
|
- workunit:
|
2012-06-11 01:43:35 +00:00
|
|
|
clients:
|
|
|
|
client.0: [direct_io, xattrs.sh]
|
|
|
|
client.1: [snaps]
|
2012-07-13 18:12:31 +00:00
|
|
|
branch: foo
|
2011-08-30 22:48:58 +00:00
|
|
|
|
|
|
|
You can also run a list of workunits on all clients:
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
2013-02-17 07:53:23 +00:00
|
|
|
- ceph-fuse:
|
2011-08-30 22:48:58 +00:00
|
|
|
- workunit:
|
2012-07-13 18:12:31 +00:00
|
|
|
tag: v0.47
|
2012-06-11 01:43:35 +00:00
|
|
|
clients:
|
|
|
|
all: [direct_io, xattrs.sh, snaps]
|
2011-08-30 22:48:58 +00:00
|
|
|
|
|
|
|
If you have an "all" section it will run all the workunits
|
|
|
|
on each client simultaneously, AFTER running any workunits specified
|
|
|
|
for individual clients. (This prevents unintended simultaneous runs.)
|
2012-06-11 01:43:35 +00:00
|
|
|
|
|
|
|
To customize tests, you can specify environment variables as a dict::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
2013-02-17 07:53:23 +00:00
|
|
|
- ceph-fuse:
|
2012-06-11 01:43:35 +00:00
|
|
|
- workunit:
|
2012-07-13 18:12:31 +00:00
|
|
|
sha1: 9b28948635b17165d17c1cf83d4a870bd138ddf6
|
2012-06-11 01:43:35 +00:00
|
|
|
clients:
|
|
|
|
all: [snaps]
|
|
|
|
env:
|
|
|
|
FOO: bar
|
|
|
|
BAZ: quux
|
2011-06-15 18:59:57 +00:00
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
2012-06-11 01:43:35 +00:00
|
|
|
assert isinstance(config.get('clients'), dict), \
|
|
|
|
'configuration must contain a dictionary of clients'
|
2012-07-13 18:12:31 +00:00
|
|
|
|
2012-07-13 18:13:31 +00:00
|
|
|
overrides = ctx.config.get('overrides', {})
|
|
|
|
teuthology.deep_merge(config, overrides.get('workunit', {}))
|
|
|
|
|
2012-07-13 18:12:31 +00:00
|
|
|
refspec = config.get('branch')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = config.get('sha1')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = config.get('tag')
|
|
|
|
if refspec is None:
|
|
|
|
refspec = 'HEAD'
|
|
|
|
|
|
|
|
log.info('Pulling workunits from ref %s', refspec)
|
|
|
|
|
2013-01-14 20:09:56 +00:00
|
|
|
created_dir_dict = {}
|
|
|
|
|
2012-06-11 01:43:35 +00:00
|
|
|
if config.get('env') is not None:
|
|
|
|
assert isinstance(config['env'], dict), 'env must be a dictionary'
|
|
|
|
clients = config['clients']
|
2011-06-15 18:59:57 +00:00
|
|
|
log.info('Making a separate scratch dir for every client...')
|
2012-06-11 01:43:35 +00:00
|
|
|
for role in clients.iterkeys():
|
2011-06-15 18:59:57 +00:00
|
|
|
assert isinstance(role, basestring)
|
2011-08-30 22:48:58 +00:00
|
|
|
if role == "all":
|
|
|
|
continue
|
2011-06-15 18:59:57 +00:00
|
|
|
PREFIX = 'client.'
|
|
|
|
assert role.startswith(PREFIX)
|
2013-01-14 20:09:56 +00:00
|
|
|
created_mnt_dir = _make_scratch_dir(ctx, role, config.get('subdir'))
|
|
|
|
created_dir_dict[role] = created_mnt_dir
|
|
|
|
|
2011-08-30 22:48:58 +00:00
|
|
|
all_spec = False #is there an all grouping?
|
2011-07-14 20:57:07 +00:00
|
|
|
with parallel() as p:
|
2012-06-11 01:43:35 +00:00
|
|
|
for role, tests in clients.iteritems():
|
2011-08-30 22:48:58 +00:00
|
|
|
if role != "all":
|
2012-07-13 18:12:31 +00:00
|
|
|
p.spawn(_run_tests, ctx, refspec, role, tests, config.get('env'))
|
2011-08-30 22:48:58 +00:00
|
|
|
else:
|
|
|
|
all_spec = True
|
|
|
|
|
|
|
|
if all_spec:
|
2012-06-11 19:31:22 +00:00
|
|
|
all_tasks = clients["all"]
|
2012-11-07 04:28:56 +00:00
|
|
|
_spawn_on_all_clients(ctx, refspec, all_tasks, config.get('env'), config.get('subdir'))
|
2011-08-30 22:48:58 +00:00
|
|
|
|
2013-01-14 20:09:56 +00:00
|
|
|
for role in clients.iterkeys():
|
|
|
|
assert isinstance(role, basestring)
|
|
|
|
if role == "all":
|
|
|
|
continue
|
|
|
|
PREFIX = 'client.'
|
|
|
|
assert role.startswith(PREFIX)
|
|
|
|
if created_dir_dict[role]:
|
|
|
|
_delete_dir(ctx, role, config.get('subdir'))
|
|
|
|
|
|
|
|
def _delete_dir(ctx, role, subdir):
|
|
|
|
PREFIX = 'client.'
|
2013-02-02 17:00:17 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2013-01-14 20:09:56 +00:00
|
|
|
id_ = role[len(PREFIX):]
|
|
|
|
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
|
2013-02-02 17:00:17 +00:00
|
|
|
mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
|
2013-01-14 20:09:56 +00:00
|
|
|
client = os.path.join(mnt, 'client.{id}'.format(id=id_))
|
|
|
|
try:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rm',
|
|
|
|
'-rf',
|
|
|
|
'--',
|
|
|
|
client,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
log.info("Deleted dir {dir}".format(dir=client))
|
2013-08-30 15:58:10 +00:00
|
|
|
except Exception:
|
|
|
|
log.exception("Caught an execption deleting dir {dir}".format(dir=client))
|
2013-01-14 20:09:56 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rmdir',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
log.info("Deleted dir {dir}".format(dir=mnt))
|
2013-08-30 15:58:10 +00:00
|
|
|
except Exception:
|
|
|
|
log.exception("Caught an execption deleting dir {dir}".format(dir=mnt))
|
2013-01-14 20:09:56 +00:00
|
|
|
|
2012-11-07 04:28:56 +00:00
|
|
|
def _make_scratch_dir(ctx, role, subdir):
|
2013-01-14 20:09:56 +00:00
|
|
|
retVal = False
|
2011-08-30 22:48:58 +00:00
|
|
|
PREFIX = 'client.'
|
|
|
|
id_ = role[len(PREFIX):]
|
|
|
|
log.debug("getting remote for {id} role {role_}".format(id=id_, role_=role))
|
|
|
|
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
|
2012-10-25 00:33:25 +00:00
|
|
|
dir_owner = remote.shortname.split('@', 1)[0]
|
2013-01-23 20:37:39 +00:00
|
|
|
mnt = os.path.join(teuthology.get_testdir(ctx), 'mnt.{id}'.format(id=id_))
|
2013-01-14 20:09:56 +00:00
|
|
|
# if neither kclient nor ceph-fuse are required for a workunit,
|
|
|
|
# mnt may not exist. Stat and create the directory if it doesn't.
|
|
|
|
try:
|
2013-01-31 13:58:57 +00:00
|
|
|
remote.run(
|
2013-01-14 20:09:56 +00:00
|
|
|
args=[
|
|
|
|
'stat',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
log.info('Did not need to create dir {dir}'.format(dir=mnt))
|
2013-08-30 15:58:10 +00:00
|
|
|
except Exception:
|
2013-01-31 13:58:57 +00:00
|
|
|
remote.run(
|
2013-01-14 20:09:56 +00:00
|
|
|
args=[
|
|
|
|
'mkdir',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
log.info('Created dir {dir}'.format(dir=mnt))
|
|
|
|
retVal = True
|
|
|
|
|
2012-11-07 04:28:56 +00:00
|
|
|
if not subdir: subdir = 'client.{id}'.format(id=id_)
|
2013-01-14 20:09:56 +00:00
|
|
|
if retVal:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'cd',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
run.Raw('&&'),
|
|
|
|
'mkdir',
|
|
|
|
'--',
|
|
|
|
subdir,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
# cd first so this will fail if the mount point does
|
|
|
|
# not exist; pure install -d will silently do the
|
|
|
|
# wrong thing
|
|
|
|
'cd',
|
|
|
|
'--',
|
|
|
|
mnt,
|
|
|
|
run.Raw('&&'),
|
|
|
|
'sudo',
|
|
|
|
'install',
|
|
|
|
'-d',
|
|
|
|
'-m', '0755',
|
|
|
|
'--owner={user}'.format(user=dir_owner),
|
|
|
|
'--',
|
|
|
|
subdir,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
return retVal
|
2011-08-30 22:48:58 +00:00
|
|
|
|
2012-11-07 04:28:56 +00:00
|
|
|
def _spawn_on_all_clients(ctx, refspec, tests, env, subdir):
|
2011-08-30 22:48:58 +00:00
|
|
|
client_generator = teuthology.all_roles_of_type(ctx.cluster, 'client')
|
|
|
|
client_remotes = list()
|
|
|
|
for client in client_generator:
|
|
|
|
(client_remote,) = ctx.cluster.only('client.{id}'.format(id=client)).remotes.iterkeys()
|
|
|
|
client_remotes.append((client_remote, 'client.{id}'.format(id=client)))
|
2012-11-07 04:28:56 +00:00
|
|
|
_make_scratch_dir(ctx, "client.{id}".format(id=client), subdir)
|
|
|
|
|
2011-08-30 22:48:58 +00:00
|
|
|
for unit in tests:
|
|
|
|
with parallel() as p:
|
|
|
|
for remote, role in client_remotes:
|
2012-11-07 04:28:56 +00:00
|
|
|
p.spawn(_run_tests, ctx, refspec, role, [unit], env, subdir)
|
2011-06-22 17:56:40 +00:00
|
|
|
|
2013-03-22 18:56:50 +00:00
|
|
|
# cleanup the generated client directories
|
|
|
|
client_generator = teuthology.all_roles_of_type(ctx.cluster, 'client')
|
|
|
|
for client in client_generator:
|
|
|
|
_delete_dir(ctx, 'client.{id}'.format(id=client), subdir)
|
|
|
|
|
2012-11-18 17:24:10 +00:00
|
|
|
def _run_tests(ctx, refspec, role, tests, env, subdir=None):
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2011-06-22 17:56:40 +00:00
|
|
|
assert isinstance(role, basestring)
|
|
|
|
PREFIX = 'client.'
|
|
|
|
assert role.startswith(PREFIX)
|
|
|
|
id_ = role[len(PREFIX):]
|
|
|
|
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
|
2013-01-23 20:37:39 +00:00
|
|
|
mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
|
2011-06-22 17:56:40 +00:00
|
|
|
# subdir so we can remove and recreate this a lot without sudo
|
2012-11-18 17:24:10 +00:00
|
|
|
if subdir is None:
|
2012-11-07 04:28:56 +00:00
|
|
|
scratch_tmp = os.path.join(mnt, 'client.{id}'.format(id=id_), 'tmp')
|
2012-11-18 17:24:10 +00:00
|
|
|
else:
|
|
|
|
scratch_tmp = os.path.join(mnt, subdir)
|
2013-01-23 20:37:39 +00:00
|
|
|
srcdir = '{tdir}/workunit.{role}'.format(tdir=testdir, role=role)
|
2011-06-22 17:56:40 +00:00
|
|
|
|
|
|
|
remote.run(
|
|
|
|
logger=log.getChild(role),
|
|
|
|
args=[
|
|
|
|
'mkdir', '--', srcdir,
|
|
|
|
run.Raw('&&'),
|
2013-01-23 22:08:53 +00:00
|
|
|
'git',
|
|
|
|
'archive',
|
|
|
|
'--remote=git://ceph.newdream.net/git/ceph.git',
|
|
|
|
'%s:qa/workunits' % refspec,
|
2011-06-22 17:56:40 +00:00
|
|
|
run.Raw('|'),
|
|
|
|
'tar',
|
|
|
|
'-C', srcdir,
|
|
|
|
'-x',
|
|
|
|
'-f-',
|
|
|
|
run.Raw('&&'),
|
|
|
|
'cd', '--', srcdir,
|
|
|
|
run.Raw('&&'),
|
|
|
|
'if', 'test', '-e', 'Makefile', run.Raw(';'), 'then', 'make', run.Raw(';'), 'fi',
|
|
|
|
run.Raw('&&'),
|
|
|
|
'find', '-executable', '-type', 'f', '-printf', r'%P\0'.format(srcdir=srcdir),
|
2013-01-23 20:37:39 +00:00
|
|
|
run.Raw('>{tdir}/workunits.list'.format(tdir=testdir)),
|
2011-06-22 17:56:40 +00:00
|
|
|
],
|
|
|
|
)
|
2011-06-15 18:59:57 +00:00
|
|
|
|
2013-01-23 20:37:39 +00:00
|
|
|
workunits = sorted(teuthology.get_file(
|
|
|
|
remote,
|
|
|
|
'{tdir}/workunits.list'.format(tdir=testdir)).split('\0'))
|
2011-06-22 17:56:40 +00:00
|
|
|
assert workunits
|
|
|
|
|
|
|
|
try:
|
|
|
|
assert isinstance(tests, list)
|
|
|
|
for spec in tests:
|
|
|
|
log.info('Running workunits matching %s on %s...', spec, role)
|
|
|
|
prefix = '{spec}/'.format(spec=spec)
|
|
|
|
to_run = [w for w in workunits if w == spec or w.startswith(prefix)]
|
|
|
|
if not to_run:
|
|
|
|
raise RuntimeError('Spec did not match any workunits: {spec!r}'.format(spec=spec))
|
|
|
|
for workunit in to_run:
|
|
|
|
log.info('Running workunit %s...', workunit)
|
2012-06-11 01:43:35 +00:00
|
|
|
args = [
|
2012-11-07 19:14:09 +00:00
|
|
|
'mkdir', '-p', '--', scratch_tmp,
|
2012-06-11 01:43:35 +00:00
|
|
|
run.Raw('&&'),
|
|
|
|
'cd', '--', scratch_tmp,
|
|
|
|
run.Raw('&&'),
|
2013-07-17 00:15:55 +00:00
|
|
|
run.Raw('CEPH_CLI_TEST_DUP_COMMAND=1'),
|
2013-04-28 19:15:42 +00:00
|
|
|
run.Raw('CEPH_REF={ref}'.format(ref=refspec)),
|
2013-02-13 22:32:52 +00:00
|
|
|
run.Raw('TESTDIR="{tdir}"'.format(tdir=testdir)),
|
2012-06-11 01:43:35 +00:00
|
|
|
run.Raw('CEPH_ID="{id}"'.format(id=id_)),
|
|
|
|
]
|
|
|
|
if env is not None:
|
|
|
|
for var, val in env.iteritems():
|
|
|
|
quoted_val = pipes.quote(val)
|
|
|
|
env_arg = '{var}={val}'.format(var=var, val=quoted_val)
|
|
|
|
args.append(run.Raw(env_arg))
|
|
|
|
args.extend([
|
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),
|
2011-06-22 17:56:40 +00:00
|
|
|
'{srcdir}/{workunit}'.format(
|
|
|
|
srcdir=srcdir,
|
|
|
|
workunit=workunit,
|
|
|
|
),
|
2012-06-11 01:43:35 +00:00
|
|
|
])
|
|
|
|
remote.run(
|
|
|
|
logger=log.getChild(role),
|
|
|
|
args=args,
|
2011-06-22 17:56:40 +00:00
|
|
|
)
|
2012-11-08 14:55:36 +00:00
|
|
|
remote.run(
|
|
|
|
logger=log.getChild(role),
|
2013-04-04 05:01:01 +00:00
|
|
|
args=['sudo', 'rm', '-rf', '--', scratch_tmp],
|
2012-11-08 14:55:36 +00:00
|
|
|
)
|
2011-06-22 17:56:40 +00:00
|
|
|
finally:
|
2012-11-21 16:29:47 +00:00
|
|
|
log.info('Stopping %s on %s...', spec, role)
|
|
|
|
remote.run(
|
2011-06-16 22:19:14 +00:00
|
|
|
logger=log.getChild(role),
|
2011-06-15 18:59:57 +00:00
|
|
|
args=[
|
2013-01-23 20:37:39 +00:00
|
|
|
'rm', '-rf', '--', '{tdir}/workunits.list'.format(tdir=testdir), srcdir,
|
2011-06-15 18:59:57 +00:00
|
|
|
],
|
|
|
|
)
|