]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tool/ceph: create "tell x help" command
authorliuchang0812 <liuchang0812@gmail.com>
Tue, 16 May 2017 10:16:46 +0000 (18:16 +0800)
committerliuchang0812 <liuchang0812@gmail.com>
Fri, 26 May 2017 02:27:26 +0000 (10:27 +0800)
Fixes: http://tracker.ceph.com/issues/19885
Signed-off-by: liuchang0812 <liuchang0812@gmail.com>
qa/workunits/cephtool/test.sh
src/ceph.in
src/mgr/DaemonServer.cc
src/mon/MonCommands.h

index 6ef6782c37b000c34681e52de831536c467f1d11..01401601021d69bcc362ea2d696a1c53e439ea47 100755 (executable)
@@ -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
index 3579799b50a7065bd157667f35f18edfaf3a08dd..ea4d5dd19498faa386842786f54df7d2cdc0f9ac 100755 (executable)
@@ -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.
index bb1927e25d6fa7e1405920f5061ffd6f45ec8c2f..ac23a9f90287959a1375b38b70752dd2cce324e8 100644 (file)
@@ -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);
index 2c91d79c5d4cab5a8d9ca2f8ab7e463455080437..59bc608d5608d7437f002ccfd117127e0eb9d2f0 100644 (file)
@@ -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