]> git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/cram.py
update sources to 12.2.10
[ceph.git] / ceph / qa / tasks / cram.py
1 """
2 Cram tests
3 """
4 import logging
5 import os
6
7 from util.workunit import get_refspec_after_overrides
8
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
13
14 log = logging.getLogger(__name__)
15
16 def task(ctx, config):
17 """
18 Run all cram tests from the specified paths on the specified
19 clients. Each client runs tests in parallel.
20
21 Limitations:
22 Tests must have a .t suffix. Tests with duplicate names will
23 overwrite each other, so only the last one will run.
24
25 For example::
26
27 tasks:
28 - ceph:
29 - cram:
30 clients:
31 client.0:
32 - qa/test.t
33 - qa/test2.t]
34 client.1: [qa/test.t]
35 branch: foo
36
37 You can also run a list of cram tests on all clients::
38
39 tasks:
40 - ceph:
41 - cram:
42 clients:
43 all: [qa/test.t]
44
45 :param ctx: Context
46 :param config: Configuration
47 """
48 assert isinstance(config, dict)
49 assert 'clients' in config and isinstance(config['clients'], dict), \
50 'configuration must contain a dictionary of clients'
51
52 clients = teuthology.replace_all_with_clients(ctx.cluster,
53 config['clients'])
54 testdir = teuthology.get_testdir(ctx)
55
56 overrides = ctx.config.get('overrides', {})
57 refspec = get_refspec_after_overrides(config, overrides)
58
59 git_url = teuth_config.get_ceph_qa_suite_git_url()
60 log.info('Pulling tests from %s ref %s', git_url, refspec)
61
62 try:
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)
66 remote.run(
67 args=[
68 'mkdir', '--', client_dir,
69 run.Raw('&&'),
70 'virtualenv', '{tdir}/virtualenv'.format(tdir=testdir),
71 run.Raw('&&'),
72 '{tdir}/virtualenv/bin/pip'.format(tdir=testdir),
73 'install', 'cram==0.6',
74 ],
75 )
76 clone_dir = '{tdir}/clone.{role}'.format(tdir=testdir, role=client)
77 remote.run(args=refspec.clone(git_url, clone_dir))
78
79 for test in tests:
80 assert test.endswith('.t'), 'tests must end in .t'
81 remote.run(
82 args=[
83 'cp', '--', os.path.join(clone_dir, test), client_dir,
84 ],
85 )
86
87 with parallel() as p:
88 for role in clients.iterkeys():
89 p.spawn(_run_tests, ctx, role)
90 finally:
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])
95
96 # remove test files unless they failed
97 for test_file in test_files:
98 abs_file = os.path.join(client_dir, test_file)
99 remote.run(
100 args=[
101 'test', '-f', abs_file + '.err',
102 run.Raw('||'),
103 'rm', '-f', '--', abs_file,
104 ],
105 )
106
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
110 remote.run(
111 args=[
112 'rm', '-rf', '--',
113 '{tdir}/virtualenv'.format(tdir=testdir),
114 clone_dir,
115 run.Raw(';'),
116 'rmdir', '--ignore-fail-on-non-empty', client_dir,
117 ],
118 )
119
120 def _run_tests(ctx, role):
121 """
122 For each role, check to make sure it's a client, then run the cram on that client
123
124 :param ctx: Context
125 :param role: Roles
126 """
127 assert isinstance(role, basestring)
128 PREFIX = 'client.'
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')
133
134 testdir = teuthology.get_testdir(ctx)
135 log.info('Running tests for %s...', role)
136 remote.run(
137 args=[
138 run.Raw('CEPH_REF={ref}'.format(ref=ceph_ref)),
139 run.Raw('CEPH_ID="{id}"'.format(id=id_)),
140 'adjust-ulimits',
141 'ceph-coverage',
142 '{tdir}/archive/coverage'.format(tdir=testdir),
143 '{tdir}/virtualenv/bin/cram'.format(tdir=testdir),
144 '-v', '--',
145 run.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir=testdir, role=role)),
146 ],
147 logger=log.getChild(role),
148 )