]>
Commit | Line | Data |
---|---|---|
9f95a23c | 1 | """ |
7c673cae FG |
2 | Run an autotest test on the ceph cluster. |
3 | """ | |
4 | import json | |
5 | import logging | |
6 | import os | |
7 | ||
8 | from teuthology import misc as teuthology | |
9 | from teuthology.parallel import parallel | |
10 | from teuthology.orchestra import run | |
11 | ||
12 | log = logging.getLogger(__name__) | |
13 | ||
14 | def task(ctx, config): | |
15 | """ | |
16 | Run an autotest test on the ceph cluster. | |
17 | ||
18 | Only autotest client tests are supported. | |
19 | ||
20 | The config is a mapping from role name to list of tests to run on | |
21 | that client. | |
22 | ||
23 | For example:: | |
24 | ||
25 | tasks: | |
26 | - ceph: | |
27 | - ceph-fuse: [client.0, client.1] | |
28 | - autotest: | |
29 | client.0: [dbench] | |
30 | client.1: [bonnie] | |
31 | ||
32 | You can also specify a list of tests to run on all clients:: | |
33 | ||
34 | tasks: | |
35 | - ceph: | |
36 | - ceph-fuse: | |
37 | - autotest: | |
38 | all: [dbench] | |
39 | """ | |
40 | assert isinstance(config, dict) | |
41 | config = teuthology.replace_all_with_clients(ctx.cluster, config) | |
42 | log.info('Setting up autotest...') | |
43 | testdir = teuthology.get_testdir(ctx) | |
44 | with parallel() as p: | |
9f95a23c | 45 | for role in config.keys(): |
7c673cae FG |
46 | (remote,) = ctx.cluster.only(role).remotes.keys() |
47 | p.spawn(_download, testdir, remote) | |
48 | ||
49 | log.info('Making a separate scratch dir for every client...') | |
9f95a23c | 50 | for role in config.keys(): |
f67539c2 | 51 | assert isinstance(role, str) |
7c673cae FG |
52 | PREFIX = 'client.' |
53 | assert role.startswith(PREFIX) | |
54 | id_ = role[len(PREFIX):] | |
9f95a23c | 55 | (remote,) = ctx.cluster.only(role).remotes.keys() |
7c673cae FG |
56 | mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_)) |
57 | scratch = os.path.join(mnt, 'client.{id}'.format(id=id_)) | |
58 | remote.run( | |
59 | args=[ | |
60 | 'sudo', | |
61 | 'install', | |
62 | '-d', | |
63 | '-m', '0755', | |
64 | '--owner={user}'.format(user='ubuntu'), #TODO | |
65 | '--', | |
66 | scratch, | |
67 | ], | |
68 | ) | |
69 | ||
70 | with parallel() as p: | |
9f95a23c | 71 | for role, tests in config.items(): |
7c673cae FG |
72 | (remote,) = ctx.cluster.only(role).remotes.keys() |
73 | p.spawn(_run_tests, testdir, remote, role, tests) | |
74 | ||
75 | def _download(testdir, remote): | |
76 | """ | |
77 | Download. Does not explicitly support muliple tasks in a single run. | |
78 | """ | |
79 | remote.run( | |
80 | args=[ | |
81 | # explicitly does not support multiple autotest tasks | |
82 | # in a single run; the result archival would conflict | |
83 | 'mkdir', '{tdir}/archive/autotest'.format(tdir=testdir), | |
84 | run.Raw('&&'), | |
85 | 'mkdir', '{tdir}/autotest'.format(tdir=testdir), | |
86 | run.Raw('&&'), | |
87 | 'wget', | |
88 | '-nv', | |
89 | '--no-check-certificate', | |
90 | 'https://github.com/ceph/autotest/tarball/ceph', | |
91 | '-O-', | |
92 | run.Raw('|'), | |
93 | 'tar', | |
94 | '-C', '{tdir}/autotest'.format(tdir=testdir), | |
95 | '-x', | |
96 | '-z', | |
97 | '-f-', | |
98 | '--strip-components=1', | |
99 | ], | |
100 | ) | |
101 | ||
102 | def _run_tests(testdir, remote, role, tests): | |
103 | """ | |
104 | Spawned to run test on remote site | |
105 | """ | |
f67539c2 | 106 | assert isinstance(role, str) |
7c673cae FG |
107 | PREFIX = 'client.' |
108 | assert role.startswith(PREFIX) | |
109 | id_ = role[len(PREFIX):] | |
110 | mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_)) | |
111 | scratch = os.path.join(mnt, 'client.{id}'.format(id=id_)) | |
112 | ||
113 | assert isinstance(tests, list) | |
114 | for idx, testname in enumerate(tests): | |
115 | log.info('Running autotest client test #%d: %s...', idx, testname) | |
116 | ||
117 | tag = 'client.{id}.num{idx}.{testname}'.format( | |
118 | idx=idx, | |
119 | testname=testname, | |
120 | id=id_, | |
121 | ) | |
122 | control = '{tdir}/control.{tag}'.format(tdir=testdir, tag=tag) | |
f67539c2 | 123 | remote.write_file( |
7c673cae FG |
124 | path=control, |
125 | data='import json; data=json.loads({data!r}); job.run_test(**data)'.format( | |
126 | data=json.dumps(dict( | |
127 | url=testname, | |
128 | dir=scratch, | |
129 | # TODO perhaps tag | |
130 | # results will be in {testdir}/autotest/client/results/dbench | |
131 | # or {testdir}/autotest/client/results/dbench.{tag} | |
132 | )), | |
133 | ), | |
134 | ) | |
135 | remote.run( | |
136 | args=[ | |
137 | '{tdir}/autotest/client/bin/autotest'.format(tdir=testdir), | |
138 | '--verbose', | |
139 | '--harness=simple', | |
140 | '--tag={tag}'.format(tag=tag), | |
141 | control, | |
142 | run.Raw('3>&1'), | |
143 | ], | |
144 | ) | |
145 | ||
146 | remote.run( | |
147 | args=[ | |
148 | 'rm', '-rf', '--', control, | |
149 | ], | |
150 | ) | |
151 | ||
152 | remote.run( | |
153 | args=[ | |
154 | 'mv', | |
155 | '--', | |
156 | '{tdir}/autotest/client/results/{tag}'.format(tdir=testdir, tag=tag), | |
157 | '{tdir}/archive/autotest/{tag}'.format(tdir=testdir, tag=tag), | |
158 | ], | |
159 | ) | |
160 | ||
161 | remote.run( | |
162 | args=[ | |
163 | 'rm', '-rf', '--', '{tdir}/autotest'.format(tdir=testdir), | |
164 | ], | |
165 | ) |