]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/pybind/test_ceph_argparse.py
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
5 # Ceph - scalable distributed file system
7 # Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 # Copyright (C) 2014 Red Hat <contact@redhat.com>
10 # Author: Loic Dachary <loic@dachary.org>
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.
18 from nose
.tools
import eq_
as eq
19 from nose
.tools
import *
21 from ceph_argparse
import validate_command
, parse_json_funcsigs
27 def get_command_descriptions(what
):
28 CEPH_BIN
= os
.environ
['CEPH_BIN']
31 return os
.popen(CEPH_BIN
+ "/get_command_descriptions " + "--" + what
).read()
33 def test_parse_json_funcsigs():
34 commands
= get_command_descriptions("all")
35 cmd_json
= parse_json_funcsigs(commands
, 'cli')
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')
41 sigdict
= parse_json_funcsigs(get_command_descriptions("all"), 'cli')
46 def assert_valid_command(self
, args
):
47 result
= validate_command(sigdict
, args
)
48 assert_not_equal(result
,None)
49 assert_not_equal(result
,{})
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',
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',
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
,
73 def check_1_or_more_string_args(self
, prefix
, command
):
74 assert_equal({}, validate_command(sigdict
, [prefix
,
76 self
.assert_valid_command([prefix
,
79 self
.assert_valid_command([prefix
,
84 def check_no_arg(self
, prefix
, command
):
85 self
.assert_valid_command([prefix
,
87 assert_equal({}, validate_command(sigdict
, [prefix
,
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
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
103 assert_is_none(validate_command(sigdict
, ['章鱼和鱿鱼']))
104 assert_is_none(validate_command(sigdict
, ['–w']))
107 class TestPG(TestArgparse
):
110 self
.assert_valid_command(['pg', 'stat'])
112 def test_getmap(self
):
113 self
.assert_valid_command(['pg', 'getmap'])
116 self
.assert_valid_command(['pg', 'dump'])
117 self
.assert_valid_command(['pg', 'dump',
126 assert_equal({}, validate_command(sigdict
, ['pg', 'dump', 'invalid']))
128 def test_dump_json(self
):
129 self
.assert_valid_command(['pg', 'dump_json'])
130 self
.assert_valid_command(['pg', 'dump_json',
137 assert_equal({}, validate_command(sigdict
, ['pg', 'dump_json',
140 def test_dump_pools_json(self
):
141 self
.assert_valid_command(['pg', 'dump_pools_json'])
143 def test_dump_pools_stuck(self
):
144 self
.assert_valid_command(['pg', 'dump_stuck'])
145 self
.assert_valid_command(['pg', 'dump_stuck',
149 assert_equal({}, validate_command(sigdict
, ['pg', 'dump_stuck',
151 self
.assert_valid_command(['pg', 'dump_stuck',
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']))
163 def test_scrub(self
):
164 self
.one_pgid('scrub')
166 def test_deep_scrub(self
):
167 self
.one_pgid('deep-scrub')
169 def test_repair(self
):
170 self
.one_pgid('repair')
172 def test_debug(self
):
173 self
.assert_valid_command(['pg',
175 'unfound_objects_exist'])
176 self
.assert_valid_command(['pg',
178 'degraded_pgs_exist'])
179 assert_equal({}, validate_command(sigdict
, ['pg', 'debug']))
180 assert_equal({}, validate_command(sigdict
, ['pg', 'debug',
183 def test_force_create_pg(self
):
184 self
.one_pgid('force_create_pg')
187 class TestAuth(TestArgparse
):
189 def test_export(self
):
190 self
.assert_valid_command(['auth', 'export'])
191 self
.assert_valid_command(['auth',
194 assert_equal({}, validate_command(sigdict
, ['auth',
200 self
.check_1_string_arg('auth', 'get')
202 def test_get_key(self
):
203 self
.check_1_string_arg('auth', 'get-key')
205 def test_print_key(self
):
206 self
.check_1_string_arg('auth', 'print-key')
207 self
.check_1_string_arg('auth', 'print_key')
210 self
.check_no_arg('auth', 'list')
212 def test_import(self
):
213 self
.check_no_arg('auth', 'import')
216 self
.check_1_or_more_string_args('auth', 'add')
218 def test_get_or_create_key(self
):
219 self
.check_1_or_more_string_args('auth', 'get-or-create-key')
221 def test_get_or_create(self
):
222 self
.check_1_or_more_string_args('auth', 'get-or-create')
225 assert_equal({}, validate_command(sigdict
, ['auth',
227 assert_equal({}, validate_command(sigdict
, ['auth',
230 self
.assert_valid_command(['auth',
236 self
.check_1_string_arg('auth', 'del')
239 class TestMonitor(TestArgparse
):
241 def test_compact(self
):
242 self
.assert_valid_command(['compact'])
244 def test_scrub(self
):
245 self
.assert_valid_command(['scrub'])
248 self
.assert_valid_command(['fsid'])
251 assert_equal({}, validate_command(sigdict
, ['log']))
252 self
.assert_valid_command(['log', 'a logtext'])
253 self
.assert_valid_command(['log', 'a logtext', 'and another'])
255 def test_injectargs(self
):
256 assert_equal({}, validate_command(sigdict
, ['injectargs']))
257 self
.assert_valid_command(['injectargs', 'one'])
258 self
.assert_valid_command(['injectargs', 'one', 'two'])
260 def test_status(self
):
261 self
.assert_valid_command(['status'])
263 def test_health(self
):
264 self
.assert_valid_command(['health'])
265 self
.assert_valid_command(['health', 'detail'])
266 assert_equal({}, validate_command(sigdict
, ['health', 'invalid']))
267 assert_equal({}, validate_command(sigdict
, ['health', 'detail',
271 self
.assert_valid_command(['df'])
272 self
.assert_valid_command(['df', 'detail'])
273 assert_equal({}, validate_command(sigdict
, ['df', 'invalid']))
274 assert_equal({}, validate_command(sigdict
, ['df', 'detail',
277 def test_report(self
):
278 self
.assert_valid_command(['report'])
279 self
.assert_valid_command(['report', 'tag1'])
280 self
.assert_valid_command(['report', 'tag1', 'tag2'])
282 def test_quorum_status(self
):
283 self
.assert_valid_command(['quorum_status'])
285 def test_mon_status(self
):
286 self
.assert_valid_command(['mon_status'])
288 def test_sync_force(self
):
289 self
.assert_valid_command(['sync',
291 '--yes-i-really-mean-it',
292 '--i-know-what-i-am-doing'])
293 self
.assert_valid_command(['sync',
295 '--yes-i-really-mean-it'])
296 self
.assert_valid_command(['sync',
298 assert_equal({}, validate_command(sigdict
, ['sync']))
299 assert_equal({}, validate_command(sigdict
, ['sync',
301 '--yes-i-really-mean-it',
302 '--i-know-what-i-am-doing',
306 assert_equal({}, validate_command(sigdict
, ['heap']))
307 assert_equal({}, validate_command(sigdict
, ['heap', 'invalid']))
308 self
.assert_valid_command(['heap', 'dump'])
309 self
.assert_valid_command(['heap', 'start_profiler'])
310 self
.assert_valid_command(['heap', 'stop_profiler'])
311 self
.assert_valid_command(['heap', 'release'])
312 self
.assert_valid_command(['heap', 'stats'])
314 def test_quorum(self
):
315 assert_equal({}, validate_command(sigdict
, ['quorum']))
316 assert_equal({}, validate_command(sigdict
, ['quorum', 'invalid']))
317 self
.assert_valid_command(['quorum', 'enter'])
318 self
.assert_valid_command(['quorum', 'exit'])
319 assert_equal({}, validate_command(sigdict
, ['quorum',
324 assert_equal({}, validate_command(sigdict
, ['tell']))
325 assert_equal({}, validate_command(sigdict
, ['tell', 'invalid']))
326 for name
in ('osd', 'mon', 'client', 'mds'):
327 assert_equal({}, validate_command(sigdict
, ['tell', name
]))
328 assert_equal({}, validate_command(sigdict
, ['tell',
330 self
.assert_valid_command(['tell', name
+ ".42", 'something'])
331 self
.assert_valid_command(['tell', name
+ ".42",
336 class TestMDS(TestArgparse
):
339 self
.check_no_arg('mds', 'stat')
342 self
.check_0_or_1_natural_arg('mds', 'dump')
345 self
.assert_valid_command(['mds', 'tell',
348 self
.assert_valid_command(['mds', 'tell',
352 assert_equal({}, validate_command(sigdict
, ['mds', 'tell']))
353 assert_equal({}, validate_command(sigdict
, ['mds', 'tell',
356 def test_compat_show(self
):
357 self
.assert_valid_command(['mds', 'compat', 'show'])
358 assert_equal({}, validate_command(sigdict
, ['mds', 'compat']))
359 assert_equal({}, validate_command(sigdict
, ['mds', 'compat',
363 self
.assert_valid_command(['mds', 'stop', 'someone'])
364 assert_equal({}, validate_command(sigdict
, ['mds', 'stop']))
365 assert_equal({}, validate_command(sigdict
, ['mds', 'stop',
366 'someone', 'toomany']))
368 def test_deactivate(self
):
369 self
.assert_valid_command(['mds', 'deactivate', 'someone'])
370 assert_equal({}, validate_command(sigdict
, ['mds', 'deactivate']))
371 assert_equal({}, validate_command(sigdict
, ['mds', 'deactivate',
372 'someone', 'toomany']))
374 def test_set_max_mds(self
):
375 self
.check_1_natural_arg('mds', 'set_max_mds')
377 def test_set_state(self
):
378 self
.assert_valid_command(['mds', 'set_state', '1', '2'])
379 assert_equal({}, validate_command(sigdict
, ['mds', 'set_state']))
380 assert_equal({}, validate_command(sigdict
, ['mds', 'set_state', '-1']))
381 assert_equal({}, validate_command(sigdict
, ['mds', 'set_state',
383 assert_equal({}, validate_command(sigdict
, ['mds', 'set_state',
387 self
.check_1_string_arg('mds', 'fail')
390 # Valid: single GID argument present
391 self
.assert_valid_command(['mds', 'rm', '1'])
393 # Missing GID arg: invalid
394 assert_equal({}, validate_command(sigdict
, ['mds', 'rm']))
396 assert_equal({}, validate_command(sigdict
, ['mds', 'rm', '1', 'mds.42']))
398 def test_rmfailed(self
):
399 self
.assert_valid_command(['mds', 'rmfailed', '0'])
400 self
.assert_valid_command(['mds', 'rmfailed', '0', '--yes-i-really-mean-it'])
401 assert_equal({}, validate_command(sigdict
, ['mds', 'rmfailed', '0',
402 '--yes-i-really-mean-it',
405 def test_cluster_down(self
):
406 self
.check_no_arg('mds', 'cluster_down')
408 def test_cluster_up(self
):
409 self
.check_no_arg('mds', 'cluster_up')
411 def test_compat_rm_compat(self
):
412 self
.assert_valid_command(['mds', 'compat', 'rm_compat', '1'])
413 assert_equal({}, validate_command(sigdict
, ['mds',
416 assert_equal({}, validate_command(sigdict
, ['mds',
419 assert_equal({}, validate_command(sigdict
, ['mds',
421 'rm_compat', '1', '1']))
423 def test_incompat_rm_incompat(self
):
424 self
.assert_valid_command(['mds', 'compat', 'rm_incompat', '1'])
425 assert_equal({}, validate_command(sigdict
, ['mds',
428 assert_equal({}, validate_command(sigdict
, ['mds',
430 'rm_incompat', '-1']))
431 assert_equal({}, validate_command(sigdict
, ['mds',
433 'rm_incompat', '1', '1']))
435 def test_mds_set(self
):
436 self
.assert_valid_command(['mds', 'set', 'max_mds', '2'])
437 self
.assert_valid_command(['mds', 'set', 'max_file_size', '2'])
438 self
.assert_valid_command(['mds', 'set', 'allow_new_snaps', 'no'])
439 assert_equal({}, validate_command(sigdict
, ['mds',
443 def test_add_data_pool(self
):
444 self
.assert_valid_command(['mds', 'add_data_pool', '1'])
445 self
.assert_valid_command(['mds', 'add_data_pool', 'foo'])
447 def test_remove_data_pool(self
):
448 self
.assert_valid_command(['mds', 'remove_data_pool', '1'])
449 self
.assert_valid_command(['mds', 'remove_data_pool', 'foo'])
451 def test_newfs(self
):
452 self
.assert_valid_command(['mds', 'newfs', '1', '2',
453 '--yes-i-really-mean-it'])
454 self
.assert_valid_command(['mds', 'newfs', '1', '2'])
455 assert_equal({}, validate_command(sigdict
, ['mds', 'newfs']))
456 assert_equal({}, validate_command(sigdict
, ['mds', 'newfs', '1']))
457 assert_equal({}, validate_command(sigdict
, ['mds',
461 '--yes-i-really-mean-it',
463 assert_equal({}, validate_command(sigdict
, ['mds',
467 '--yes-i-really-mean-it']))
468 assert_equal({}, validate_command(sigdict
, ['mds',
472 '--yes-i-really-mean-it']))
475 class TestFS(TestArgparse
):
478 self
.check_0_or_1_natural_arg('fs', 'dump')
480 def test_fs_new(self
):
481 self
.assert_valid_command(['fs', 'new', 'default', 'metadata', 'data'])
483 def test_fs_rm(self
):
484 self
.assert_valid_command(['fs', 'rm', 'default'])
485 self
.assert_valid_command(['fs', 'rm', 'default', '--yes-i-really-mean-it'])
486 assert_equal({}, validate_command(sigdict
, ['fs', 'rm', 'default', '--yes-i-really-mean-it', 'toomany']))
488 def test_fs_ls(self
):
489 self
.assert_valid_command(['fs', 'ls'])
490 assert_equal({}, validate_command(sigdict
, ['fs', 'ls', 'toomany']))
492 def test_fs_set_default(self
):
493 self
.assert_valid_command(['fs', 'set-default', 'cephfs'])
494 assert_equal({}, validate_command(sigdict
, ['fs', 'set-default']))
495 assert_equal({}, validate_command(sigdict
, ['fs', 'set-default', 'cephfs', 'toomany']))
497 class TestMon(TestArgparse
):
500 self
.check_0_or_1_natural_arg('mon', 'dump')
503 self
.check_no_arg('mon', 'stat')
505 def test_getmap(self
):
506 self
.check_0_or_1_natural_arg('mon', 'getmap')
509 self
.assert_valid_command(['mon', 'add', 'name', '1.2.3.4:1234'])
510 assert_equal({}, validate_command(sigdict
, ['mon', 'add']))
511 assert_equal({}, validate_command(sigdict
, ['mon', 'add', 'name']))
512 assert_equal({}, validate_command(sigdict
, ['mon', 'add',
515 assert_equal({}, validate_command(sigdict
, ['mon', 'add', 'name',
519 def test_remove(self
):
520 self
.assert_valid_command(['mon', 'remove', 'name'])
521 assert_equal({}, validate_command(sigdict
, ['mon', 'remove']))
522 assert_equal({}, validate_command(sigdict
, ['mon', 'remove',
526 class TestOSD(TestArgparse
):
529 self
.check_no_arg('osd', 'stat')
532 self
.check_0_or_1_natural_arg('osd', 'dump')
534 def test_osd_tree(self
):
535 self
.check_0_or_1_natural_arg('osd', 'tree')
537 def test_osd_ls(self
):
538 self
.check_0_or_1_natural_arg('osd', 'ls')
540 def test_osd_getmap(self
):
541 self
.check_0_or_1_natural_arg('osd', 'getmap')
543 def test_osd_getcrushmap(self
):
544 self
.check_0_or_1_natural_arg('osd', 'getcrushmap')
547 self
.check_no_arg('osd', 'perf')
549 def test_getmaxosd(self
):
550 self
.check_no_arg('osd', 'getmaxosd')
553 self
.check_1_natural_arg('osd', 'find')
556 self
.assert_valid_command(['osd', 'map', 'poolname', 'objectname'])
557 self
.assert_valid_command(['osd', 'map', 'poolname', 'objectname', 'nspace'])
558 assert_equal({}, validate_command(sigdict
, ['osd', 'map']))
559 assert_equal({}, validate_command(sigdict
, ['osd', 'map', 'poolname']))
560 assert_equal({}, validate_command(sigdict
, ['osd', 'map',
561 'poolname', 'objectname', 'nspace',
564 def test_metadata(self
):
565 self
.check_0_or_1_natural_arg('osd', 'metadata')
567 def test_scrub(self
):
568 self
.check_1_string_arg('osd', 'scrub')
570 def test_deep_scrub(self
):
571 self
.check_1_string_arg('osd', 'deep-scrub')
573 def test_repair(self
):
574 self
.check_1_string_arg('osd', 'repair')
576 def test_lspools(self
):
577 self
.assert_valid_command(['osd', 'lspools'])
578 self
.assert_valid_command(['osd', 'lspools', '1'])
579 self
.assert_valid_command(['osd', 'lspools', '-1'])
580 assert_equal({}, validate_command(sigdict
, ['osd', 'lspools',
583 def test_blacklist_ls(self
):
584 self
.assert_valid_command(['osd', 'blacklist', 'ls'])
585 assert_equal({}, validate_command(sigdict
, ['osd', 'blacklist']))
586 assert_equal({}, validate_command(sigdict
, ['osd', 'blacklist',
589 def test_crush_rule(self
):
590 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
591 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule']))
592 for subcommand
in ('list', 'ls'):
593 self
.assert_valid_command(['osd', 'crush', 'rule', subcommand
])
594 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
598 def test_crush_rule_dump(self
):
599 self
.assert_valid_command(['osd', 'crush', 'rule', 'dump'])
600 self
.assert_valid_command(['osd', 'crush', 'rule', 'dump', 'RULE'])
601 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
606 def test_crush_dump(self
):
607 self
.assert_valid_command(['osd', 'crush', 'dump'])
608 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
609 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
613 def test_setcrushmap(self
):
614 self
.check_no_arg('osd', 'setcrushmap')
616 def test_crush_add_bucket(self
):
617 self
.assert_valid_command(['osd', 'crush', 'add-bucket',
619 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
620 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
622 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
623 'add-bucket', 'name',
626 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
630 def test_crush_rename_bucket(self
):
631 self
.assert_valid_command(['osd', 'crush', 'rename-bucket',
632 'srcname', 'dstname'])
633 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
634 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
636 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
639 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
640 'rename-bucket', 'srcname',
643 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
644 'rename-bucket', '^^^',
646 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
647 'rename-bucket', 'srcname',
650 def check_crush_setter(self
, setter
):
651 self
.assert_valid_command(['osd', 'crush', setter
,
652 '*', '2.3', 'AZaz09-_.='])
653 self
.assert_valid_command(['osd', 'crush', setter
,
654 'osd.0', '2.3', 'AZaz09-_.='])
655 self
.assert_valid_command(['osd', 'crush', setter
,
656 '0', '2.3', 'AZaz09-_.='])
657 self
.assert_valid_command(['osd', 'crush', setter
,
658 '0', '2.3', 'AZaz09-_.=', 'AZaz09-_.='])
659 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
662 ret
= validate_command(sigdict
, ['osd', 'crush',
666 assert ret
in [None, {}]
667 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
673 def test_crush_set(self
):
674 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
675 self
.check_crush_setter('set')
677 def test_crush_add(self
):
678 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
679 self
.check_crush_setter('add')
681 def test_crush_create_or_move(self
):
682 assert_equal({}, validate_command(sigdict
, ['osd', 'crush']))
683 self
.check_crush_setter('create-or-move')
685 def test_crush_move(self
):
686 self
.assert_valid_command(['osd', 'crush', 'move',
687 'AZaz09-_.', 'AZaz09-_.='])
688 self
.assert_valid_command(['osd', 'crush', 'move',
689 '0', 'AZaz09-_.=', 'AZaz09-_.='])
690 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
692 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
693 'move', 'AZaz09-_.']))
694 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
697 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
701 def test_crush_link(self
):
702 self
.assert_valid_command(['osd', 'crush', 'link',
703 'name', 'AZaz09-_.='])
704 self
.assert_valid_command(['osd', 'crush', 'link',
705 'name', 'AZaz09-_.=', 'AZaz09-_.='])
706 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
708 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
712 def test_crush_rm(self
):
713 for alias
in ('rm', 'remove', 'unlink'):
714 self
.assert_valid_command(['osd', 'crush', alias
, 'AZaz09-_.'])
715 self
.assert_valid_command(['osd', 'crush', alias
,
716 'AZaz09-_.', 'AZaz09-_.'])
717 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
719 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
725 def test_crush_reweight(self
):
726 self
.assert_valid_command(['osd', 'crush', 'reweight',
728 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
730 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
733 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
737 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
742 def test_crush_tunables(self
):
743 for tunable
in ('legacy', 'argonaut', 'bobtail', 'firefly',
744 'optimal', 'default'):
745 self
.assert_valid_command(['osd', 'crush', 'tunables',
747 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
749 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
751 'default', 'toomany']))
753 def test_crush_rule_create_simple(self
):
754 self
.assert_valid_command(['osd', 'crush', 'rule', 'create-simple',
755 'AZaz09-_.', 'AZaz09-_.', 'AZaz09-_.'])
756 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
758 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
761 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
765 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
770 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
775 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
780 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
787 def test_crush_rule_create_erasure(self
):
788 self
.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
790 self
.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
791 'AZaz09-_.', 'whatever'])
792 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
794 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
797 assert_equal({}, validate_command(sigdict
, ['osd', 'crush', 'rule',
801 def test_crush_rule_rm(self
):
802 self
.assert_valid_command(['osd', 'crush', 'rule', 'rm', 'AZaz09-_.'])
803 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
805 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
808 assert_equal({}, validate_command(sigdict
, ['osd', 'crush',
813 def test_setmaxosd(self
):
814 self
.check_1_natural_arg('osd', 'setmaxosd')
816 def test_pause(self
):
817 self
.check_no_arg('osd', 'pause')
819 def test_unpause(self
):
820 self
.check_no_arg('osd', 'unpause')
822 def test_erasure_code_profile_set(self
):
823 self
.assert_valid_command(['osd', 'erasure-code-profile', 'set',
825 self
.assert_valid_command(['osd', 'erasure-code-profile', 'set',
827 self
.assert_valid_command(['osd', 'erasure-code-profile', 'set',
828 'name', 'A=B', 'C=D'])
829 assert_equal({}, validate_command(sigdict
, ['osd',
830 'erasure-code-profile',
832 assert_equal({}, validate_command(sigdict
, ['osd',
833 'erasure-code-profile',
837 def test_erasure_code_profile_get(self
):
838 self
.assert_valid_command(['osd', 'erasure-code-profile', 'get',
840 assert_equal({}, validate_command(sigdict
, ['osd',
841 'erasure-code-profile',
843 assert_equal({}, validate_command(sigdict
, ['osd',
844 'erasure-code-profile',
848 def test_erasure_code_profile_rm(self
):
849 self
.assert_valid_command(['osd', 'erasure-code-profile', 'rm',
851 assert_equal({}, validate_command(sigdict
, ['osd',
852 'erasure-code-profile',
854 assert_equal({}, validate_command(sigdict
, ['osd',
855 'erasure-code-profile',
859 def test_erasure_code_profile_ls(self
):
860 self
.assert_valid_command(['osd', 'erasure-code-profile', 'ls'])
861 assert_equal({}, validate_command(sigdict
, ['osd',
862 'erasure-code-profile',
866 def test_set_unset(self
):
867 for action
in ('set', 'unset'):
868 for flag
in ('pause', 'noup', 'nodown', 'noout', 'noin',
869 'nobackfill', 'norecover', 'noscrub', 'nodeep-scrub'):
870 self
.assert_valid_command(['osd', action
, flag
])
871 assert_equal({}, validate_command(sigdict
, ['osd', action
]))
872 assert_equal({}, validate_command(sigdict
, ['osd', action
,
874 assert_equal({}, validate_command(sigdict
, ['osd', action
,
875 'pause', 'toomany']))
877 def test_cluster_snap(self
):
878 assert_equal(None, validate_command(sigdict
, ['osd', 'cluster_snap']))
881 self
.check_1_or_more_string_args('osd', 'down')
884 self
.check_1_or_more_string_args('osd', 'out')
887 self
.check_1_or_more_string_args('osd', 'in')
890 self
.check_1_or_more_string_args('osd', 'rm')
892 def test_reweight(self
):
893 self
.assert_valid_command(['osd', 'reweight', '1', '0.1'])
894 assert_equal({}, validate_command(sigdict
, ['osd', 'reweight']))
895 assert_equal({}, validate_command(sigdict
, ['osd', 'reweight',
897 assert_equal({}, validate_command(sigdict
, ['osd', 'reweight',
899 assert_equal({}, validate_command(sigdict
, ['osd', 'reweight',
901 assert_equal({}, validate_command(sigdict
, ['osd', 'reweight',
906 self
.assert_valid_command(['osd', 'lost', '1',
907 '--yes-i-really-mean-it'])
908 self
.assert_valid_command(['osd', 'lost', '1'])
909 assert_equal({}, validate_command(sigdict
, ['osd', 'lost']))
910 assert_equal({}, validate_command(sigdict
, ['osd', 'lost',
913 assert_equal({}, validate_command(sigdict
, ['osd', 'lost',
915 '--yes-i-really-mean-it']))
916 assert_equal({}, validate_command(sigdict
, ['osd', 'lost',
918 '--yes-i-really-mean-it',
921 def test_create(self
):
922 uuid
= '12345678123456781234567812345678'
923 self
.assert_valid_command(['osd', 'create'])
924 self
.assert_valid_command(['osd', 'create',
926 assert_equal({}, validate_command(sigdict
, ['osd', 'create',
928 assert_equal({}, validate_command(sigdict
, ['osd', 'create',
932 def test_blacklist(self
):
933 for action
in ('add', 'rm'):
934 self
.assert_valid_command(['osd', 'blacklist', action
,
936 self
.assert_valid_command(['osd', 'blacklist', action
,
938 self
.assert_valid_command(['osd', 'blacklist', action
,
939 '1.2.3.4/567', '600.40'])
940 self
.assert_valid_command(['osd', 'blacklist', action
,
941 '1.2.3.4', '600.40'])
942 assert_equal({}, validate_command(sigdict
, ['osd', 'blacklist',
946 assert_equal({}, validate_command(sigdict
, ['osd', 'blacklist',
950 assert_equal({}, validate_command(sigdict
, ['osd', 'blacklist',
956 def test_pool_mksnap(self
):
957 self
.assert_valid_command(['osd', 'pool', 'mksnap',
958 'poolname', 'snapname'])
959 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'mksnap']))
960 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'mksnap',
962 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'mksnap',
963 'poolname', 'snapname',
966 def test_pool_rmsnap(self
):
967 self
.assert_valid_command(['osd', 'pool', 'rmsnap',
968 'poolname', 'snapname'])
969 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rmsnap']))
970 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rmsnap',
972 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rmsnap',
973 'poolname', 'snapname',
976 def test_pool_create(self
):
977 self
.assert_valid_command(['osd', 'pool', 'create',
979 self
.assert_valid_command(['osd', 'pool', 'create',
980 'poolname', '128', '128'])
981 self
.assert_valid_command(['osd', 'pool', 'create',
982 'poolname', '128', '128',
984 self
.assert_valid_command(['osd', 'pool', 'create',
985 'poolname', '128', '128',
986 'erasure', 'A-Za-z0-9-_.', 'ruleset^^'])
987 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create']))
988 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create',
990 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create',
992 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create',
997 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create',
1000 'erasure', 'profile',
1003 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'create',
1006 'INVALID', 'profile',
1009 def test_pool_delete(self
):
1010 self
.assert_valid_command(['osd', 'pool', 'delete',
1011 'poolname', 'poolname',
1012 '--yes-i-really-really-mean-it'])
1013 self
.assert_valid_command(['osd', 'pool', 'delete',
1014 'poolname', 'poolname'])
1015 self
.assert_valid_command(['osd', 'pool', 'delete',
1017 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'delete']))
1018 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'delete',
1019 'poolname', 'poolname',
1021 assert_equal({}, validate_command(sigdict
,
1022 ['osd', 'pool', 'delete',
1023 'poolname', 'poolname',
1024 '--yes-i-really-really-mean-it',
1027 def test_pool_rename(self
):
1028 self
.assert_valid_command(['osd', 'pool', 'rename',
1029 'poolname', 'othername'])
1030 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rename']))
1031 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rename',
1033 assert_equal({}, validate_command(sigdict
, ['osd', 'pool', 'rename',
1034 'poolname', 'othername',
1037 def test_pool_get(self
):
1038 for var
in ('size', 'min_size', 'crash_replay_interval',
1039 'pg_num', 'pgp_num', 'crush_rule', 'auid', 'fast_read',
1040 'scrub_min_interval', 'scrub_max_interval',
1041 'deep_scrub_interval', 'recovery_priority',
1042 'recovery_op_priority'):
1043 self
.assert_valid_command(['osd', 'pool', 'get', 'poolname', var
])
1044 assert_equal({}, validate_command(sigdict
, ['osd', 'pool']))
1045 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1047 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1048 'get', 'poolname']))
1049 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1051 'size', 'toomany']))
1052 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1056 def test_pool_set(self
):
1057 for var
in ('size', 'min_size', 'crash_replay_interval',
1058 'pg_num', 'pgp_num', 'crush_rule',
1059 'hashpspool', 'auid', 'fast_read',
1060 'scrub_min_interval', 'scrub_max_interval',
1061 'deep_scrub_interval', 'recovery_priority',
1062 'recovery_op_priority'):
1063 self
.assert_valid_command(['osd', 'pool',
1064 'set', 'poolname', var
, 'value'])
1065 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1067 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1068 'set', 'poolname']))
1069 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1074 def test_pool_set_quota(self
):
1075 for field
in ('max_objects', 'max_bytes'):
1076 self
.assert_valid_command(['osd', 'pool', 'set-quota',
1077 'poolname', field
, '10K'])
1078 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1080 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1083 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1087 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1092 assert_equal({}, validate_command(sigdict
, ['osd', 'pool',
1099 def test_reweight_by_utilization(self
):
1100 self
.assert_valid_command(['osd', 'reweight-by-utilization'])
1101 self
.assert_valid_command(['osd', 'reweight-by-utilization', '100'])
1102 self
.assert_valid_command(['osd', 'reweight-by-utilization', '100', '.1'])
1103 self
.assert_valid_command(['osd', 'reweight-by-utilization', '--no-increasing'])
1104 assert_equal({}, validate_command(sigdict
, ['osd',
1105 'reweight-by-utilization',
1109 def test_tier_op(self
):
1110 for op
in ('add', 'remove', 'set-overlay'):
1111 self
.assert_valid_command(['osd', 'tier', op
,
1112 'poolname', 'othername'])
1113 assert_equal({}, validate_command(sigdict
, ['osd', 'tier', op
]))
1114 assert_equal({}, validate_command(sigdict
, ['osd', 'tier', op
,
1116 assert_equal({}, validate_command(sigdict
, ['osd', 'tier', op
,
1121 def test_tier_cache_mode(self
):
1122 for mode
in ('none', 'writeback', 'forward', 'readonly', 'readforward', 'readproxy'):
1123 self
.assert_valid_command(['osd', 'tier', 'cache-mode',
1125 assert_equal({}, validate_command(sigdict
, ['osd', 'tier',
1127 assert_equal({}, validate_command(sigdict
, ['osd', 'tier',
1131 def test_tier_remove_overlay(self
):
1132 self
.assert_valid_command(['osd', 'tier', 'remove-overlay',
1134 assert_equal({}, validate_command(sigdict
, ['osd', 'tier',
1136 assert_equal({}, validate_command(sigdict
, ['osd', 'tier',
1141 def set_ratio(self
, command
):
1142 self
.assert_valid_command(['osd',
1145 assert_equal({}, validate_command(sigdict
, ['osd', command
]))
1146 assert_equal({}, validate_command(sigdict
, ['osd',
1150 def test_set_full_ratio(self
):
1151 self
.set_ratio('set-full-ratio')
1153 def test_set_backfillfull_ratio(self
):
1154 self
.set_ratio('set-backfillfull-ratio')
1156 def test_set_nearfull_ratio(self
):
1157 self
.set_ratio('set-nearfull-ratio')
1160 class TestConfigKey(TestArgparse
):
1163 self
.check_1_string_arg('config-key', 'get')
1166 self
.assert_valid_command(['config-key', 'put',
1168 self
.assert_valid_command(['config-key', 'put',
1170 assert_equal({}, validate_command(sigdict
, ['config-key', 'put']))
1171 assert_equal({}, validate_command(sigdict
, ['config-key', 'put',
1176 self
.check_1_string_arg('config-key', 'del')
1178 def test_exists(self
):
1179 self
.check_1_string_arg('config-key', 'exists')
1181 def test_dump(self
):
1182 self
.check_no_arg('config-key', 'dump')
1184 def test_list(self
):
1185 self
.check_no_arg('config-key', 'list')
1187 # compile-command: "cd ../.. ; make -j4 &&
1188 # PYTHONPATH=pybind nosetests --stop \
1189 # test/pybind/test_ceph_argparse.py # test_ceph_argparse.py:TestOSD.test_rm"