]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/cram.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / qa / tasks / cram.py
CommitLineData
7c673cae
FG
1"""
2Cram tests
3"""
4import logging
5import os
6
e306af50 7from tasks.util.workunit import get_refspec_after_overrides
91327a77 8
7c673cae
FG
9from teuthology import misc as teuthology
10from teuthology.parallel import parallel
11from teuthology.orchestra import run
12from teuthology.config import config as teuth_config
13
14log = logging.getLogger(__name__)
15
16def task(ctx, config):
17 """
91327a77 18 Run all cram tests from the specified paths on the specified
f67539c2
TL
19 clients. Each client runs tests in parallel as default, and
20 you can also disable it by adding "parallel: False" option.
7c673cae
FG
21
22 Limitations:
23 Tests must have a .t suffix. Tests with duplicate names will
24 overwrite each other, so only the last one will run.
25
26 For example::
27
28 tasks:
29 - ceph:
30 - cram:
31 clients:
32 client.0:
91327a77
AA
33 - qa/test.t
34 - qa/test2.t]
35 client.1: [qa/test.t]
7c673cae 36 branch: foo
f67539c2 37 parallel: False
7c673cae
FG
38
39 You can also run a list of cram tests on all clients::
40
41 tasks:
42 - ceph:
43 - cram:
44 clients:
91327a77 45 all: [qa/test.t]
7c673cae
FG
46
47 :param ctx: Context
48 :param config: Configuration
49 """
50 assert isinstance(config, dict)
51 assert 'clients' in config and isinstance(config['clients'], dict), \
52 'configuration must contain a dictionary of clients'
53
54 clients = teuthology.replace_all_with_clients(ctx.cluster,
55 config['clients'])
56 testdir = teuthology.get_testdir(ctx)
57
58 overrides = ctx.config.get('overrides', {})
91327a77
AA
59 refspec = get_refspec_after_overrides(config, overrides)
60
f67539c2
TL
61 _parallel = config.get('parallel', True)
62
91327a77
AA
63 git_url = teuth_config.get_ceph_qa_suite_git_url()
64 log.info('Pulling tests from %s ref %s', git_url, refspec)
7c673cae
FG
65
66 try:
9f95a23c 67 for client, tests in clients.items():
f67539c2 68 (remote,) = (ctx.cluster.only(client).remotes.keys())
7c673cae
FG
69 client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client)
70 remote.run(
71 args=[
72 'mkdir', '--', client_dir,
73 run.Raw('&&'),
74 'virtualenv', '{tdir}/virtualenv'.format(tdir=testdir),
75 run.Raw('&&'),
76 '{tdir}/virtualenv/bin/pip'.format(tdir=testdir),
77 'install', 'cram==0.6',
78 ],
79 )
91327a77
AA
80 clone_dir = '{tdir}/clone.{role}'.format(tdir=testdir, role=client)
81 remote.run(args=refspec.clone(git_url, clone_dir))
82
7c673cae 83 for test in tests:
7c673cae
FG
84 assert test.endswith('.t'), 'tests must end in .t'
85 remote.run(
86 args=[
91327a77 87 'cp', '--', os.path.join(clone_dir, test), client_dir,
7c673cae
FG
88 ],
89 )
90
f67539c2
TL
91 if _parallel:
92 with parallel() as p:
93 for role in clients.keys():
94 p.spawn(_run_tests, ctx, role)
95 else:
9f95a23c 96 for role in clients.keys():
f67539c2 97 _run_tests(ctx, role)
7c673cae 98 finally:
9f95a23c 99 for client, tests in clients.items():
f67539c2 100 (remote,) = (ctx.cluster.only(client).remotes.keys())
7c673cae
FG
101 client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client)
102 test_files = set([test.rsplit('/', 1)[1] for test in tests])
103
104 # remove test files unless they failed
105 for test_file in test_files:
106 abs_file = os.path.join(client_dir, test_file)
107 remote.run(
108 args=[
109 'test', '-f', abs_file + '.err',
110 run.Raw('||'),
111 'rm', '-f', '--', abs_file,
112 ],
113 )
114
115 # ignore failure since more than one client may
116 # be run on a host, and the client dir should be
117 # non-empty if the test failed
f67539c2 118 clone_dir = '{tdir}/clone.{role}'.format(tdir=testdir, role=client)
7c673cae
FG
119 remote.run(
120 args=[
121 'rm', '-rf', '--',
122 '{tdir}/virtualenv'.format(tdir=testdir),
91327a77 123 clone_dir,
7c673cae
FG
124 run.Raw(';'),
125 'rmdir', '--ignore-fail-on-non-empty', client_dir,
126 ],
127 )
128
129def _run_tests(ctx, role):
130 """
131 For each role, check to make sure it's a client, then run the cram on that client
132
133 :param ctx: Context
134 :param role: Roles
135 """
f67539c2 136 assert isinstance(role, str)
7c673cae 137 PREFIX = 'client.'
f67539c2
TL
138 if role.startswith(PREFIX):
139 id_ = role[len(PREFIX):]
140 else:
141 id_ = role
142 (remote,) = (ctx.cluster.only(role).remotes.keys())
7c673cae
FG
143 ceph_ref = ctx.summary.get('ceph-sha1', 'master')
144
145 testdir = teuthology.get_testdir(ctx)
146 log.info('Running tests for %s...', role)
147 remote.run(
148 args=[
149 run.Raw('CEPH_REF={ref}'.format(ref=ceph_ref)),
150 run.Raw('CEPH_ID="{id}"'.format(id=id_)),
11fdf7f2 151 run.Raw('PATH=$PATH:/usr/sbin'),
7c673cae
FG
152 'adjust-ulimits',
153 'ceph-coverage',
154 '{tdir}/archive/coverage'.format(tdir=testdir),
155 '{tdir}/virtualenv/bin/cram'.format(tdir=testdir),
156 '-v', '--',
157 run.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir=testdir, role=role)),
158 ],
159 logger=log.getChild(role),
160 )