2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Cram tests
|
|
|
|
"""
|
2013-01-15 01:55:43 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2018-09-06 14:07:08 +00:00
|
|
|
from util.workunit import get_refspec_after_overrides
|
|
|
|
|
2013-01-15 01:55:43 +00:00
|
|
|
from teuthology import misc as teuthology
|
|
|
|
from teuthology.parallel import parallel
|
2014-08-07 14:24:59 +00:00
|
|
|
from teuthology.orchestra import run
|
2017-01-06 20:06:11 +00:00
|
|
|
from teuthology.config import config as teuth_config
|
2013-01-15 01:55:43 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
2018-09-06 14:07:08 +00:00
|
|
|
Run all cram tests from the specified paths on the specified
|
2013-01-15 01:55:43 +00:00
|
|
|
clients. Each client runs tests in parallel.
|
|
|
|
|
|
|
|
Limitations:
|
|
|
|
Tests must have a .t suffix. Tests with duplicate names will
|
|
|
|
overwrite each other, so only the last one will run.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- cram:
|
|
|
|
clients:
|
|
|
|
client.0:
|
2018-09-06 14:07:08 +00:00
|
|
|
- qa/test.t
|
|
|
|
- qa/test2.t]
|
|
|
|
client.1: [qa/test.t]
|
2016-12-09 09:41:49 +00:00
|
|
|
branch: foo
|
2013-01-15 01:55:43 +00:00
|
|
|
|
|
|
|
You can also run a list of cram tests on all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- cram:
|
|
|
|
clients:
|
2018-09-06 14:07:08 +00:00
|
|
|
all: [qa/test.t]
|
2013-10-12 08:28:27 +00:00
|
|
|
|
|
|
|
:param ctx: Context
|
|
|
|
:param config: Configuration
|
2013-01-15 01:55:43 +00:00
|
|
|
"""
|
|
|
|
assert isinstance(config, dict)
|
|
|
|
assert 'clients' in config and isinstance(config['clients'], dict), \
|
|
|
|
'configuration must contain a dictionary of clients'
|
|
|
|
|
|
|
|
clients = teuthology.replace_all_with_clients(ctx.cluster,
|
|
|
|
config['clients'])
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
|
|
|
|
2016-12-09 09:41:49 +00:00
|
|
|
overrides = ctx.config.get('overrides', {})
|
2018-09-06 14:07:08 +00:00
|
|
|
refspec = get_refspec_after_overrides(config, overrides)
|
2016-12-09 09:41:49 +00:00
|
|
|
|
2018-09-03 15:40:08 +00:00
|
|
|
git_url = teuth_config.get_ceph_qa_suite_git_url()
|
2018-09-06 14:07:08 +00:00
|
|
|
log.info('Pulling tests from %s ref %s', git_url, refspec)
|
2017-01-06 20:06:11 +00:00
|
|
|
|
2013-01-15 01:55:43 +00:00
|
|
|
try:
|
|
|
|
for client, tests in clients.iteritems():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.iterkeys()
|
2013-01-23 20:37:39 +00:00
|
|
|
client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client)
|
2013-01-15 01:55:43 +00:00
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'mkdir', '--', client_dir,
|
|
|
|
run.Raw('&&'),
|
2013-01-23 20:37:39 +00:00
|
|
|
'virtualenv', '{tdir}/virtualenv'.format(tdir=testdir),
|
2013-01-15 01:55:43 +00:00
|
|
|
run.Raw('&&'),
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/virtualenv/bin/pip'.format(tdir=testdir),
|
2016-03-01 06:54:07 +00:00
|
|
|
'install', 'cram==0.6',
|
2013-01-15 01:55:43 +00:00
|
|
|
],
|
|
|
|
)
|
2018-09-06 14:07:08 +00:00
|
|
|
clone_dir = '{tdir}/clone.{role}'.format(tdir=testdir, role=client)
|
|
|
|
remote.run(args=refspec.clone(git_url, clone_dir))
|
|
|
|
|
2013-01-15 01:55:43 +00:00
|
|
|
for test in tests:
|
|
|
|
assert test.endswith('.t'), 'tests must end in .t'
|
|
|
|
remote.run(
|
|
|
|
args=[
|
2018-09-06 14:07:08 +00:00
|
|
|
'cp', '--', os.path.join(clone_dir, test), client_dir,
|
2013-01-15 01:55:43 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
with parallel() as p:
|
|
|
|
for role in clients.iterkeys():
|
|
|
|
p.spawn(_run_tests, ctx, role)
|
|
|
|
finally:
|
|
|
|
for client, tests in clients.iteritems():
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.iterkeys()
|
2013-01-23 20:37:39 +00:00
|
|
|
client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client)
|
2013-01-15 01:55:43 +00:00
|
|
|
test_files = set([test.rsplit('/', 1)[1] for test in tests])
|
|
|
|
|
|
|
|
# remove test files unless they failed
|
|
|
|
for test_file in test_files:
|
|
|
|
abs_file = os.path.join(client_dir, test_file)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'test', '-f', abs_file + '.err',
|
|
|
|
run.Raw('||'),
|
|
|
|
'rm', '-f', '--', abs_file,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
# ignore failure since more than one client may
|
|
|
|
# be run on a host, and the client dir should be
|
|
|
|
# non-empty if the test failed
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rm', '-rf', '--',
|
2013-01-23 20:37:39 +00:00
|
|
|
'{tdir}/virtualenv'.format(tdir=testdir),
|
2018-09-06 14:07:08 +00:00
|
|
|
clone_dir,
|
2013-01-15 01:55:43 +00:00
|
|
|
run.Raw(';'),
|
|
|
|
'rmdir', '--ignore-fail-on-non-empty', client_dir,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def _run_tests(ctx, role):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
For each role, check to make sure it's a client, then run the cram on that client
|
|
|
|
|
|
|
|
:param ctx: Context
|
|
|
|
:param role: Roles
|
|
|
|
"""
|
2013-01-15 01:55:43 +00:00
|
|
|
assert isinstance(role, basestring)
|
|
|
|
PREFIX = 'client.'
|
|
|
|
assert role.startswith(PREFIX)
|
|
|
|
id_ = role[len(PREFIX):]
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(role).remotes.iterkeys()
|
2013-01-15 01:55:43 +00:00
|
|
|
ceph_ref = ctx.summary.get('ceph-sha1', 'master')
|
|
|
|
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2013-01-15 01:55:43 +00:00
|
|
|
log.info('Running tests for %s...', role)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
run.Raw('CEPH_REF={ref}'.format(ref=ceph_ref)),
|
|
|
|
run.Raw('CEPH_ID="{id}"'.format(id=id_)),
|
2017-11-06 19:00:50 +00:00
|
|
|
run.Raw('PATH=$PATH:/usr/sbin'),
|
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),
|
|
|
|
'{tdir}/virtualenv/bin/cram'.format(tdir=testdir),
|
2013-01-15 01:55:43 +00:00
|
|
|
'-v', '--',
|
2013-01-23 20:37:39 +00:00
|
|
|
run.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir=testdir, role=role)),
|
2013-01-15 01:55:43 +00:00
|
|
|
],
|
|
|
|
logger=log.getChild(role),
|
|
|
|
)
|