Skip to content

Commit

Permalink
mgr/PyModule: correctly remove config options
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tserong committed Nov 22, 2019
1 parent 4c3127d commit 0520ff5
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/mgr/PyModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,40 @@ 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;
JSONFormatter jf;
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;
}
}
Expand Down

0 comments on commit 0520ff5

Please sign in to comment.