]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import logging |
2 | import os | |
3 | import yaml | |
4 | ||
5 | from teuthology import misc | |
11fdf7f2 TL |
6 | from teuthology.orchestra import run |
7 | from teuthology.task import Task | |
8 | ||
9 | log = logging.getLogger(__name__) | |
10 | ||
11 | ||
12 | class CBT(Task): | |
13 | """ | |
14 | Passes through a CBT configuration yaml fragment. | |
15 | """ | |
16 | def __init__(self, ctx, config): | |
17 | super(CBT, self).__init__(ctx, config) | |
18 | self.log = log | |
19 | ||
20 | def hosts_of_type(self, type_): | |
21 | return [r.name for r in self.ctx.cluster.only(misc.is_type(type_)).remotes.keys()] | |
22 | ||
23 | def generate_cbt_config(self): | |
24 | mon_hosts = self.hosts_of_type('mon') | |
25 | osd_hosts = self.hosts_of_type('osd') | |
26 | client_hosts = self.hosts_of_type('client') | |
27 | rgw_client = {} | |
28 | rgw_client[client_hosts[0]] = None | |
29 | rgw_hosts = self.config.get('cluster', {}).get('rgws', rgw_client) | |
30 | cluster_config = dict( | |
31 | user=self.config.get('cluster', {}).get('user', 'ubuntu'), | |
32 | head=mon_hosts[0], | |
33 | osds=osd_hosts, | |
34 | mons=mon_hosts, | |
35 | clients=client_hosts, | |
36 | rgws=rgw_hosts, | |
37 | osds_per_node=self.config.get('cluster', {}).get('osds_per_node', 1), | |
38 | rebuild_every_test=False, | |
39 | use_existing=True, | |
40 | is_teuthology=self.config.get('cluster', {}).get('is_teuthology', True), | |
41 | iterations=self.config.get('cluster', {}).get('iterations', 1), | |
42 | tmp_dir='/tmp/cbt', | |
43 | pool_profiles=self.config.get('cluster', {}).get('pool_profiles'), | |
44 | ) | |
45 | ||
46 | benchmark_config = self.config.get('benchmarks') | |
e306af50 | 47 | benchmark_type = next(iter(benchmark_config.keys())) |
9f95a23c | 48 | if benchmark_type in ['librbdfio', 'fio']: |
11fdf7f2 | 49 | testdir = misc.get_testdir(self.ctx) |
9f95a23c | 50 | benchmark_config[benchmark_type]['cmd_path'] = os.path.join(testdir, 'fio/fio') |
11fdf7f2 TL |
51 | if benchmark_type == 'cosbench': |
52 | # create cosbench_dir and cosbench_xml_dir | |
53 | testdir = misc.get_testdir(self.ctx) | |
54 | benchmark_config['cosbench']['cosbench_dir'] = os.path.join(testdir, 'cos') | |
55 | benchmark_config['cosbench']['cosbench_xml_dir'] = os.path.join(testdir, 'xml') | |
56 | self.ctx.cluster.run(args=['mkdir', '-p', '-m0755', '--', benchmark_config['cosbench']['cosbench_xml_dir']]) | |
57 | benchmark_config['cosbench']['controller'] = osd_hosts[0] | |
58 | ||
59 | # set auth details | |
60 | remotes_and_roles = self.ctx.cluster.remotes.items() | |
61 | ips = [host for (host, port) in | |
62 | (remote.ssh.get_transport().getpeername() for (remote, role_list) in remotes_and_roles)] | |
494da23a | 63 | benchmark_config['cosbench']['auth'] = "username=cosbench:operator;password=intel2012;url=http://%s:80/auth/v1.0;retry=9" %(ips[0]) |
9f95a23c | 64 | client_endpoints_config = self.config.get('client_endpoints', None) |
11fdf7f2 TL |
65 | |
66 | return dict( | |
67 | cluster=cluster_config, | |
68 | benchmarks=benchmark_config, | |
9f95a23c | 69 | client_endpoints = client_endpoints_config, |
11fdf7f2 TL |
70 | ) |
71 | ||
72 | def install_dependencies(self): | |
73 | system_type = misc.get_system_type(self.first_mon) | |
74 | ||
75 | if system_type == 'rpm': | |
76 | install_cmd = ['sudo', 'yum', '-y', 'install'] | |
9f95a23c | 77 | cbt_depends = ['python3-yaml', 'python3-lxml', 'librbd-devel', 'pdsh', 'collectl'] |
11fdf7f2 TL |
78 | else: |
79 | install_cmd = ['sudo', 'apt-get', '-y', '--force-yes', 'install'] | |
92f5a8d4 | 80 | cbt_depends = ['python3-yaml', 'python3-lxml', 'librbd-dev', 'collectl'] |
11fdf7f2 TL |
81 | self.first_mon.run(args=install_cmd + cbt_depends) |
82 | ||
e306af50 | 83 | benchmark_type = next(iter(self.cbt_config.get('benchmarks').keys())) |
11fdf7f2 TL |
84 | self.log.info('benchmark: %s', benchmark_type) |
85 | ||
9f95a23c | 86 | if benchmark_type in ['librbdfio', 'fio']: |
11fdf7f2 TL |
87 | # install fio |
88 | testdir = misc.get_testdir(self.ctx) | |
89 | self.first_mon.run( | |
90 | args=[ | |
91 | 'git', 'clone', '-b', 'master', | |
92 | 'https://github.com/axboe/fio.git', | |
93 | '{tdir}/fio'.format(tdir=testdir) | |
94 | ] | |
95 | ) | |
96 | self.first_mon.run( | |
97 | args=[ | |
98 | 'cd', os.path.join(testdir, 'fio'), run.Raw('&&'), | |
99 | './configure', run.Raw('&&'), | |
100 | 'make' | |
101 | ] | |
102 | ) | |
103 | ||
104 | if benchmark_type == 'cosbench': | |
105 | # install cosbench | |
106 | self.log.info('install dependencies for cosbench') | |
107 | if system_type == 'rpm': | |
108 | cosbench_depends = ['wget', 'unzip', 'java-1.7.0-openjdk', 'curl'] | |
109 | else: | |
110 | cosbench_depends = ['wget', 'unzip', 'openjdk-8-jre', 'curl'] | |
111 | self.first_mon.run(args=install_cmd + cosbench_depends) | |
112 | testdir = misc.get_testdir(self.ctx) | |
113 | cosbench_version = '0.4.2.c3' | |
114 | cosbench_location = 'https://github.com/intel-cloud/cosbench/releases/download/v0.4.2.c3/0.4.2.c3.zip' | |
115 | os_version = misc.get_system_type(self.first_mon, False, True) | |
116 | ||
117 | # additional requirements for bionic | |
118 | if os_version == '18.04': | |
119 | self.first_mon.run( | |
120 | args=['sudo', 'apt-get', '-y', 'purge', 'openjdk-11*']) | |
121 | # use our own version of cosbench | |
122 | cosbench_version = 'cosbench-0.4.2.c3.1' | |
123 | # contains additional parameter "-N" to nc | |
124 | cosbench_location = 'http://drop.ceph.com/qa/cosbench-0.4.2.c3.1.zip' | |
125 | cosbench_dir = os.path.join(testdir, cosbench_version) | |
126 | self.ctx.cluster.run(args=['mkdir', '-p', '-m0755', '--', cosbench_dir]) | |
127 | self.first_mon.run( | |
128 | args=[ | |
129 | 'cd', testdir, run.Raw('&&'), | |
130 | 'wget', | |
131 | cosbench_location, run.Raw('&&'), | |
132 | 'unzip', '{name}.zip'.format(name=cosbench_version), '-d', cosbench_version | |
133 | ] | |
134 | ) | |
135 | else: | |
136 | self.first_mon.run( | |
137 | args=[ | |
138 | 'cd', testdir, run.Raw('&&'), | |
139 | 'wget', | |
140 | cosbench_location, run.Raw('&&'), | |
141 | 'unzip', '{name}.zip'.format(name=cosbench_version) | |
142 | ] | |
143 | ) | |
144 | self.first_mon.run( | |
145 | args=[ | |
146 | 'cd', testdir, run.Raw('&&'), | |
147 | 'ln', '-s', cosbench_version, 'cos', | |
148 | ] | |
149 | ) | |
150 | self.first_mon.run( | |
151 | args=[ | |
152 | 'cd', os.path.join(testdir, 'cos'), run.Raw('&&'), | |
153 | 'chmod', '+x', run.Raw('*.sh'), | |
154 | ] | |
155 | ) | |
156 | ||
157 | # start cosbench and check info | |
158 | self.log.info('start cosbench') | |
159 | self.first_mon.run( | |
160 | args=[ | |
161 | 'cd', testdir, run.Raw('&&'), | |
162 | 'cd', 'cos', run.Raw('&&'), | |
163 | 'sh', 'start-all.sh' | |
164 | ] | |
165 | ) | |
166 | self.log.info('check cosbench info') | |
167 | self.first_mon.run( | |
168 | args=[ | |
169 | 'cd', testdir, run.Raw('&&'), | |
170 | 'cd', 'cos', run.Raw('&&'), | |
171 | 'sh', 'cli.sh', 'info' | |
172 | ] | |
173 | ) | |
174 | ||
175 | def checkout_cbt(self): | |
176 | testdir = misc.get_testdir(self.ctx) | |
177 | repo = self.config.get('repo', 'https://github.com/ceph/cbt.git') | |
178 | branch = self.config.get('branch', 'master') | |
179 | branch = self.config.get('force-branch', branch) | |
180 | sha1 = self.config.get('sha1') | |
9f95a23c TL |
181 | if sha1 is None: |
182 | self.first_mon.run( | |
183 | args=[ | |
184 | 'git', 'clone', '--depth', '1', '-b', branch, repo, | |
185 | '{tdir}/cbt'.format(tdir=testdir) | |
186 | ] | |
187 | ) | |
188 | else: | |
189 | self.first_mon.run( | |
190 | args=[ | |
191 | 'git', 'clone', '-b', branch, repo, | |
192 | '{tdir}/cbt'.format(tdir=testdir) | |
193 | ] | |
194 | ) | |
11fdf7f2 TL |
195 | self.first_mon.run( |
196 | args=[ | |
197 | 'cd', os.path.join(testdir, 'cbt'), run.Raw('&&'), | |
198 | 'git', 'reset', '--hard', sha1, | |
199 | ] | |
200 | ) | |
201 | ||
202 | def setup(self): | |
203 | super(CBT, self).setup() | |
e306af50 | 204 | self.first_mon = next(iter(self.ctx.cluster.only(misc.get_first_mon(self.ctx, self.config)).remotes.keys())) |
11fdf7f2 TL |
205 | self.cbt_config = self.generate_cbt_config() |
206 | self.log.info('cbt configuration is %s', self.cbt_config) | |
207 | self.cbt_dir = os.path.join(misc.get_archive_dir(self.ctx), 'cbt') | |
208 | self.ctx.cluster.run(args=['mkdir', '-p', '-m0755', '--', self.cbt_dir]) | |
f67539c2 TL |
209 | self.first_mon.write_file( |
210 | os.path.join(self.cbt_dir, 'cbt_config.yaml'), | |
211 | yaml.safe_dump(self.cbt_config, default_flow_style=False)) | |
11fdf7f2 TL |
212 | self.checkout_cbt() |
213 | self.install_dependencies() | |
214 | ||
215 | def begin(self): | |
216 | super(CBT, self).begin() | |
217 | testdir = misc.get_testdir(self.ctx) | |
218 | self.first_mon.run( | |
219 | args=[ | |
220 | '{tdir}/cbt/cbt.py'.format(tdir=testdir), | |
221 | '-a', self.cbt_dir, | |
222 | '{cbtdir}/cbt_config.yaml'.format(cbtdir=self.cbt_dir), | |
223 | ], | |
224 | ) | |
225 | preserve_file = os.path.join(self.ctx.archive, '.preserve') | |
226 | open(preserve_file, 'a').close() | |
227 | ||
228 | def end(self): | |
229 | super(CBT, self).end() | |
230 | testdir = misc.get_testdir(self.ctx) | |
231 | self.first_mon.run( | |
232 | args=[ | |
233 | 'rm', '--one-file-system', '-rf', '--', | |
234 | '{tdir}/cbt'.format(tdir=testdir), | |
235 | ] | |
236 | ) | |
e306af50 | 237 | benchmark_type = next(iter(self.cbt_config.get('benchmarks').keys())) |
9f95a23c | 238 | if benchmark_type in ['librbdfio', 'fio']: |
11fdf7f2 TL |
239 | self.first_mon.run( |
240 | args=[ | |
241 | 'rm', '--one-file-system', '-rf', '--', | |
242 | '{tdir}/fio'.format(tdir=testdir), | |
243 | ] | |
244 | ) | |
245 | ||
246 | if benchmark_type == 'cosbench': | |
247 | os_version = misc.get_system_type(self.first_mon, False, True) | |
248 | if os_version == '18.04': | |
249 | cosbench_version = 'cosbench-0.4.2.c3.1' | |
250 | else: | |
251 | cosbench_version = '0.4.2.c3' | |
eafe8130 TL |
252 | # note: stop-all requires 'nc' |
253 | self.first_mon.run( | |
254 | args=[ | |
255 | 'cd', testdir, run.Raw('&&'), | |
256 | 'cd', 'cos', run.Raw('&&'), | |
257 | 'sh', 'stop-all.sh', | |
258 | run.Raw('||'), 'true' | |
259 | ] | |
260 | ) | |
261 | self.first_mon.run( | |
262 | args=[ | |
263 | 'sudo', 'killall', '-9', 'java', | |
264 | run.Raw('||'), 'true' | |
265 | ] | |
266 | ) | |
11fdf7f2 TL |
267 | self.first_mon.run( |
268 | args=[ | |
269 | 'rm', '--one-file-system', '-rf', '--', | |
270 | '{tdir}/cos'.format(tdir=testdir), | |
271 | ] | |
272 | ) | |
273 | self.first_mon.run( | |
274 | args=[ | |
275 | 'rm', '--one-file-system', '-rf', '--', | |
276 | '{tdir}/{version}'.format(tdir=testdir, version=cosbench_version), | |
277 | ] | |
278 | ) | |
279 | self.first_mon.run( | |
280 | args=[ | |
281 | 'rm', '--one-file-system', '-rf', '--', | |
282 | '{tdir}/{version}.zip'.format(tdir=testdir, version=cosbench_version), | |
283 | ] | |
284 | ) | |
285 | self.first_mon.run( | |
286 | args=[ | |
287 | 'rm', '--one-file-system', '-rf', '--', | |
288 | '{tdir}/xml'.format(tdir=testdir), | |
289 | ] | |
290 | ) | |
291 | ||
292 | ||
293 | task = CBT |