]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: fix "ceph pg dump_json/dump_pools_json" format error
authorhaoyixing <haoyixing@kuaishou.com>
Sat, 21 Nov 2020 14:31:00 +0000 (22:31 +0800)
committerhaoyixing <haoyixing@kuaishou.com>
Tue, 24 Nov 2020 08:09:51 +0000 (16:09 +0800)
When execute ceph pg dump_json, the expected result is json format,
but now is plain. Same to ceph pg dump_pools_json. So check args to
show right format result.

Signed-off-by: haoyixing <haoyixing@kuaishou.com>
Co-authored-by: Kefu Chai <kefu@redhat.com>
src/mgr/DaemonServer.cc
src/mon/PGMap.cc

index 91e6c3759b9f091f9c3b8bc0d993bb5a353465e0..001f8f81bbf5db30df6e55d2be9b5fd8515bdb26 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include "DaemonServer.h"
+#include <boost/algorithm/string.hpp>
 #include "mgr/Mgr.h"
 
 #include "include/stringify.h"
@@ -889,8 +890,6 @@ bool DaemonServer::_handle_command(
     session->inst.name = m->get_source();
   }
 
-  std::string format;
-  boost::scoped_ptr<Formatter> f;
   map<string,string> param_str_map;
   std::stringstream ss;
   int r = 0;
@@ -900,15 +899,20 @@ bool DaemonServer::_handle_command(
     return true;
   }
 
-  {
-    cmd_getval(cmdctx->cmdmap, "format", format, string("plain"));
-    f.reset(Formatter::create(format));
-  }
-
   string prefix;
   cmd_getval(cmdctx->cmdmap, "prefix", prefix);
+  dout(10) << "decoded-size=" << cmdctx->cmdmap.size() << " prefix=" << prefix << dendl;
 
-  dout(10) << "decoded-size=" << cmdctx->cmdmap.size() << " prefix=" << prefix  << dendl;
+  boost::scoped_ptr<Formatter> f;
+  {
+    std::string format;
+    if (boost::algorithm::ends_with(prefix, "_json")) {
+      format = "json";
+    } else {
+      cmd_getval(cmdctx->cmdmap, "format", format, string("plain"));
+    }
+    f.reset(Formatter::create(format));
+  }
 
   // this is just for mgr commands - admin socket commands will fall
   // through and use the admin socket version of
index 176b64e15717f41b80d55a8901699eed2d3001f0..26bfcf046731dca832064bfd38df1e10eabdabbb 100644 (file)
@@ -3496,13 +3496,11 @@ int process_pg_map_command(
   if (prefix == "pg dump_json") {
     vector<string> v;
     v.push_back(string("all"));
-    cmd_putval(g_ceph_context, cmdmap, "format", string("json"));
     cmd_putval(g_ceph_context, cmdmap, "dumpcontents", v);
     prefix = "pg dump";
   } else if (prefix == "pg dump_pools_json") {
     vector<string> v;
     v.push_back(string("pools"));
-    cmd_putval(g_ceph_context, cmdmap, "format", string("json"));
     cmd_putval(g_ceph_context, cmdmap, "dumpcontents", v);
     prefix = "pg dump";
   } else if (prefix == "pg ls-by-primary") {