]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/pybind/test_ceph_argparse.py
update sources to v12.1.2
[ceph.git] / ceph / src / test / pybind / test_ceph_argparse.py
CommitLineData
7c673cae
FG
1#!/usr/bin/env nosetests
2# -*- mode:python; tab-width:4; indent-tabs-mode:t; coding:utf-8 -*-
3# vim: ts=4 sw=4 smarttab expandtab fileencoding=utf-8
4#
5# Ceph - scalable distributed file system
6#
7# Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
8# Copyright (C) 2014 Red Hat <contact@redhat.com>
9#
10# Author: Loic Dachary <loic@dachary.org>
11#
12# This library is free software; you can redistribute it and/or
13# modify it under the terms of the GNU Lesser General Public
14# License as published by the Free Software Foundation; either
15# version 2.1 of the License, or (at your option) any later version.
16#
17
18from nose.tools import eq_ as eq
19from nose.tools import *
20
21from ceph_argparse import validate_command, parse_json_funcsigs
22
23import os
24import re
25import json
26
27def get_command_descriptions(what):
28 CEPH_BIN = os.environ['CEPH_BIN']
29 if CEPH_BIN == "":
30 CEPH_BIN = "."
31 return os.popen(CEPH_BIN + "/get_command_descriptions " + "--" + what).read()
32
33def test_parse_json_funcsigs():
34 commands = get_command_descriptions("all")
35 cmd_json = parse_json_funcsigs(commands, 'cli')
36
37 # syntax error https://github.com/ceph/ceph/pull/585
38 commands = get_command_descriptions("pull585")
39 assert_raises(TypeError, parse_json_funcsigs, commands, 'cli')
40
41sigdict = parse_json_funcsigs(get_command_descriptions("all"), 'cli')
42
43
44class TestArgparse:
45
46 def assert_valid_command(self, args):
47 result = validate_command(sigdict, args)
48 assert_not_equal(result,None)
49 assert_not_equal(result,{})
50
51 def check_1_natural_arg(self, prefix, command):
52 self.assert_valid_command([prefix, command, '1'])
53 assert_equal({}, validate_command(sigdict, [prefix, command]))
54 assert_equal({}, validate_command(sigdict, [prefix, command, '-1']))
55 assert_equal({}, validate_command(sigdict, [prefix, command, '1',
56 '1']))
57
58 def check_0_or_1_natural_arg(self, prefix, command):
59 self.assert_valid_command([prefix, command, '1'])
60 self.assert_valid_command([prefix, command])
61 assert_equal({}, validate_command(sigdict, [prefix, command, '-1']))
62 assert_equal({}, validate_command(sigdict, [prefix, command, '1',
63 '1']))
64
65 def check_1_string_arg(self, prefix, command):
66 assert_equal({}, validate_command(sigdict, [prefix, command]))
67 self.assert_valid_command([prefix, command, 'string'])
68 assert_equal({}, validate_command(sigdict, [prefix,
69 command,
70 'string',
71 'toomany']))
72
73 def check_1_or_more_string_args(self, prefix, command):
74 assert_equal({}, validate_command(sigdict, [prefix,
75 command]))
76 self.assert_valid_command([prefix,
77 command,
78 'string'])
79 self.assert_valid_command([prefix,
80 command,
81 'string',
82 'more string'])
83
84 def check_no_arg(self, prefix, command):
85 self.assert_valid_command([prefix,
86 command])
87 assert_equal({}, validate_command(sigdict, [prefix,
88 command,
89 'toomany']))
90
91
92class TestBasic:
93
94 def test_non_ascii_in_non_options(self):
95 # ArgumentPrefix("no match for {0}".format(s)) is not able to convert
96 # unicode str parameter into str. and validate_command() should not
97 # choke on it.
98 assert_is_none(validate_command(sigdict, [u'章鱼和鱿鱼']))
99 assert_is_none(validate_command(sigdict, [u'–w']))
100 # actually we always pass unicode strings to validate_command() in "ceph"
101 # CLI, but we also use bytestrings in our tests, so make sure it does not
102 # break.
103 assert_is_none(validate_command(sigdict, ['章鱼和鱿鱼']))
104 assert_is_none(validate_command(sigdict, ['–w']))
105
106
107class TestPG(TestArgparse):
108
109 def test_stat(self):
110 self.assert_valid_command(['pg', 'stat'])
111
112 def test_getmap(self):
113 self.assert_valid_command(['pg', 'getmap'])
114
115 def test_dump(self):
116 self.assert_valid_command(['pg', 'dump'])
117 self.assert_valid_command(['pg', 'dump',
118 'all',
119 'summary',
120 'sum',
121 'delta',
122 'pools',
123 'osds',
124 'pgs',
125 'pgs_brief'])
126 assert_equal({}, validate_command(sigdict, ['pg', 'dump', 'invalid']))
127
128 def test_dump_json(self):
129 self.assert_valid_command(['pg', 'dump_json'])
130 self.assert_valid_command(['pg', 'dump_json',
131 'all',
132 'summary',
133 'sum',
134 'pools',
135 'osds',
136 'pgs'])
137 assert_equal({}, validate_command(sigdict, ['pg', 'dump_json',
138 'invalid']))
139
140 def test_dump_pools_json(self):
141 self.assert_valid_command(['pg', 'dump_pools_json'])
142
143 def test_dump_pools_stuck(self):
144 self.assert_valid_command(['pg', 'dump_stuck'])
145 self.assert_valid_command(['pg', 'dump_stuck',
146 'inactive',
147 'unclean',
148 'stale'])
149 assert_equal({}, validate_command(sigdict, ['pg', 'dump_stuck',
150 'invalid']))
151 self.assert_valid_command(['pg', 'dump_stuck',
152 'inactive',
153 '1234'])
154
155 def one_pgid(self, command):
156 self.assert_valid_command(['pg', command, '1.1'])
157 assert_equal({}, validate_command(sigdict, ['pg', command]))
158 assert_equal({}, validate_command(sigdict, ['pg', command, '1']))
159
160 def test_map(self):
161 self.one_pgid('map')
162
163 def test_scrub(self):
164 self.one_pgid('scrub')
165
166 def test_deep_scrub(self):
167 self.one_pgid('deep-scrub')
168
169 def test_repair(self):
170 self.one_pgid('repair')
171
172 def test_debug(self):
173 self.assert_valid_command(['pg',
174 'debug',
175 'unfound_objects_exist'])
176 self.assert_valid_command(['pg',
177 'debug',
178 'degraded_pgs_exist'])
179 assert_equal({}, validate_command(sigdict, ['pg', 'debug']))
180 assert_equal({}, validate_command(sigdict, ['pg', 'debug',
181 'invalid']))
182
7c673cae
FG
183
184class TestAuth(TestArgparse):
185
186 def test_export(self):
187 self.assert_valid_command(['auth', 'export'])
188 self.assert_valid_command(['auth',
189 'export',
190 'string'])
191 assert_equal({}, validate_command(sigdict, ['auth',
192 'export',
193 'string',
194 'toomany']))
195
196 def test_get(self):
197 self.check_1_string_arg('auth', 'get')
198
199 def test_get_key(self):
200 self.check_1_string_arg('auth', 'get-key')
201
202 def test_print_key(self):
203 self.check_1_string_arg('auth', 'print-key')
204 self.check_1_string_arg('auth', 'print_key')
205
206 def test_list(self):
207 self.check_no_arg('auth', 'list')
208
209 def test_import(self):
210 self.check_no_arg('auth', 'import')
211
212 def test_add(self):
213 self.check_1_or_more_string_args('auth', 'add')
214
215 def test_get_or_create_key(self):
216 self.check_1_or_more_string_args('auth', 'get-or-create-key')
217
218 def test_get_or_create(self):
219 self.check_1_or_more_string_args('auth', 'get-or-create')
220
221 def test_caps(self):
222 assert_equal({}, validate_command(sigdict, ['auth',
223 'caps']))
224 assert_equal({}, validate_command(sigdict, ['auth',
225 'caps',
226 'string']))
227 self.assert_valid_command(['auth',
228 'caps',
229 'string',
230 'more string'])
231
232 def test_del(self):
233 self.check_1_string_arg('auth', 'del')
234
235
236class TestMonitor(TestArgparse):
237
238 def test_compact(self):
239 self.assert_valid_command(['compact'])
240
241 def test_scrub(self):
242 self.assert_valid_command(['scrub'])
243
244 def test_fsid(self):
245 self.assert_valid_command(['fsid'])
246
247 def test_log(self):
248 assert_equal({}, validate_command(sigdict, ['log']))
249 self.assert_valid_command(['log', 'a logtext'])
250 self.assert_valid_command(['log', 'a logtext', 'and another'])
251
252 def test_injectargs(self):
253 assert_equal({}, validate_command(sigdict, ['injectargs']))
254 self.assert_valid_command(['injectargs', 'one'])
255 self.assert_valid_command(['injectargs', 'one', 'two'])
256
257 def test_status(self):
258 self.assert_valid_command(['status'])
259
260 def test_health(self):
261 self.assert_valid_command(['health'])
262 self.assert_valid_command(['health', 'detail'])
263 assert_equal({}, validate_command(sigdict, ['health', 'invalid']))
264 assert_equal({}, validate_command(sigdict, ['health', 'detail',
265 'toomany']))
266
267 def test_df(self):
268 self.assert_valid_command(['df'])
269 self.assert_valid_command(['df', 'detail'])
270 assert_equal({}, validate_command(sigdict, ['df', 'invalid']))
271 assert_equal({}, validate_command(sigdict, ['df', 'detail',
272 'toomany']))
273
274 def test_report(self):
275 self.assert_valid_command(['report'])
276 self.assert_valid_command(['report', 'tag1'])
277 self.assert_valid_command(['report', 'tag1', 'tag2'])
278
279 def test_quorum_status(self):
280 self.assert_valid_command(['quorum_status'])
281
282 def test_mon_status(self):
283 self.assert_valid_command(['mon_status'])
284
285 def test_sync_force(self):
286 self.assert_valid_command(['sync',
287 'force',
288 '--yes-i-really-mean-it',
289 '--i-know-what-i-am-doing'])
290 self.assert_valid_command(['sync',
291 'force',
292 '--yes-i-really-mean-it'])
293 self.assert_valid_command(['sync',
294 'force'])
295 assert_equal({}, validate_command(sigdict, ['sync']))
296 assert_equal({}, validate_command(sigdict, ['sync',
297 'force',
298 '--yes-i-really-mean-it',
299 '--i-know-what-i-am-doing',
300 'toomany']))
301
302 def test_heap(self):
303 assert_equal({}, validate_command(sigdict, ['heap']))
304 assert_equal({}, validate_command(sigdict, ['heap', 'invalid']))
305 self.assert_valid_command(['heap', 'dump'])
306 self.assert_valid_command(['heap', 'start_profiler'])
307 self.assert_valid_command(['heap', 'stop_profiler'])
308 self.assert_valid_command(['heap', 'release'])
309 self.assert_valid_command(['heap', 'stats'])
310
311 def test_quorum(self):
312 assert_equal({}, validate_command(sigdict, ['quorum']))
313 assert_equal({}, validate_command(sigdict, ['quorum', 'invalid']))
314 self.assert_valid_command(['quorum', 'enter'])
315 self.assert_valid_command(['quorum', 'exit'])
316 assert_equal({}, validate_command(sigdict, ['quorum',
317 'enter',
318 'toomany']))
319
320 def test_tell(self):
321 assert_equal({}, validate_command(sigdict, ['tell']))
322 assert_equal({}, validate_command(sigdict, ['tell', 'invalid']))
323 for name in ('osd', 'mon', 'client', 'mds'):
324 assert_equal({}, validate_command(sigdict, ['tell', name]))
325 assert_equal({}, validate_command(sigdict, ['tell',
326 name + ".42"]))
327 self.assert_valid_command(['tell', name + ".42", 'something'])
328 self.assert_valid_command(['tell', name + ".42",
329 'something',
330 'something else'])
331
332
333class TestMDS(TestArgparse):
334
335 def test_stat(self):
336 self.check_no_arg('mds', 'stat')
337
338 def test_dump(self):
339 self.check_0_or_1_natural_arg('mds', 'dump')
340
341 def test_tell(self):
342 self.assert_valid_command(['mds', 'tell',
343 'someone',
344 'something'])
345 self.assert_valid_command(['mds', 'tell',
346 'someone',
347 'something',
348 'something else'])
349 assert_equal({}, validate_command(sigdict, ['mds', 'tell']))
350 assert_equal({}, validate_command(sigdict, ['mds', 'tell',
351 'someone']))
352
353 def test_compat_show(self):
354 self.assert_valid_command(['mds', 'compat', 'show'])
355 assert_equal({}, validate_command(sigdict, ['mds', 'compat']))
356 assert_equal({}, validate_command(sigdict, ['mds', 'compat',
357 'show', 'toomany']))
358
359 def test_stop(self):
360 self.assert_valid_command(['mds', 'stop', 'someone'])
361 assert_equal({}, validate_command(sigdict, ['mds', 'stop']))
362 assert_equal({}, validate_command(sigdict, ['mds', 'stop',
363 'someone', 'toomany']))
364
365 def test_deactivate(self):
366 self.assert_valid_command(['mds', 'deactivate', 'someone'])
367 assert_equal({}, validate_command(sigdict, ['mds', 'deactivate']))
368 assert_equal({}, validate_command(sigdict, ['mds', 'deactivate',
369 'someone', 'toomany']))
370
371 def test_set_max_mds(self):
372 self.check_1_natural_arg('mds', 'set_max_mds')
373
374 def test_set_state(self):
375 self.assert_valid_command(['mds', 'set_state', '1', '2'])
376 assert_equal({}, validate_command(sigdict, ['mds', 'set_state']))
377 assert_equal({}, validate_command(sigdict, ['mds', 'set_state', '-1']))
378 assert_equal({}, validate_command(sigdict, ['mds', 'set_state',
379 '1', '-1']))
380 assert_equal({}, validate_command(sigdict, ['mds', 'set_state',
381 '1', '21']))
382
383 def test_fail(self):
384 self.check_1_string_arg('mds', 'fail')
385
386 def test_rm(self):
387 # Valid: single GID argument present
388 self.assert_valid_command(['mds', 'rm', '1'])
389
390 # Missing GID arg: invalid
391 assert_equal({}, validate_command(sigdict, ['mds', 'rm']))
392 # Extra arg: invalid
393 assert_equal({}, validate_command(sigdict, ['mds', 'rm', '1', 'mds.42']))
394
395 def test_rmfailed(self):
396 self.assert_valid_command(['mds', 'rmfailed', '0'])
397 self.assert_valid_command(['mds', 'rmfailed', '0', '--yes-i-really-mean-it'])
398 assert_equal({}, validate_command(sigdict, ['mds', 'rmfailed', '0',
399 '--yes-i-really-mean-it',
400 'toomany']))
401
402 def test_cluster_down(self):
403 self.check_no_arg('mds', 'cluster_down')
404
405 def test_cluster_up(self):
406 self.check_no_arg('mds', 'cluster_up')
407
408 def test_compat_rm_compat(self):
409 self.assert_valid_command(['mds', 'compat', 'rm_compat', '1'])
410 assert_equal({}, validate_command(sigdict, ['mds',
411 'compat',
412 'rm_compat']))
413 assert_equal({}, validate_command(sigdict, ['mds',
414 'compat',
415 'rm_compat', '-1']))
416 assert_equal({}, validate_command(sigdict, ['mds',
417 'compat',
418 'rm_compat', '1', '1']))
419
420 def test_incompat_rm_incompat(self):
421 self.assert_valid_command(['mds', 'compat', 'rm_incompat', '1'])
422 assert_equal({}, validate_command(sigdict, ['mds',
423 'compat',
424 'rm_incompat']))
425 assert_equal({}, validate_command(sigdict, ['mds',
426 'compat',
427 'rm_incompat', '-1']))
428 assert_equal({}, validate_command(sigdict, ['mds',
429 'compat',
430 'rm_incompat', '1', '1']))
431
432 def test_mds_set(self):
433 self.assert_valid_command(['mds', 'set', 'max_mds', '2'])
434 self.assert_valid_command(['mds', 'set', 'max_file_size', '2'])
435 self.assert_valid_command(['mds', 'set', 'allow_new_snaps', 'no'])
436 assert_equal({}, validate_command(sigdict, ['mds',
437 'set',
438 'invalid']))
439
440 def test_add_data_pool(self):
441 self.assert_valid_command(['mds', 'add_data_pool', '1'])
442 self.assert_valid_command(['mds', 'add_data_pool', 'foo'])
443
444 def test_remove_data_pool(self):
445 self.assert_valid_command(['mds', 'remove_data_pool', '1'])
446 self.assert_valid_command(['mds', 'remove_data_pool', 'foo'])
447
448 def test_newfs(self):
449 self.assert_valid_command(['mds', 'newfs', '1', '2',
450 '--yes-i-really-mean-it'])
451 self.assert_valid_command(['mds', 'newfs', '1', '2'])
452 assert_equal({}, validate_command(sigdict, ['mds', 'newfs']))
453 assert_equal({}, validate_command(sigdict, ['mds', 'newfs', '1']))
454 assert_equal({}, validate_command(sigdict, ['mds',
455 'newfs',
456 '1',
457 '2',
458 '--yes-i-really-mean-it',
459 'toomany']))
460 assert_equal({}, validate_command(sigdict, ['mds',
461 'newfs',
462 '-1',
463 '2',
464 '--yes-i-really-mean-it']))
465 assert_equal({}, validate_command(sigdict, ['mds',
466 'newfs',
467 '1',
468 '-1',
469 '--yes-i-really-mean-it']))
470
471
472class TestFS(TestArgparse):
473
474 def test_dump(self):
475 self.check_0_or_1_natural_arg('fs', 'dump')
476
477 def test_fs_new(self):
478 self.assert_valid_command(['fs', 'new', 'default', 'metadata', 'data'])
479
480 def test_fs_rm(self):
481 self.assert_valid_command(['fs', 'rm', 'default'])
482 self.assert_valid_command(['fs', 'rm', 'default', '--yes-i-really-mean-it'])
483 assert_equal({}, validate_command(sigdict, ['fs', 'rm', 'default', '--yes-i-really-mean-it', 'toomany']))
484
485 def test_fs_ls(self):
486 self.assert_valid_command(['fs', 'ls'])
487 assert_equal({}, validate_command(sigdict, ['fs', 'ls', 'toomany']))
488
489 def test_fs_set_default(self):
490 self.assert_valid_command(['fs', 'set-default', 'cephfs'])
491 assert_equal({}, validate_command(sigdict, ['fs', 'set-default']))
492 assert_equal({}, validate_command(sigdict, ['fs', 'set-default', 'cephfs', 'toomany']))
493
494class TestMon(TestArgparse):
495
496 def test_dump(self):
497 self.check_0_or_1_natural_arg('mon', 'dump')
498
499 def test_stat(self):
500 self.check_no_arg('mon', 'stat')
501
502 def test_getmap(self):
503 self.check_0_or_1_natural_arg('mon', 'getmap')
504
505 def test_add(self):
506 self.assert_valid_command(['mon', 'add', 'name', '1.2.3.4:1234'])
507 assert_equal({}, validate_command(sigdict, ['mon', 'add']))
508 assert_equal({}, validate_command(sigdict, ['mon', 'add', 'name']))
509 assert_equal({}, validate_command(sigdict, ['mon', 'add',
510 'name',
511 '400.500.600.700']))
512 assert_equal({}, validate_command(sigdict, ['mon', 'add', 'name',
513 '1.2.3.4:1234',
514 'toomany']))
515
516 def test_remove(self):
517 self.assert_valid_command(['mon', 'remove', 'name'])
518 assert_equal({}, validate_command(sigdict, ['mon', 'remove']))
519 assert_equal({}, validate_command(sigdict, ['mon', 'remove',
520 'name', 'toomany']))
521
522
523class TestOSD(TestArgparse):
524
525 def test_stat(self):
526 self.check_no_arg('osd', 'stat')
527
528 def test_dump(self):
529 self.check_0_or_1_natural_arg('osd', 'dump')
530
531 def test_osd_tree(self):
532 self.check_0_or_1_natural_arg('osd', 'tree')
533
534 def test_osd_ls(self):
535 self.check_0_or_1_natural_arg('osd', 'ls')
536
537 def test_osd_getmap(self):
538 self.check_0_or_1_natural_arg('osd', 'getmap')
539
540 def test_osd_getcrushmap(self):
541 self.check_0_or_1_natural_arg('osd', 'getcrushmap')
542
543 def test_perf(self):
544 self.check_no_arg('osd', 'perf')
545
546 def test_getmaxosd(self):
547 self.check_no_arg('osd', 'getmaxosd')
548
549 def test_find(self):
550 self.check_1_natural_arg('osd', 'find')
551
552 def test_map(self):
553 self.assert_valid_command(['osd', 'map', 'poolname', 'objectname'])
554 self.assert_valid_command(['osd', 'map', 'poolname', 'objectname', 'nspace'])
555 assert_equal({}, validate_command(sigdict, ['osd', 'map']))
556 assert_equal({}, validate_command(sigdict, ['osd', 'map', 'poolname']))
557 assert_equal({}, validate_command(sigdict, ['osd', 'map',
558 'poolname', 'objectname', 'nspace',
559 'toomany']))
560
561 def test_metadata(self):
562 self.check_0_or_1_natural_arg('osd', 'metadata')
563
564 def test_scrub(self):
565 self.check_1_string_arg('osd', 'scrub')
566
567 def test_deep_scrub(self):
568 self.check_1_string_arg('osd', 'deep-scrub')
569
570 def test_repair(self):
571 self.check_1_string_arg('osd', 'repair')
572
573 def test_lspools(self):
574 self.assert_valid_command(['osd', 'lspools'])
575 self.assert_valid_command(['osd', 'lspools', '1'])
576 self.assert_valid_command(['osd', 'lspools', '-1'])
577 assert_equal({}, validate_command(sigdict, ['osd', 'lspools',
578 '1', 'toomany']))
579
580 def test_blacklist_ls(self):
581 self.assert_valid_command(['osd', 'blacklist', 'ls'])
582 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist']))
583 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
584 'ls', 'toomany']))
585
586 def test_crush_rule(self):
587 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
588 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule']))
589 for subcommand in ('list', 'ls'):
590 self.assert_valid_command(['osd', 'crush', 'rule', subcommand])
591 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
592 'rule', subcommand,
593 'toomany']))
594
595 def test_crush_rule_dump(self):
596 self.assert_valid_command(['osd', 'crush', 'rule', 'dump'])
597 self.assert_valid_command(['osd', 'crush', 'rule', 'dump', 'RULE'])
598 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
599 'rule', 'dump',
600 'RULE',
601 'toomany']))
602
603 def test_crush_dump(self):
604 self.assert_valid_command(['osd', 'crush', 'dump'])
605 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
606 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
607 'dump',
608 'toomany']))
609
610 def test_setcrushmap(self):
611 self.check_no_arg('osd', 'setcrushmap')
612
613 def test_crush_add_bucket(self):
614 self.assert_valid_command(['osd', 'crush', 'add-bucket',
615 'name', 'type'])
616 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
617 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
618 'add-bucket']))
619 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
620 'add-bucket', 'name',
621 'type',
622 'toomany']))
623 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
624 'add-bucket', '^^^',
625 'type']))
626
627 def test_crush_rename_bucket(self):
628 self.assert_valid_command(['osd', 'crush', 'rename-bucket',
629 'srcname', 'dstname'])
630 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
631 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
632 'rename-bucket']))
633 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
634 'rename-bucket',
635 'srcname']))
636 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
637 'rename-bucket', 'srcname',
638 'dstname',
639 'toomany']))
640 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
641 'rename-bucket', '^^^',
642 'dstname']))
643 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
644 'rename-bucket', 'srcname',
645 '^^^^']))
646
647 def check_crush_setter(self, setter):
648 self.assert_valid_command(['osd', 'crush', setter,
649 '*', '2.3', 'AZaz09-_.='])
650 self.assert_valid_command(['osd', 'crush', setter,
651 'osd.0', '2.3', 'AZaz09-_.='])
652 self.assert_valid_command(['osd', 'crush', setter,
653 '0', '2.3', 'AZaz09-_.='])
654 self.assert_valid_command(['osd', 'crush', setter,
655 '0', '2.3', 'AZaz09-_.=', 'AZaz09-_.='])
656 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
657 setter,
658 'osd.0']))
659 ret = validate_command(sigdict, ['osd', 'crush',
660 setter,
661 'osd.0',
662 '-1.0'])
663 assert ret in [None, {}]
664 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
665 setter,
666 'osd.0',
667 '1.0',
668 '^^^']))
669
670 def test_crush_set(self):
671 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
672 self.check_crush_setter('set')
673
674 def test_crush_add(self):
675 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
676 self.check_crush_setter('add')
677
678 def test_crush_create_or_move(self):
679 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
680 self.check_crush_setter('create-or-move')
681
682 def test_crush_move(self):
683 self.assert_valid_command(['osd', 'crush', 'move',
684 'AZaz09-_.', 'AZaz09-_.='])
685 self.assert_valid_command(['osd', 'crush', 'move',
686 '0', 'AZaz09-_.=', 'AZaz09-_.='])
687 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
688 'move']))
689 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
690 'move', 'AZaz09-_.']))
691 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
692 'move', '^^^',
693 'AZaz09-_.=']))
694 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
695 'move', 'AZaz09-_.',
696 '^^^']))
697
698 def test_crush_link(self):
699 self.assert_valid_command(['osd', 'crush', 'link',
700 'name', 'AZaz09-_.='])
701 self.assert_valid_command(['osd', 'crush', 'link',
702 'name', 'AZaz09-_.=', 'AZaz09-_.='])
703 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
704 'link']))
705 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
706 'link',
707 'name']))
708
709 def test_crush_rm(self):
710 for alias in ('rm', 'remove', 'unlink'):
711 self.assert_valid_command(['osd', 'crush', alias, 'AZaz09-_.'])
712 self.assert_valid_command(['osd', 'crush', alias,
713 'AZaz09-_.', 'AZaz09-_.'])
714 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
715 alias]))
716 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
717 alias,
718 'AZaz09-_.',
719 'AZaz09-_.',
720 'toomany']))
721
722 def test_crush_reweight(self):
723 self.assert_valid_command(['osd', 'crush', 'reweight',
724 'AZaz09-_.', '2.3'])
725 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
726 'reweight']))
727 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
728 'reweight',
729 'AZaz09-_.']))
730 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
731 'reweight',
732 'AZaz09-_.',
733 '-1.0']))
734 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
735 'reweight',
736 '^^^',
737 '2.3']))
738
739 def test_crush_tunables(self):
740 for tunable in ('legacy', 'argonaut', 'bobtail', 'firefly',
741 'optimal', 'default'):
742 self.assert_valid_command(['osd', 'crush', 'tunables',
743 tunable])
744 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
745 'tunables']))
746 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
747 'tunables',
748 'default', 'toomany']))
749
750 def test_crush_rule_create_simple(self):
751 self.assert_valid_command(['osd', 'crush', 'rule', 'create-simple',
752 'AZaz09-_.', 'AZaz09-_.', 'AZaz09-_.'])
753 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
754 'create-simple']))
755 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
756 'create-simple',
757 'AZaz09-_.']))
758 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
759 'create-simple',
760 'AZaz09-_.',
761 'AZaz09-_.']))
762 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
763 'create-simple',
764 '^^^',
765 'AZaz09-_.',
766 'AZaz09-_.']))
767 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
768 'create-simple',
769 'AZaz09-_.',
770 '|||',
771 'AZaz09-_.']))
772 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
773 'create-simple',
774 'AZaz09-_.',
775 'AZaz09-_.',
776 '+++']))
777 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
778 'create-simple',
779 'AZaz09-_.',
780 'AZaz09-_.',
781 'AZaz09-_.',
782 'toomany']))
783
784 def test_crush_rule_create_erasure(self):
785 self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
786 'AZaz09-_.'])
787 self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
788 'AZaz09-_.', 'whatever'])
789 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
790 'create-erasure']))
791 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
792 'create-erasure',
793 '^^^']))
794 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
795 'create-erasure',
796 'name', '^^^']))
797
798 def test_crush_rule_rm(self):
799 self.assert_valid_command(['osd', 'crush', 'rule', 'rm', 'AZaz09-_.'])
800 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
801 'rule', 'rm']))
802 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
803 'rule', 'rm',
804 '^^^^']))
805 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
806 'rule', 'rm',
807 'AZaz09-_.',
808 'toomany']))
809
810 def test_setmaxosd(self):
811 self.check_1_natural_arg('osd', 'setmaxosd')
812
813 def test_pause(self):
814 self.check_no_arg('osd', 'pause')
815
816 def test_unpause(self):
817 self.check_no_arg('osd', 'unpause')
818
819 def test_erasure_code_profile_set(self):
820 self.assert_valid_command(['osd', 'erasure-code-profile', 'set',
821 'name'])
822 self.assert_valid_command(['osd', 'erasure-code-profile', 'set',
823 'name', 'A=B'])
824 self.assert_valid_command(['osd', 'erasure-code-profile', 'set',
825 'name', 'A=B', 'C=D'])
826 assert_equal({}, validate_command(sigdict, ['osd',
827 'erasure-code-profile',
828 'set']))
829 assert_equal({}, validate_command(sigdict, ['osd',
830 'erasure-code-profile',
831 'set',
832 '^^^^']))
833
834 def test_erasure_code_profile_get(self):
835 self.assert_valid_command(['osd', 'erasure-code-profile', 'get',
836 'name'])
837 assert_equal({}, validate_command(sigdict, ['osd',
838 'erasure-code-profile',
839 'get']))
840 assert_equal({}, validate_command(sigdict, ['osd',
841 'erasure-code-profile',
842 'get',
843 '^^^^']))
844
845 def test_erasure_code_profile_rm(self):
846 self.assert_valid_command(['osd', 'erasure-code-profile', 'rm',
847 'name'])
848 assert_equal({}, validate_command(sigdict, ['osd',
849 'erasure-code-profile',
850 'rm']))
851 assert_equal({}, validate_command(sigdict, ['osd',
852 'erasure-code-profile',
853 'rm',
854 '^^^^']))
855
856 def test_erasure_code_profile_ls(self):
857 self.assert_valid_command(['osd', 'erasure-code-profile', 'ls'])
858 assert_equal({}, validate_command(sigdict, ['osd',
859 'erasure-code-profile',
860 'ls',
861 'toomany']))
862
863 def test_set_unset(self):
864 for action in ('set', 'unset'):
865 for flag in ('pause', 'noup', 'nodown', 'noout', 'noin',
866 'nobackfill', 'norecover', 'noscrub', 'nodeep-scrub'):
867 self.assert_valid_command(['osd', action, flag])
868 assert_equal({}, validate_command(sigdict, ['osd', action]))
869 assert_equal({}, validate_command(sigdict, ['osd', action,
870 'invalid']))
871 assert_equal({}, validate_command(sigdict, ['osd', action,
872 'pause', 'toomany']))
873
874 def test_cluster_snap(self):
875 assert_equal(None, validate_command(sigdict, ['osd', 'cluster_snap']))
876
877 def test_down(self):
878 self.check_1_or_more_string_args('osd', 'down')
879
880 def test_out(self):
881 self.check_1_or_more_string_args('osd', 'out')
882
883 def test_in(self):
884 self.check_1_or_more_string_args('osd', 'in')
885
886 def test_rm(self):
887 self.check_1_or_more_string_args('osd', 'rm')
888
889 def test_reweight(self):
890 self.assert_valid_command(['osd', 'reweight', '1', '0.1'])
891 assert_equal({}, validate_command(sigdict, ['osd', 'reweight']))
892 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
893 '1']))
894 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
895 '1', '2.0']))
896 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
897 '-1', '0.1']))
898 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
899 '1', '0.1',
900 'toomany']))
901
902 def test_lost(self):
903 self.assert_valid_command(['osd', 'lost', '1',
904 '--yes-i-really-mean-it'])
905 self.assert_valid_command(['osd', 'lost', '1'])
906 assert_equal({}, validate_command(sigdict, ['osd', 'lost']))
907 assert_equal({}, validate_command(sigdict, ['osd', 'lost',
908 '1',
909 'what?']))
910 assert_equal({}, validate_command(sigdict, ['osd', 'lost',
911 '-1',
912 '--yes-i-really-mean-it']))
913 assert_equal({}, validate_command(sigdict, ['osd', 'lost',
914 '1',
915 '--yes-i-really-mean-it',
916 'toomany']))
917
918 def test_create(self):
919 uuid = '12345678123456781234567812345678'
920 self.assert_valid_command(['osd', 'create'])
921 self.assert_valid_command(['osd', 'create',
922 uuid])
923 assert_equal({}, validate_command(sigdict, ['osd', 'create',
924 'invalid']))
925 assert_equal({}, validate_command(sigdict, ['osd', 'create',
926 uuid,
927 'toomany']))
928
929 def test_blacklist(self):
930 for action in ('add', 'rm'):
931 self.assert_valid_command(['osd', 'blacklist', action,
932 '1.2.3.4/567'])
933 self.assert_valid_command(['osd', 'blacklist', action,
934 '1.2.3.4'])
935 self.assert_valid_command(['osd', 'blacklist', action,
936 '1.2.3.4/567', '600.40'])
937 self.assert_valid_command(['osd', 'blacklist', action,
938 '1.2.3.4', '600.40'])
939 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
940 action,
941 'invalid',
942 '600.40']))
943 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
944 action,
945 '1.2.3.4/567',
946 '-1.0']))
947 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
948 action,
949 '1.2.3.4/567',
950 '600.40',
951 'toomany']))
952
953 def test_pool_mksnap(self):
954 self.assert_valid_command(['osd', 'pool', 'mksnap',
955 'poolname', 'snapname'])
956 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'mksnap']))
957 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'mksnap',
958 'poolname']))
959 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'mksnap',
960 'poolname', 'snapname',
961 'toomany']))
962
963 def test_pool_rmsnap(self):
964 self.assert_valid_command(['osd', 'pool', 'rmsnap',
965 'poolname', 'snapname'])
966 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rmsnap']))
967 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rmsnap',
968 'poolname']))
969 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rmsnap',
970 'poolname', 'snapname',
971 'toomany']))
972
973 def test_pool_create(self):
974 self.assert_valid_command(['osd', 'pool', 'create',
975 'poolname', '128'])
976 self.assert_valid_command(['osd', 'pool', 'create',
977 'poolname', '128', '128'])
978 self.assert_valid_command(['osd', 'pool', 'create',
979 'poolname', '128', '128',
980 'replicated'])
981 self.assert_valid_command(['osd', 'pool', 'create',
982 'poolname', '128', '128',
983 'erasure', 'A-Za-z0-9-_.', 'ruleset^^'])
984 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create']))
985 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
986 'poolname']))
987 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
988 'poolname', '-1']))
989 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
990 'poolname',
991 '128', '128',
992 'erasure', '^^^',
993 'ruleset']))
994 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
995 'poolname',
996 '128', '128',
997 'erasure', 'profile',
998 'ruleset',
999 'toomany']))
1000 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
1001 'poolname',
1002 '128', '128',
1003 'INVALID', 'profile',
1004 'ruleset']))
1005
1006 def test_pool_delete(self):
1007 self.assert_valid_command(['osd', 'pool', 'delete',
1008 'poolname', 'poolname',
1009 '--yes-i-really-really-mean-it'])
1010 self.assert_valid_command(['osd', 'pool', 'delete',
1011 'poolname', 'poolname'])
1012 self.assert_valid_command(['osd', 'pool', 'delete',
1013 'poolname'])
1014 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'delete']))
7c673cae
FG
1015 assert_equal({}, validate_command(sigdict,
1016 ['osd', 'pool', 'delete',
1017 'poolname', 'poolname',
1018 '--yes-i-really-really-mean-it',
1019 'toomany']))
1020
1021 def test_pool_rename(self):
1022 self.assert_valid_command(['osd', 'pool', 'rename',
1023 'poolname', 'othername'])
1024 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename']))
1025 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename',
1026 'poolname']))
1027 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename',
1028 'poolname', 'othername',
1029 'toomany']))
1030
1031 def test_pool_get(self):
1032 for var in ('size', 'min_size', 'crash_replay_interval',
31f18b77 1033 'pg_num', 'pgp_num', 'crush_rule', 'auid', 'fast_read',
7c673cae
FG
1034 'scrub_min_interval', 'scrub_max_interval',
1035 'deep_scrub_interval', 'recovery_priority',
1036 'recovery_op_priority'):
1037 self.assert_valid_command(['osd', 'pool', 'get', 'poolname', var])
1038 assert_equal({}, validate_command(sigdict, ['osd', 'pool']))
1039 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1040 'get']))
1041 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1042 'get', 'poolname']))
1043 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1044 'get', 'poolname',
1045 'size', 'toomany']))
1046 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1047 'get', 'poolname',
1048 'invalid']))
1049
1050 def test_pool_set(self):
1051 for var in ('size', 'min_size', 'crash_replay_interval',
31f18b77 1052 'pg_num', 'pgp_num', 'crush_rule',
7c673cae
FG
1053 'hashpspool', 'auid', 'fast_read',
1054 'scrub_min_interval', 'scrub_max_interval',
1055 'deep_scrub_interval', 'recovery_priority',
1056 'recovery_op_priority'):
1057 self.assert_valid_command(['osd', 'pool',
1058 'set', 'poolname', var, 'value'])
1059 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1060 'set']))
1061 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1062 'set', 'poolname']))
1063 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1064 'set', 'poolname',
1065 'size', 'value',
1066 'toomany']))
1067
1068 def test_pool_set_quota(self):
1069 for field in ('max_objects', 'max_bytes'):
1070 self.assert_valid_command(['osd', 'pool', 'set-quota',
1071 'poolname', field, '10K'])
1072 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1073 'set-quota']))
1074 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1075 'set-quota',
1076 'poolname']))
1077 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1078 'set-quota',
1079 'poolname',
1080 'max_objects']))
1081 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1082 'set-quota',
1083 'poolname',
1084 'invalid',
1085 '10K']))
1086 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1087 'set-quota',
1088 'poolname',
1089 'max_objects',
1090 '10K',
1091 'toomany']))
1092
1093 def test_reweight_by_utilization(self):
1094 self.assert_valid_command(['osd', 'reweight-by-utilization'])
1095 self.assert_valid_command(['osd', 'reweight-by-utilization', '100'])
1096 self.assert_valid_command(['osd', 'reweight-by-utilization', '100', '.1'])
1097 self.assert_valid_command(['osd', 'reweight-by-utilization', '--no-increasing'])
1098 assert_equal({}, validate_command(sigdict, ['osd',
1099 'reweight-by-utilization',
1100 '100',
1101 'toomany']))
1102
1103 def test_tier_op(self):
1104 for op in ('add', 'remove', 'set-overlay'):
1105 self.assert_valid_command(['osd', 'tier', op,
1106 'poolname', 'othername'])
1107 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op]))
1108 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op,
1109 'poolname']))
1110 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op,
1111 'poolname',
1112 'othername',
1113 'toomany']))
1114
1115 def test_tier_cache_mode(self):
1116 for mode in ('none', 'writeback', 'forward', 'readonly', 'readforward', 'readproxy'):
1117 self.assert_valid_command(['osd', 'tier', 'cache-mode',
1118 'poolname', mode])
1119 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1120 'cache-mode']))
1121 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1122 'cache-mode',
1123 'invalid']))
1124
1125 def test_tier_remove_overlay(self):
1126 self.assert_valid_command(['osd', 'tier', 'remove-overlay',
1127 'poolname'])
1128 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1129 'remove-overlay']))
1130 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1131 'remove-overlay',
1132 'poolname',
1133 'toomany']))
1134
1135 def set_ratio(self, command):
1136 self.assert_valid_command(['osd',
1137 command,
1138 '0.0'])
1139 assert_equal({}, validate_command(sigdict, ['osd', command]))
1140 assert_equal({}, validate_command(sigdict, ['osd',
1141 command,
1142 '2.0']))
1143
1144 def test_set_full_ratio(self):
1145 self.set_ratio('set-full-ratio')
1146
1147 def test_set_backfillfull_ratio(self):
1148 self.set_ratio('set-backfillfull-ratio')
1149
1150 def test_set_nearfull_ratio(self):
1151 self.set_ratio('set-nearfull-ratio')
1152
1153
1154class TestConfigKey(TestArgparse):
1155
1156 def test_get(self):
1157 self.check_1_string_arg('config-key', 'get')
1158
1159 def test_put(self):
1160 self.assert_valid_command(['config-key', 'put',
1161 'key'])
1162 self.assert_valid_command(['config-key', 'put',
1163 'key', 'value'])
1164 assert_equal({}, validate_command(sigdict, ['config-key', 'put']))
1165 assert_equal({}, validate_command(sigdict, ['config-key', 'put',
1166 'key', 'value',
1167 'toomany']))
1168
1169 def test_del(self):
1170 self.check_1_string_arg('config-key', 'del')
1171
1172 def test_exists(self):
1173 self.check_1_string_arg('config-key', 'exists')
1174
1175 def test_dump(self):
1176 self.check_no_arg('config-key', 'dump')
1177
1178 def test_list(self):
1179 self.check_no_arg('config-key', 'list')
1180# Local Variables:
1181# compile-command: "cd ../.. ; make -j4 &&
1182# PYTHONPATH=pybind nosetests --stop \
1183# test/pybind/test_ceph_argparse.py # test_ceph_argparse.py:TestOSD.test_rm"
1184# End: