diff options
author | Volker Theile <vtheile@suse.com> | 2019-01-25 14:45:01 +0100 |
---|---|---|
committer | Volker Theile <vtheile@suse.com> | 2019-02-11 14:20:19 +0100 |
commit | 5ac9e85a213017322e0fbdc604a9fc26f157a815 (patch) | |
tree | 6b805f935570bf4b10fd0ae9857590e59111054d /src/mgr | |
parent | Merge pull request #26360 from rhcs-dashboard/wip-38254-master (diff) | |
download | ceph-5ac9e85a213017322e0fbdc604a9fc26f157a815.tar.xz ceph-5ac9e85a213017322e0fbdc604a9fc26f157a815.zip |
mgr: Improve ActivePyModules::get_typed_config implementation
- Remove PyModuleRegistry::module_exists method
- Refactor PyModuleRegistry::get_module method
Signed-off-by: Volker Theile <vtheile@suse.com>
Diffstat (limited to 'src/mgr')
-rw-r--r-- | src/mgr/ActivePyModules.cc | 10 | ||||
-rw-r--r-- | src/mgr/DaemonServer.cc | 1 | ||||
-rw-r--r-- | src/mgr/PyModuleRegistry.h | 19 |
3 files changed, 15 insertions, 15 deletions
diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 1f185714972..06b478c4ec1 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -529,15 +529,15 @@ PyObject *ActivePyModules::get_typed_config( const std::string &module_name, const std::string &key) const { - if (!py_module_registry.module_exists(module_name)) { - derr << "Module '" << module_name << "' is not available" << dendl; - Py_RETURN_NONE; - } - std::string value; bool found = get_config(module_name, key, &value); if (found) { PyModuleRef module = py_module_registry.get_module(module_name); + if (!module) { + derr << "Module '" << module_name << "' is not available" << dendl; + Py_RETURN_NONE; + } + dout(10) << __func__ << " " << key << " found: " << value << dendl; return module->get_typed_option_value(key, value); } diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index f256c2c548d..be403112bf7 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -2082,6 +2082,7 @@ bool DaemonServer::_handle_command( // Validate that the module is enabled PyModuleRef module = py_modules.get_module(handler_name); + ceph_assert(module); if (!module->is_enabled()) { ss << "Module '" << handler_name << "' is not enabled (required by " "command '" << prefix << "'): use `ceph mgr module enable " diff --git a/src/mgr/PyModuleRegistry.h b/src/mgr/PyModuleRegistry.h index eccc2bfb0f6..78555453137 100644 --- a/src/mgr/PyModuleRegistry.h +++ b/src/mgr/PyModuleRegistry.h @@ -113,20 +113,19 @@ public: std::vector<ModuleCommand> get_py_commands() const; /** - * module_name **must** exist, but does not have to be loaded - * or runnable. + * Get the specified module. The module does not have to be + * loaded or runnable. + * + * Returns an empty reference if it does not exist. */ PyModuleRef get_module(const std::string &module_name) { std::lock_guard l(lock); - return modules.at(module_name); - } - - bool module_exists(const std::string &module_name) const - { - std::lock_guard l(lock); - auto mod_iter = modules.find(module_name); - return mod_iter != modules.end(); + auto module_iter = modules.find(module_name); + if (module_iter == modules.end()) { + return {}; + } + return module_iter->second; } /** |