From: Tim Serong Date: Fri, 22 Nov 2019 09:25:19 +0000 (+1100) Subject: mgr/PyModule: correctly remove config options X-Git-Tag: v15.1.0~780^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F31807%2Fhead;p=ceph.git mgr/PyModule: correctly remove config options Previously, incorrect parameters were being passed to "config rm", causing it to do nothing. This commit also ensures the correct error message is shown for both the set and remove failure cases. I've also moved the update of the in-memory config map to *after* the value is persisted, to ensure the config map actually reflects what's stored. Fixes: https://tracker.ceph.com/issues/42958 Signed-off-by: Tim Serong --- diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index e65b46befff10..e4c20ae452a75 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -145,16 +145,6 @@ void PyModuleConfig::set_config( { const std::string global_key = PyModule::config_prefix + module_name + "/" + key; - { - std::lock_guard l(lock); - - if (val) { - config[global_key] = *val; - } else { - config.erase(global_key); - } - } - Command set_cmd; { std::ostringstream cmd_json; @@ -162,23 +152,33 @@ void PyModuleConfig::set_config( jf.open_object_section("cmd"); if (val) { jf.dump_string("prefix", "config set"); - jf.dump_string("who", "mgr"); - jf.dump_string("name", global_key); jf.dump_string("value", *val); } else { jf.dump_string("prefix", "config rm"); - jf.dump_string("name", "mgr"); - jf.dump_string("key", global_key); } + jf.dump_string("who", "mgr"); + jf.dump_string("name", global_key); jf.close_section(); jf.flush(cmd_json); set_cmd.run(monc, cmd_json.str()); } set_cmd.wait(); - if (set_cmd.r != 0) { - dout(0) << "`config set mgr" << global_key << " " << val << "` failed: " - << cpp_strerror(set_cmd.r) << dendl; + if (set_cmd.r == 0) { + std::lock_guard l(lock); + if (val) { + config[global_key] = *val; + } else { + config.erase(global_key); + } + } else { + if (val) { + dout(0) << "`config set mgr " << global_key << " " << val << "` failed: " + << cpp_strerror(set_cmd.r) << dendl; + } else { + dout(0) << "`config rm mgr " << global_key << "` failed: " + << cpp_strerror(set_cmd.r) << dendl; + } dout(0) << "mon returned " << set_cmd.r << ": " << set_cmd.outs << dendl; } }