]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: Improve ActivePyModules::get_typed_config implementation 26149/head
authorVolker Theile <vtheile@suse.com>
Fri, 25 Jan 2019 13:45:01 +0000 (14:45 +0100)
committerVolker Theile <vtheile@suse.com>
Mon, 11 Feb 2019 13:20:19 +0000 (14:20 +0100)
- Remove PyModuleRegistry::module_exists method
- Refactor PyModuleRegistry::get_module method

Signed-off-by: Volker Theile <vtheile@suse.com>
src/mgr/ActivePyModules.cc
src/mgr/DaemonServer.cc
src/mgr/PyModuleRegistry.h

index 1f185714972c14f636d8c51e6b16f8dbb302b026..06b478c4ec1a91f617c3e9de469551e04f043d42 100644 (file)
@@ -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);
   }
index f256c2c548daf9fc97dd301a20a8171a2bb92c30..be403112bf7b451a4a5925d31a0701a8cd18b9d3 100644 (file)
@@ -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 "
index eccc2bfb0f6a63dc021fc84f128b0184a57a71dd..78555453137a2ac338c6cebafcd45d0dc52e8e80 100644 (file)
@@ -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;
   }
 
   /**