From: liuchang0812 Date: Tue, 16 May 2017 10:16:46 +0000 (+0800) Subject: tool/ceph: create "tell x help" command X-Git-Tag: v12.1.0~57^2~24^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=568093687839c309ae446cb2d117714ffa67c6c7;p=ceph.git tool/ceph: create "tell x help" command Fixes: http://tracker.ceph.com/issues/19885 Signed-off-by: liuchang0812 --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 6ef6782c37b0..01401601021d 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -2037,6 +2037,48 @@ function test_mon_cephdf_commands() expect_false test $cal_raw_used_size != $raw_used_size } +function test_mon_tell_help_command() +{ + ceph tell mon.a help + + # wrong target + expect_false ceph tell mon.zzz help +} + +function test_osd_tell_help_command() +{ + ceph tell osd.1 help + expect_false ceph tell osd.100 help +} + +function test_mds_tell_help_command() +{ + FS_NAME=cephfs + if ! mds_exists ; then + echo "Skipping test, no MDS found" + return + fi + + remove_all_fs + ceph osd pool create fs_data 10 + ceph osd pool create fs_metadata 10 + ceph fs new $FS_NAME fs_metadata fs_data + wait_mds_active $FS_NAME + + + ceph tell mds.a help + expect_false ceph tell mds.z help + + remove_all_fs + ceph osd pool delete fs_data fs_data --yes-i-really-really-mean-it + ceph osd pool delete fs_metadata fs_metadata --yes-i-really-really-mean-it +} + +function test_mgr_tell_help_command() +{ + ceph tell mgr help +} + # # New tests should be added to the TESTS array below # @@ -2078,18 +2120,25 @@ MON_TESTS+=" mon_ping" MON_TESTS+=" mon_deprecated_commands" MON_TESTS+=" mon_caps" MON_TESTS+=" mon_cephdf_commands" +MON_TESTS+=" mon_tell_help_command" + OSD_TESTS+=" osd_bench" OSD_TESTS+=" osd_negative_filestore_merge_threshold" OSD_TESTS+=" tiering_agent" OSD_TESTS+=" admin_heap_profiler" +OSD_TESTS+=" osd_tell_help_command" MDS_TESTS+=" mds_tell" MDS_TESTS+=" mon_mds" MDS_TESTS+=" mon_mds_metadata" +MDS_TESTS+=" mds_tell_help_command" + +MGR_TESTS+=" mgr_tell_help_command" TESTS+=$MON_TESTS TESTS+=$OSD_TESTS TESTS+=$MDS_TESTS +TESTS+=$MGR_TESTS # # "main" follows @@ -2134,6 +2183,9 @@ while [[ $# -gt 0 ]]; do "--test-mds" ) tests_to_run+="$MDS_TESTS" ;; + "--test-mgr" ) + tests_to_run+="$MGR_TESTS" + ;; "-t" ) shift if [[ -z "$1" ]]; then diff --git a/src/ceph.in b/src/ceph.in index 3579799b50a7..ea4d5dd19498 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -287,7 +287,7 @@ daemonperf {type.id | path} list|ls [stat-pats] [priority] """, file=sys.stdout) -def do_extended_help(parser, args): +def do_extended_help(parser, args, target, partial): def help_for_sigs(sigs, partial=None): sys.stdout.write(format_help(parse_json_funcsigs(sigs, 'cli'), partial=partial)) @@ -299,13 +299,12 @@ def do_extended_help(parser, args): if ret: print("couldn't get command descriptions for {0}: {1}".\ format(target, outs), file=sys.stderr) + return 1 else: - help_for_sigs(outbuf.decode('utf-8'), partial) + return help_for_sigs(outbuf.decode('utf-8'), partial) - partial = ' '.join(args) assert(cluster_handle.state == "connected") - help_for_target(target=('mon', ''), partial=partial) - return 0 + return help_for_target(target, partial) DONTSPLIT = string.ascii_letters + '{[<>]}' @@ -853,7 +852,11 @@ def main(): return 1 if parsed_args.help: - return do_extended_help(parser, childargs) + return do_extended_help(parser, childargs, ('mon', ''), ' '.join(childargs)) + + # implement "tell service.id help" + if len(childargs) >= 3 and childargs[0] == 'tell' and childargs[2] == 'help': + return do_extended_help(parser, childargs, childargs[1].split('.'), None) # implement -w/--watch_* # This is ugly, but Namespace() isn't quite rich enough. diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index bb1927e25d6f..ac23a9f90287 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -492,17 +492,14 @@ bool DaemonServer::handle_command(MCommand *m) "mgr", pyc.perm, "cli", 0); cmdnum++; } -#if 0 - for (MgrCommand *cp = mgr_commands; - cp < &mgr_commands[ARRAY_SIZE(mgr_commands)]; cp++) { + for (const auto &cp : mgr_commands) { ostringstream secname; secname << "cmd" << setfill('0') << std::setw(3) << cmdnum; - dump_cmddesc_to_json(f, secname.str(), cp->cmdstring, cp->helpstring, - cp->module, cp->perm, cp->availability, 0); + dump_cmddesc_to_json(&f, secname.str(), cp.cmdstring, cp.helpstring, + cp.module, cp.perm, cp.availability, 0); cmdnum++; } -#endif f.close_section(); // command_descriptions f.flush(cmdctx->odata); cmdctx->reply(0, ss); diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 2c91d79c5d4c..59bc608d5608 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -29,7 +29,7 @@ * helpstring: displays in CLI help, API help (nice if it refers to * parameter names from signature, 40-a few hundred chars) * modulename: the monitor module or daemon this applies to: - * mds, osd, pg (osd), mon, auth, log, config-key + * mds, osd, pg (osd), mon, auth, log, config-key, mgr * req perms: required permission in that modulename space to execute command * this also controls what type of REST command is accepted * availability: cli, rest, or both