7 from util
.workunit
import get_refspec_after_overrides
9 from teuthology
import misc
as teuthology
10 from teuthology
.parallel
import parallel
11 from teuthology
.orchestra
import run
12 from teuthology
.config
import config
as teuth_config
14 log
= logging
.getLogger(__name__
)
16 def task(ctx
, config
):
18 Run all cram tests from the specified paths on the specified
19 clients. Each client runs tests in parallel.
22 Tests must have a .t suffix. Tests with duplicate names will
23 overwrite each other, so only the last one will run.
37 You can also run a list of cram tests on all clients::
46 :param config: Configuration
48 assert isinstance(config
, dict)
49 assert 'clients' in config
and isinstance(config
['clients'], dict), \
50 'configuration must contain a dictionary of clients'
52 clients
= teuthology
.replace_all_with_clients(ctx
.cluster
,
54 testdir
= teuthology
.get_testdir(ctx
)
56 overrides
= ctx
.config
.get('overrides', {})
57 refspec
= get_refspec_after_overrides(config
, overrides
)
59 git_url
= teuth_config
.get_ceph_qa_suite_git_url()
60 log
.info('Pulling tests from %s ref %s', git_url
, refspec
)
63 for client
, tests
in clients
.iteritems():
64 (remote
,) = ctx
.cluster
.only(client
).remotes
.iterkeys()
65 client_dir
= '{tdir}/archive/cram.{role}'.format(tdir
=testdir
, role
=client
)
68 'mkdir', '--', client_dir
,
70 'virtualenv', '{tdir}/virtualenv'.format(tdir
=testdir
),
72 '{tdir}/virtualenv/bin/pip'.format(tdir
=testdir
),
73 'install', 'cram==0.6',
76 clone_dir
= '{tdir}/clone.{role}'.format(tdir
=testdir
, role
=client
)
77 remote
.run(args
=refspec
.clone(git_url
, clone_dir
))
80 assert test
.endswith('.t'), 'tests must end in .t'
83 'cp', '--', os
.path
.join(clone_dir
, test
), client_dir
,
88 for role
in clients
.iterkeys():
89 p
.spawn(_run_tests
, ctx
, role
)
91 for client
, tests
in clients
.iteritems():
92 (remote
,) = ctx
.cluster
.only(client
).remotes
.iterkeys()
93 client_dir
= '{tdir}/archive/cram.{role}'.format(tdir
=testdir
, role
=client
)
94 test_files
= set([test
.rsplit('/', 1)[1] for test
in tests
])
96 # remove test files unless they failed
97 for test_file
in test_files
:
98 abs_file
= os
.path
.join(client_dir
, test_file
)
101 'test', '-f', abs_file
+ '.err',
103 'rm', '-f', '--', abs_file
,
107 # ignore failure since more than one client may
108 # be run on a host, and the client dir should be
109 # non-empty if the test failed
113 '{tdir}/virtualenv'.format(tdir
=testdir
),
116 'rmdir', '--ignore-fail-on-non-empty', client_dir
,
120 def _run_tests(ctx
, role
):
122 For each role, check to make sure it's a client, then run the cram on that client
127 assert isinstance(role
, basestring
)
129 assert role
.startswith(PREFIX
)
130 id_
= role
[len(PREFIX
):]
131 (remote
,) = ctx
.cluster
.only(role
).remotes
.iterkeys()
132 ceph_ref
= ctx
.summary
.get('ceph-sha1', 'master')
134 testdir
= teuthology
.get_testdir(ctx
)
135 log
.info('Running tests for %s...', role
)
138 run
.Raw('CEPH_REF={ref}'.format(ref
=ceph_ref
)),
139 run
.Raw('CEPH_ID="{id}"'.format(id=id_
)),
142 '{tdir}/archive/coverage'.format(tdir
=testdir
),
143 '{tdir}/virtualenv/bin/cram'.format(tdir
=testdir
),
145 run
.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir
=testdir
, role
=role
)),
147 logger
=log
.getChild(role
),