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