]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/pybind/test_ceph_argparse.py
update sources to v12.1.1
[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
183 def test_force_create_pg(self):
184 self.one_pgid('force_create_pg')
185
186
187class TestAuth(TestArgparse):
188
189 def test_export(self):
190 self.assert_valid_command(['auth', 'export'])
191 self.assert_valid_command(['auth',
192 'export',
193 'string'])
194 assert_equal({}, validate_command(sigdict, ['auth',
195 'export',
196 'string',
197 'toomany']))
198
199 def test_get(self):
200 self.check_1_string_arg('auth', 'get')
201
202 def test_get_key(self):
203 self.check_1_string_arg('auth', 'get-key')
204
205 def test_print_key(self):
206 self.check_1_string_arg('auth', 'print-key')
207 self.check_1_string_arg('auth', 'print_key')
208
209 def test_list(self):
210 self.check_no_arg('auth', 'list')
211
212 def test_import(self):
213 self.check_no_arg('auth', 'import')
214
215 def test_add(self):
216 self.check_1_or_more_string_args('auth', 'add')
217
218 def test_get_or_create_key(self):
219 self.check_1_or_more_string_args('auth', 'get-or-create-key')
220
221 def test_get_or_create(self):
222 self.check_1_or_more_string_args('auth', 'get-or-create')
223
224 def test_caps(self):
225 assert_equal({}, validate_command(sigdict, ['auth',
226 'caps']))
227 assert_equal({}, validate_command(sigdict, ['auth',
228 'caps',
229 'string']))
230 self.assert_valid_command(['auth',
231 'caps',
232 'string',
233 'more string'])
234
235 def test_del(self):
236 self.check_1_string_arg('auth', 'del')
237
238
239class TestMonitor(TestArgparse):
240
241 def test_compact(self):
242 self.assert_valid_command(['compact'])
243
244 def test_scrub(self):
245 self.assert_valid_command(['scrub'])
246
247 def test_fsid(self):
248 self.assert_valid_command(['fsid'])
249
250 def test_log(self):
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'])
254
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'])
259
260 def test_status(self):
261 self.assert_valid_command(['status'])
262
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',
268 'toomany']))
269
270 def test_df(self):
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',
275 'toomany']))
276
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'])
281
282 def test_quorum_status(self):
283 self.assert_valid_command(['quorum_status'])
284
285 def test_mon_status(self):
286 self.assert_valid_command(['mon_status'])
287
288 def test_sync_force(self):
289 self.assert_valid_command(['sync',
290 'force',
291 '--yes-i-really-mean-it',
292 '--i-know-what-i-am-doing'])
293 self.assert_valid_command(['sync',
294 'force',
295 '--yes-i-really-mean-it'])
296 self.assert_valid_command(['sync',
297 'force'])
298 assert_equal({}, validate_command(sigdict, ['sync']))
299 assert_equal({}, validate_command(sigdict, ['sync',
300 'force',
301 '--yes-i-really-mean-it',
302 '--i-know-what-i-am-doing',
303 'toomany']))
304
305 def test_heap(self):
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'])
313
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',
320 'enter',
321 'toomany']))
322
323 def test_tell(self):
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',
329 name + ".42"]))
330 self.assert_valid_command(['tell', name + ".42", 'something'])
331 self.assert_valid_command(['tell', name + ".42",
332 'something',
333 'something else'])
334
335
336class TestMDS(TestArgparse):
337
338 def test_stat(self):
339 self.check_no_arg('mds', 'stat')
340
341 def test_dump(self):
342 self.check_0_or_1_natural_arg('mds', 'dump')
343
344 def test_tell(self):
345 self.assert_valid_command(['mds', 'tell',
346 'someone',
347 'something'])
348 self.assert_valid_command(['mds', 'tell',
349 'someone',
350 'something',
351 'something else'])
352 assert_equal({}, validate_command(sigdict, ['mds', 'tell']))
353 assert_equal({}, validate_command(sigdict, ['mds', 'tell',
354 'someone']))
355
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',
360 'show', 'toomany']))
361
362 def test_stop(self):
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']))
367
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']))
373
374 def test_set_max_mds(self):
375 self.check_1_natural_arg('mds', 'set_max_mds')
376
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',
382 '1', '-1']))
383 assert_equal({}, validate_command(sigdict, ['mds', 'set_state',
384 '1', '21']))
385
386 def test_fail(self):
387 self.check_1_string_arg('mds', 'fail')
388
389 def test_rm(self):
390 # Valid: single GID argument present
391 self.assert_valid_command(['mds', 'rm', '1'])
392
393 # Missing GID arg: invalid
394 assert_equal({}, validate_command(sigdict, ['mds', 'rm']))
395 # Extra arg: invalid
396 assert_equal({}, validate_command(sigdict, ['mds', 'rm', '1', 'mds.42']))
397
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',
403 'toomany']))
404
405 def test_cluster_down(self):
406 self.check_no_arg('mds', 'cluster_down')
407
408 def test_cluster_up(self):
409 self.check_no_arg('mds', 'cluster_up')
410
411 def test_compat_rm_compat(self):
412 self.assert_valid_command(['mds', 'compat', 'rm_compat', '1'])
413 assert_equal({}, validate_command(sigdict, ['mds',
414 'compat',
415 'rm_compat']))
416 assert_equal({}, validate_command(sigdict, ['mds',
417 'compat',
418 'rm_compat', '-1']))
419 assert_equal({}, validate_command(sigdict, ['mds',
420 'compat',
421 'rm_compat', '1', '1']))
422
423 def test_incompat_rm_incompat(self):
424 self.assert_valid_command(['mds', 'compat', 'rm_incompat', '1'])
425 assert_equal({}, validate_command(sigdict, ['mds',
426 'compat',
427 'rm_incompat']))
428 assert_equal({}, validate_command(sigdict, ['mds',
429 'compat',
430 'rm_incompat', '-1']))
431 assert_equal({}, validate_command(sigdict, ['mds',
432 'compat',
433 'rm_incompat', '1', '1']))
434
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',
440 'set',
441 'invalid']))
442
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'])
446
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'])
450
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',
458 'newfs',
459 '1',
460 '2',
461 '--yes-i-really-mean-it',
462 'toomany']))
463 assert_equal({}, validate_command(sigdict, ['mds',
464 'newfs',
465 '-1',
466 '2',
467 '--yes-i-really-mean-it']))
468 assert_equal({}, validate_command(sigdict, ['mds',
469 'newfs',
470 '1',
471 '-1',
472 '--yes-i-really-mean-it']))
473
474
475class TestFS(TestArgparse):
476
477 def test_dump(self):
478 self.check_0_or_1_natural_arg('fs', 'dump')
479
480 def test_fs_new(self):
481 self.assert_valid_command(['fs', 'new', 'default', 'metadata', 'data'])
482
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']))
487
488 def test_fs_ls(self):
489 self.assert_valid_command(['fs', 'ls'])
490 assert_equal({}, validate_command(sigdict, ['fs', 'ls', 'toomany']))
491
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']))
496
497class TestMon(TestArgparse):
498
499 def test_dump(self):
500 self.check_0_or_1_natural_arg('mon', 'dump')
501
502 def test_stat(self):
503 self.check_no_arg('mon', 'stat')
504
505 def test_getmap(self):
506 self.check_0_or_1_natural_arg('mon', 'getmap')
507
508 def test_add(self):
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',
513 'name',
514 '400.500.600.700']))
515 assert_equal({}, validate_command(sigdict, ['mon', 'add', 'name',
516 '1.2.3.4:1234',
517 'toomany']))
518
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',
523 'name', 'toomany']))
524
525
526class TestOSD(TestArgparse):
527
528 def test_stat(self):
529 self.check_no_arg('osd', 'stat')
530
531 def test_dump(self):
532 self.check_0_or_1_natural_arg('osd', 'dump')
533
534 def test_osd_tree(self):
535 self.check_0_or_1_natural_arg('osd', 'tree')
536
537 def test_osd_ls(self):
538 self.check_0_or_1_natural_arg('osd', 'ls')
539
540 def test_osd_getmap(self):
541 self.check_0_or_1_natural_arg('osd', 'getmap')
542
543 def test_osd_getcrushmap(self):
544 self.check_0_or_1_natural_arg('osd', 'getcrushmap')
545
546 def test_perf(self):
547 self.check_no_arg('osd', 'perf')
548
549 def test_getmaxosd(self):
550 self.check_no_arg('osd', 'getmaxosd')
551
552 def test_find(self):
553 self.check_1_natural_arg('osd', 'find')
554
555 def test_map(self):
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',
562 'toomany']))
563
564 def test_metadata(self):
565 self.check_0_or_1_natural_arg('osd', 'metadata')
566
567 def test_scrub(self):
568 self.check_1_string_arg('osd', 'scrub')
569
570 def test_deep_scrub(self):
571 self.check_1_string_arg('osd', 'deep-scrub')
572
573 def test_repair(self):
574 self.check_1_string_arg('osd', 'repair')
575
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',
581 '1', 'toomany']))
582
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',
587 'ls', 'toomany']))
588
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',
595 'rule', subcommand,
596 'toomany']))
597
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',
602 'rule', 'dump',
603 'RULE',
604 'toomany']))
605
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',
610 'dump',
611 'toomany']))
612
613 def test_setcrushmap(self):
614 self.check_no_arg('osd', 'setcrushmap')
615
616 def test_crush_add_bucket(self):
617 self.assert_valid_command(['osd', 'crush', 'add-bucket',
618 'name', 'type'])
619 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
620 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
621 'add-bucket']))
622 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
623 'add-bucket', 'name',
624 'type',
625 'toomany']))
626 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
627 'add-bucket', '^^^',
628 'type']))
629
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',
635 'rename-bucket']))
636 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
637 'rename-bucket',
638 'srcname']))
639 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
640 'rename-bucket', 'srcname',
641 'dstname',
642 'toomany']))
643 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
644 'rename-bucket', '^^^',
645 'dstname']))
646 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
647 'rename-bucket', 'srcname',
648 '^^^^']))
649
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',
660 setter,
661 'osd.0']))
662 ret = validate_command(sigdict, ['osd', 'crush',
663 setter,
664 'osd.0',
665 '-1.0'])
666 assert ret in [None, {}]
667 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
668 setter,
669 'osd.0',
670 '1.0',
671 '^^^']))
672
673 def test_crush_set(self):
674 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
675 self.check_crush_setter('set')
676
677 def test_crush_add(self):
678 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
679 self.check_crush_setter('add')
680
681 def test_crush_create_or_move(self):
682 assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
683 self.check_crush_setter('create-or-move')
684
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',
691 'move']))
692 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
693 'move', 'AZaz09-_.']))
694 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
695 'move', '^^^',
696 'AZaz09-_.=']))
697 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
698 'move', 'AZaz09-_.',
699 '^^^']))
700
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',
707 'link']))
708 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
709 'link',
710 'name']))
711
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',
718 alias]))
719 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
720 alias,
721 'AZaz09-_.',
722 'AZaz09-_.',
723 'toomany']))
724
725 def test_crush_reweight(self):
726 self.assert_valid_command(['osd', 'crush', 'reweight',
727 'AZaz09-_.', '2.3'])
728 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
729 'reweight']))
730 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
731 'reweight',
732 'AZaz09-_.']))
733 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
734 'reweight',
735 'AZaz09-_.',
736 '-1.0']))
737 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
738 'reweight',
739 '^^^',
740 '2.3']))
741
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',
746 tunable])
747 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
748 'tunables']))
749 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
750 'tunables',
751 'default', 'toomany']))
752
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',
757 'create-simple']))
758 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
759 'create-simple',
760 'AZaz09-_.']))
761 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
762 'create-simple',
763 'AZaz09-_.',
764 'AZaz09-_.']))
765 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
766 'create-simple',
767 '^^^',
768 'AZaz09-_.',
769 'AZaz09-_.']))
770 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
771 'create-simple',
772 'AZaz09-_.',
773 '|||',
774 'AZaz09-_.']))
775 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
776 'create-simple',
777 'AZaz09-_.',
778 'AZaz09-_.',
779 '+++']))
780 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
781 'create-simple',
782 'AZaz09-_.',
783 'AZaz09-_.',
784 'AZaz09-_.',
785 'toomany']))
786
787 def test_crush_rule_create_erasure(self):
788 self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
789 'AZaz09-_.'])
790 self.assert_valid_command(['osd', 'crush', 'rule', 'create-erasure',
791 'AZaz09-_.', 'whatever'])
792 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
793 'create-erasure']))
794 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
795 'create-erasure',
796 '^^^']))
797 assert_equal({}, validate_command(sigdict, ['osd', 'crush', 'rule',
798 'create-erasure',
799 'name', '^^^']))
800
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',
804 'rule', 'rm']))
805 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
806 'rule', 'rm',
807 '^^^^']))
808 assert_equal({}, validate_command(sigdict, ['osd', 'crush',
809 'rule', 'rm',
810 'AZaz09-_.',
811 'toomany']))
812
813 def test_setmaxosd(self):
814 self.check_1_natural_arg('osd', 'setmaxosd')
815
816 def test_pause(self):
817 self.check_no_arg('osd', 'pause')
818
819 def test_unpause(self):
820 self.check_no_arg('osd', 'unpause')
821
822 def test_erasure_code_profile_set(self):
823 self.assert_valid_command(['osd', 'erasure-code-profile', 'set',
824 'name'])
825 self.assert_valid_command(['osd', 'erasure-code-profile', 'set',
826 'name', 'A=B'])
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',
831 'set']))
832 assert_equal({}, validate_command(sigdict, ['osd',
833 'erasure-code-profile',
834 'set',
835 '^^^^']))
836
837 def test_erasure_code_profile_get(self):
838 self.assert_valid_command(['osd', 'erasure-code-profile', 'get',
839 'name'])
840 assert_equal({}, validate_command(sigdict, ['osd',
841 'erasure-code-profile',
842 'get']))
843 assert_equal({}, validate_command(sigdict, ['osd',
844 'erasure-code-profile',
845 'get',
846 '^^^^']))
847
848 def test_erasure_code_profile_rm(self):
849 self.assert_valid_command(['osd', 'erasure-code-profile', 'rm',
850 'name'])
851 assert_equal({}, validate_command(sigdict, ['osd',
852 'erasure-code-profile',
853 'rm']))
854 assert_equal({}, validate_command(sigdict, ['osd',
855 'erasure-code-profile',
856 'rm',
857 '^^^^']))
858
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',
863 'ls',
864 'toomany']))
865
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,
873 'invalid']))
874 assert_equal({}, validate_command(sigdict, ['osd', action,
875 'pause', 'toomany']))
876
877 def test_cluster_snap(self):
878 assert_equal(None, validate_command(sigdict, ['osd', 'cluster_snap']))
879
880 def test_down(self):
881 self.check_1_or_more_string_args('osd', 'down')
882
883 def test_out(self):
884 self.check_1_or_more_string_args('osd', 'out')
885
886 def test_in(self):
887 self.check_1_or_more_string_args('osd', 'in')
888
889 def test_rm(self):
890 self.check_1_or_more_string_args('osd', 'rm')
891
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',
896 '1']))
897 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
898 '1', '2.0']))
899 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
900 '-1', '0.1']))
901 assert_equal({}, validate_command(sigdict, ['osd', 'reweight',
902 '1', '0.1',
903 'toomany']))
904
905 def test_lost(self):
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',
911 '1',
912 'what?']))
913 assert_equal({}, validate_command(sigdict, ['osd', 'lost',
914 '-1',
915 '--yes-i-really-mean-it']))
916 assert_equal({}, validate_command(sigdict, ['osd', 'lost',
917 '1',
918 '--yes-i-really-mean-it',
919 'toomany']))
920
921 def test_create(self):
922 uuid = '12345678123456781234567812345678'
923 self.assert_valid_command(['osd', 'create'])
924 self.assert_valid_command(['osd', 'create',
925 uuid])
926 assert_equal({}, validate_command(sigdict, ['osd', 'create',
927 'invalid']))
928 assert_equal({}, validate_command(sigdict, ['osd', 'create',
929 uuid,
930 'toomany']))
931
932 def test_blacklist(self):
933 for action in ('add', 'rm'):
934 self.assert_valid_command(['osd', 'blacklist', action,
935 '1.2.3.4/567'])
936 self.assert_valid_command(['osd', 'blacklist', action,
937 '1.2.3.4'])
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',
943 action,
944 'invalid',
945 '600.40']))
946 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
947 action,
948 '1.2.3.4/567',
949 '-1.0']))
950 assert_equal({}, validate_command(sigdict, ['osd', 'blacklist',
951 action,
952 '1.2.3.4/567',
953 '600.40',
954 'toomany']))
955
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',
961 'poolname']))
962 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'mksnap',
963 'poolname', 'snapname',
964 'toomany']))
965
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',
971 'poolname']))
972 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rmsnap',
973 'poolname', 'snapname',
974 'toomany']))
975
976 def test_pool_create(self):
977 self.assert_valid_command(['osd', 'pool', 'create',
978 'poolname', '128'])
979 self.assert_valid_command(['osd', 'pool', 'create',
980 'poolname', '128', '128'])
981 self.assert_valid_command(['osd', 'pool', 'create',
982 'poolname', '128', '128',
983 'replicated'])
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',
989 'poolname']))
990 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
991 'poolname', '-1']))
992 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
993 'poolname',
994 '128', '128',
995 'erasure', '^^^',
996 'ruleset']))
997 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
998 'poolname',
999 '128', '128',
1000 'erasure', 'profile',
1001 'ruleset',
1002 'toomany']))
1003 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'create',
1004 'poolname',
1005 '128', '128',
1006 'INVALID', 'profile',
1007 'ruleset']))
1008
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',
1016 'poolname'])
1017 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'delete']))
7c673cae
FG
1018 assert_equal({}, validate_command(sigdict,
1019 ['osd', 'pool', 'delete',
1020 'poolname', 'poolname',
1021 '--yes-i-really-really-mean-it',
1022 'toomany']))
1023
1024 def test_pool_rename(self):
1025 self.assert_valid_command(['osd', 'pool', 'rename',
1026 'poolname', 'othername'])
1027 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename']))
1028 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename',
1029 'poolname']))
1030 assert_equal({}, validate_command(sigdict, ['osd', 'pool', 'rename',
1031 'poolname', 'othername',
1032 'toomany']))
1033
1034 def test_pool_get(self):
1035 for var in ('size', 'min_size', 'crash_replay_interval',
31f18b77 1036 'pg_num', 'pgp_num', 'crush_rule', 'auid', 'fast_read',
7c673cae
FG
1037 'scrub_min_interval', 'scrub_max_interval',
1038 'deep_scrub_interval', 'recovery_priority',
1039 'recovery_op_priority'):
1040 self.assert_valid_command(['osd', 'pool', 'get', 'poolname', var])
1041 assert_equal({}, validate_command(sigdict, ['osd', 'pool']))
1042 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1043 'get']))
1044 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1045 'get', 'poolname']))
1046 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1047 'get', 'poolname',
1048 'size', 'toomany']))
1049 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1050 'get', 'poolname',
1051 'invalid']))
1052
1053 def test_pool_set(self):
1054 for var in ('size', 'min_size', 'crash_replay_interval',
31f18b77 1055 'pg_num', 'pgp_num', 'crush_rule',
7c673cae
FG
1056 'hashpspool', 'auid', 'fast_read',
1057 'scrub_min_interval', 'scrub_max_interval',
1058 'deep_scrub_interval', 'recovery_priority',
1059 'recovery_op_priority'):
1060 self.assert_valid_command(['osd', 'pool',
1061 'set', 'poolname', var, 'value'])
1062 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1063 'set']))
1064 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1065 'set', 'poolname']))
1066 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1067 'set', 'poolname',
1068 'size', 'value',
1069 'toomany']))
1070
1071 def test_pool_set_quota(self):
1072 for field in ('max_objects', 'max_bytes'):
1073 self.assert_valid_command(['osd', 'pool', 'set-quota',
1074 'poolname', field, '10K'])
1075 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1076 'set-quota']))
1077 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1078 'set-quota',
1079 'poolname']))
1080 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1081 'set-quota',
1082 'poolname',
1083 'max_objects']))
1084 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1085 'set-quota',
1086 'poolname',
1087 'invalid',
1088 '10K']))
1089 assert_equal({}, validate_command(sigdict, ['osd', 'pool',
1090 'set-quota',
1091 'poolname',
1092 'max_objects',
1093 '10K',
1094 'toomany']))
1095
1096 def test_reweight_by_utilization(self):
1097 self.assert_valid_command(['osd', 'reweight-by-utilization'])
1098 self.assert_valid_command(['osd', 'reweight-by-utilization', '100'])
1099 self.assert_valid_command(['osd', 'reweight-by-utilization', '100', '.1'])
1100 self.assert_valid_command(['osd', 'reweight-by-utilization', '--no-increasing'])
1101 assert_equal({}, validate_command(sigdict, ['osd',
1102 'reweight-by-utilization',
1103 '100',
1104 'toomany']))
1105
1106 def test_tier_op(self):
1107 for op in ('add', 'remove', 'set-overlay'):
1108 self.assert_valid_command(['osd', 'tier', op,
1109 'poolname', 'othername'])
1110 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op]))
1111 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op,
1112 'poolname']))
1113 assert_equal({}, validate_command(sigdict, ['osd', 'tier', op,
1114 'poolname',
1115 'othername',
1116 'toomany']))
1117
1118 def test_tier_cache_mode(self):
1119 for mode in ('none', 'writeback', 'forward', 'readonly', 'readforward', 'readproxy'):
1120 self.assert_valid_command(['osd', 'tier', 'cache-mode',
1121 'poolname', mode])
1122 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1123 'cache-mode']))
1124 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1125 'cache-mode',
1126 'invalid']))
1127
1128 def test_tier_remove_overlay(self):
1129 self.assert_valid_command(['osd', 'tier', 'remove-overlay',
1130 'poolname'])
1131 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1132 'remove-overlay']))
1133 assert_equal({}, validate_command(sigdict, ['osd', 'tier',
1134 'remove-overlay',
1135 'poolname',
1136 'toomany']))
1137
1138 def set_ratio(self, command):
1139 self.assert_valid_command(['osd',
1140 command,
1141 '0.0'])
1142 assert_equal({}, validate_command(sigdict, ['osd', command]))
1143 assert_equal({}, validate_command(sigdict, ['osd',
1144 command,
1145 '2.0']))
1146
1147 def test_set_full_ratio(self):
1148 self.set_ratio('set-full-ratio')
1149
1150 def test_set_backfillfull_ratio(self):
1151 self.set_ratio('set-backfillfull-ratio')
1152
1153 def test_set_nearfull_ratio(self):
1154 self.set_ratio('set-nearfull-ratio')
1155
1156
1157class TestConfigKey(TestArgparse):
1158
1159 def test_get(self):
1160 self.check_1_string_arg('config-key', 'get')
1161
1162 def test_put(self):
1163 self.assert_valid_command(['config-key', 'put',
1164 'key'])
1165 self.assert_valid_command(['config-key', 'put',
1166 'key', 'value'])
1167 assert_equal({}, validate_command(sigdict, ['config-key', 'put']))
1168 assert_equal({}, validate_command(sigdict, ['config-key', 'put',
1169 'key', 'value',
1170 'toomany']))
1171
1172 def test_del(self):
1173 self.check_1_string_arg('config-key', 'del')
1174
1175 def test_exists(self):
1176 self.check_1_string_arg('config-key', 'exists')
1177
1178 def test_dump(self):
1179 self.check_no_arg('config-key', 'dump')
1180
1181 def test_list(self):
1182 self.check_no_arg('config-key', 'list')
1183# Local Variables:
1184# compile-command: "cd ../.. ; make -j4 &&
1185# PYTHONPATH=pybind nosetests --stop \
1186# test/pybind/test_ceph_argparse.py # test_ceph_argparse.py:TestOSD.test_rm"
1187# End: