9 from tasks
.util
.workunit
import get_refspec_after_overrides
11 from teuthology
import misc
as teuthology
12 from teuthology
.parallel
import parallel
13 from teuthology
.orchestra
import run
14 from teuthology
.config
import config
as teuth_config
16 log
= logging
.getLogger(__name__
)
18 def task(ctx
, config
):
20 Run all cram tests from the specified paths on the specified
21 clients. Each client runs tests in parallel.
24 Tests must have a .t suffix. Tests with duplicate names will
25 overwrite each other, so only the last one will run.
39 You can also run a list of cram tests on all clients::
48 :param config: Configuration
50 assert isinstance(config
, dict)
51 assert 'clients' in config
and isinstance(config
['clients'], dict), \
52 'configuration must contain a dictionary of clients'
54 clients
= teuthology
.replace_all_with_clients(ctx
.cluster
,
56 testdir
= teuthology
.get_testdir(ctx
)
58 overrides
= ctx
.config
.get('overrides', {})
59 refspec
= get_refspec_after_overrides(config
, overrides
)
61 git_url
= teuth_config
.get_ceph_qa_suite_git_url()
62 log
.info('Pulling tests from %s ref %s', git_url
, refspec
)
65 for client
, tests
in clients
.items():
66 (remote
,) = ctx
.cluster
.only(client
).remotes
.keys()
67 client_dir
= '{tdir}/archive/cram.{role}'.format(tdir
=testdir
, role
=client
)
70 'mkdir', '--', client_dir
,
72 'virtualenv', '{tdir}/virtualenv'.format(tdir
=testdir
),
74 '{tdir}/virtualenv/bin/pip'.format(tdir
=testdir
),
75 'install', 'cram==0.6',
78 clone_dir
= '{tdir}/clone.{role}'.format(tdir
=testdir
, role
=client
)
79 remote
.run(args
=refspec
.clone(git_url
, clone_dir
))
82 assert test
.endswith('.t'), 'tests must end in .t'
85 'cp', '--', os
.path
.join(clone_dir
, test
), client_dir
,
90 for role
in clients
.keys():
91 p
.spawn(_run_tests
, ctx
, role
)
93 for client
, tests
in clients
.items():
94 (remote
,) = ctx
.cluster
.only(client
).remotes
.keys()
95 client_dir
= '{tdir}/archive/cram.{role}'.format(tdir
=testdir
, role
=client
)
96 test_files
= set([test
.rsplit('/', 1)[1] for test
in tests
])
98 # remove test files unless they failed
99 for test_file
in test_files
:
100 abs_file
= os
.path
.join(client_dir
, test_file
)
103 'test', '-f', abs_file
+ '.err',
105 'rm', '-f', '--', abs_file
,
109 # ignore failure since more than one client may
110 # be run on a host, and the client dir should be
111 # non-empty if the test failed
115 '{tdir}/virtualenv'.format(tdir
=testdir
),
118 'rmdir', '--ignore-fail-on-non-empty', client_dir
,
122 def _run_tests(ctx
, role
):
124 For each role, check to make sure it's a client, then run the cram on that client
129 assert isinstance(role
, six
.string_types
)
131 assert role
.startswith(PREFIX
)
132 id_
= role
[len(PREFIX
):]
133 (remote
,) = ctx
.cluster
.only(role
).remotes
.keys()
134 ceph_ref
= ctx
.summary
.get('ceph-sha1', 'master')
136 testdir
= teuthology
.get_testdir(ctx
)
137 log
.info('Running tests for %s...', role
)
140 run
.Raw('CEPH_REF={ref}'.format(ref
=ceph_ref
)),
141 run
.Raw('CEPH_ID="{id}"'.format(id=id_
)),
142 run
.Raw('PATH=$PATH:/usr/sbin'),
145 '{tdir}/archive/coverage'.format(tdir
=testdir
),
146 '{tdir}/virtualenv/bin/cram'.format(tdir
=testdir
),
148 run
.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir
=testdir
, role
=role
)),
150 logger
=log
.getChild(role
),