From: Kefu Chai Date: Wed, 2 Aug 2017 10:18:02 +0000 (+0800) Subject: mgr: handle "module.set_config(.., None)" correctly X-Git-Tag: v12.1.3~120^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=868420e4219fd11ef12f713c0378a6565f36f1d3;p=ceph-ci.git mgr: handle "module.set_config(.., None)" correctly otherwise "ceph restful delete-key foo" would fail: TypeError: ceph_config_set() argument 3 must be string, not None Signed-off-by: Kefu Chai --- diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index 2961394bcb6..d8b7b01cc62 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -577,7 +577,7 @@ PyObject *PyModules::get_config_prefix(const std::string &handle, } void PyModules::set_config(const std::string &handle, - const std::string &key, const std::string &val) + const std::string &key, const boost::optional& val) { const std::string global_key = config_prefix + handle + "/" + key; @@ -586,18 +586,25 @@ void PyModules::set_config(const std::string &handle, PyThreadState *tstate = PyEval_SaveThread(); Mutex::Locker l(lock); PyEval_RestoreThread(tstate); - config_cache[global_key] = val; + if (val) { + config_cache[global_key] = *val; + } else { + config_cache.erase(global_key); + } std::ostringstream cmd_json; - JSONFormatter jf; jf.open_object_section("cmd"); - jf.dump_string("prefix", "config-key set"); - jf.dump_string("key", global_key); - jf.dump_string("val", val); + if (val) { + jf.dump_string("prefix", "config-key set"); + jf.dump_string("key", global_key); + jf.dump_string("val", *val); + } else { + jf.dump_string("prefix", "config-key del"); + jf.dump_string("key", global_key); + } jf.close_section(); jf.flush(cmd_json); - set_cmd.run(&monc, cmd_json.str()); } set_cmd.wait(); diff --git a/src/mgr/PyModules.h b/src/mgr/PyModules.h index 431abec76f0..c7aad4e5df8 100644 --- a/src/mgr/PyModules.h +++ b/src/mgr/PyModules.h @@ -114,7 +114,7 @@ public: PyObject *get_config_prefix(const std::string &handle, const std::string &prefix) const; void set_config(const std::string &handle, - const std::string &key, const std::string &val); + const std::string &key, const boost::optional &val); void set_health_checks(const std::string& handle, health_check_map_t&& checks); diff --git a/src/mgr/PyState.cc b/src/mgr/PyState.cc index c8d3c73ff80..f03929102e4 100644 --- a/src/mgr/PyState.cc +++ b/src/mgr/PyState.cc @@ -359,11 +359,14 @@ ceph_config_set(PyObject *self, PyObject *args) char *handle = nullptr; char *key = nullptr; char *value = nullptr; - if (!PyArg_ParseTuple(args, "sss:ceph_config_set", &handle, &key, &value)) { + if (!PyArg_ParseTuple(args, "ssz:ceph_config_set", &handle, &key, &value)) { return nullptr; } - - global_handle->set_config(handle, key, value); + boost::optional val; + if (value) { + val = value; + } + global_handle->set_config(handle, key, val); Py_RETURN_NONE; }