]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | """ |
2 | Cram tests | |
3 | """ | |
4 | import logging | |
5 | import os | |
6 | ||
9f95a23c TL |
7 | import six |
8 | ||
e306af50 | 9 | from tasks.util.workunit import get_refspec_after_overrides |
91327a77 | 10 | |
7c673cae FG |
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 | |
15 | ||
16 | log = logging.getLogger(__name__) | |
17 | ||
18 | def task(ctx, config): | |
19 | """ | |
91327a77 | 20 | Run all cram tests from the specified paths on the specified |
7c673cae FG |
21 | clients. Each client runs tests in parallel. |
22 | ||
23 | Limitations: | |
24 | Tests must have a .t suffix. Tests with duplicate names will | |
25 | overwrite each other, so only the last one will run. | |
26 | ||
27 | For example:: | |
28 | ||
29 | tasks: | |
30 | - ceph: | |
31 | - cram: | |
32 | clients: | |
33 | client.0: | |
91327a77 AA |
34 | - qa/test.t |
35 | - qa/test2.t] | |
36 | client.1: [qa/test.t] | |
7c673cae FG |
37 | branch: foo |
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 | ||
61 | git_url = teuth_config.get_ceph_qa_suite_git_url() | |
62 | log.info('Pulling tests from %s ref %s', git_url, refspec) | |
7c673cae FG |
63 | |
64 | try: | |
9f95a23c TL |
65 | for client, tests in clients.items(): |
66 | (remote,) = ctx.cluster.only(client).remotes.keys() | |
7c673cae FG |
67 | client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client) |
68 | remote.run( | |
69 | args=[ | |
70 | 'mkdir', '--', client_dir, | |
71 | run.Raw('&&'), | |
72 | 'virtualenv', '{tdir}/virtualenv'.format(tdir=testdir), | |
73 | run.Raw('&&'), | |
74 | '{tdir}/virtualenv/bin/pip'.format(tdir=testdir), | |
75 | 'install', 'cram==0.6', | |
76 | ], | |
77 | ) | |
91327a77 AA |
78 | clone_dir = '{tdir}/clone.{role}'.format(tdir=testdir, role=client) |
79 | remote.run(args=refspec.clone(git_url, clone_dir)) | |
80 | ||
7c673cae | 81 | for test in tests: |
7c673cae FG |
82 | assert test.endswith('.t'), 'tests must end in .t' |
83 | remote.run( | |
84 | args=[ | |
91327a77 | 85 | 'cp', '--', os.path.join(clone_dir, test), client_dir, |
7c673cae FG |
86 | ], |
87 | ) | |
88 | ||
89 | with parallel() as p: | |
9f95a23c | 90 | for role in clients.keys(): |
7c673cae FG |
91 | p.spawn(_run_tests, ctx, role) |
92 | finally: | |
9f95a23c TL |
93 | for client, tests in clients.items(): |
94 | (remote,) = ctx.cluster.only(client).remotes.keys() | |
7c673cae FG |
95 | client_dir = '{tdir}/archive/cram.{role}'.format(tdir=testdir, role=client) |
96 | test_files = set([test.rsplit('/', 1)[1] for test in tests]) | |
97 | ||
98 | # remove test files unless they failed | |
99 | for test_file in test_files: | |
100 | abs_file = os.path.join(client_dir, test_file) | |
101 | remote.run( | |
102 | args=[ | |
103 | 'test', '-f', abs_file + '.err', | |
104 | run.Raw('||'), | |
105 | 'rm', '-f', '--', abs_file, | |
106 | ], | |
107 | ) | |
108 | ||
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 | |
112 | remote.run( | |
113 | args=[ | |
114 | 'rm', '-rf', '--', | |
115 | '{tdir}/virtualenv'.format(tdir=testdir), | |
91327a77 | 116 | clone_dir, |
7c673cae FG |
117 | run.Raw(';'), |
118 | 'rmdir', '--ignore-fail-on-non-empty', client_dir, | |
119 | ], | |
120 | ) | |
121 | ||
122 | def _run_tests(ctx, role): | |
123 | """ | |
124 | For each role, check to make sure it's a client, then run the cram on that client | |
125 | ||
126 | :param ctx: Context | |
127 | :param role: Roles | |
128 | """ | |
9f95a23c | 129 | assert isinstance(role, six.string_types) |
7c673cae FG |
130 | PREFIX = 'client.' |
131 | assert role.startswith(PREFIX) | |
132 | id_ = role[len(PREFIX):] | |
9f95a23c | 133 | (remote,) = ctx.cluster.only(role).remotes.keys() |
7c673cae FG |
134 | ceph_ref = ctx.summary.get('ceph-sha1', 'master') |
135 | ||
136 | testdir = teuthology.get_testdir(ctx) | |
137 | log.info('Running tests for %s...', role) | |
138 | remote.run( | |
139 | args=[ | |
140 | run.Raw('CEPH_REF={ref}'.format(ref=ceph_ref)), | |
141 | run.Raw('CEPH_ID="{id}"'.format(id=id_)), | |
11fdf7f2 | 142 | run.Raw('PATH=$PATH:/usr/sbin'), |
7c673cae FG |
143 | 'adjust-ulimits', |
144 | 'ceph-coverage', | |
145 | '{tdir}/archive/coverage'.format(tdir=testdir), | |
146 | '{tdir}/virtualenv/bin/cram'.format(tdir=testdir), | |
147 | '-v', '--', | |
148 | run.Raw('{tdir}/archive/cram.{role}/*.t'.format(tdir=testdir, role=role)), | |
149 | ], | |
150 | logger=log.getChild(role), | |
151 | ) |