]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/admin: read non-string settings as well
authorKefu Chai <kchai@redhat.com>
Tue, 4 Aug 2020 07:20:46 +0000 (15:20 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 4 Aug 2020 07:28:47 +0000 (15:28 +0800)
before this change, we were using

local_conf().get_val<std::string>(var);

for reading a setting when serving a "config get" command even if the
setting being queried is a non-string. so without this change, a failure
is returned complaining "unrecognized option..."

in this change:

* use get_val(string,string*) for querying the string representation
  of the queried setting
* drop the check for existence of "var" parameter, validate_cmd()
  always take care of this.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/admin/admin_socket.cc

index d70eb28fd3bc56c4327a223b70b2991cf2ce7838..5c3da6fa5d1761ae8480ffa753e5b4afd667eccf 100644 (file)
@@ -452,25 +452,21 @@ public:
                                       ceph::bufferlist&& input) const final
   {
     std::string var;
-    if (!cmd_getval(cmdmap, "var", var)) {
-      // should have been caught by 'validate()'
-      return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, "syntax error: 'config get <var>'"});
-    }
-    try {
-      unique_ptr<Formatter> f{Formatter::create(format,
-                                                "json-pretty",
-                                                "json-pretty")};
-      f->open_object_section("config_get");
-      std::string conf_val =
-        local_conf().get_val<std::string>(var);
-      f->dump_string(var.c_str(), conf_val.c_str());
-      f->close_section();
-      return seastar::make_ready_future<tell_result_t>(f.get());
-    } catch (const boost::bad_get&) {
+    [[maybe_unused]] bool found = cmd_getval(cmdmap, "var", var);
+    assert(found);
+    std::string conf_val;
+    if (int r = local_conf().get_val(var, &conf_val); r < 0) {
       return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, fmt::format("unrecognized option {}", var)});
+        tell_result_t{r, fmt::format("error getting {}: {}",
+                                     var, cpp_strerror(r))});
     }
+    unique_ptr<Formatter> f{Formatter::create(format,
+                                              "json-pretty",
+                                              "json-pretty")};
+    f->open_object_section("config_get");
+    f->dump_string(var, conf_val);
+    f->close_section();
+    return seastar::make_ready_future<tell_result_t>(f.get());
   }
 };