]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: refactor get_modules/list_modules
authorJohn Spray <john.spray@redhat.com>
Thu, 14 Dec 2017 16:29:00 +0000 (11:29 -0500)
committerJohn Spray <john.spray@redhat.com>
Wed, 24 Jan 2018 18:08:21 +0000 (13:08 -0500)
list_modules is really about searching for them
on disk, so it's now probe_modules and private.

Both methods now return values instead of populating
an argument, since when called they were always writing into
a newly constructed container.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/MgrStandby.cc
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h

index 335e134141abd5914cbc8fbce82fd0e8376fe788..8aaaefccfbf5b63c401e4b76e2238bf2c0fb6570 100644 (file)
@@ -152,8 +152,7 @@ void MgrStandby::send_beacon()
   assert(lock.is_locked_by_me());
   dout(1) << state_str() << dendl;
 
-  std::list<PyModuleRef> modules;
-  py_module_registry.get_modules(&modules);
+  std::list<PyModuleRef> modules = py_module_registry.get_modules();
 
   // Construct a list of the info about each loaded module
   // which we will transmit to the monitor.
index 9a8b2684931c47f38ce90c8a8f38f45af0968aac..76ad1577075fadbc4e8c827a9a3efbf218661266 100644 (file)
@@ -69,8 +69,7 @@ int PyModuleRegistry::init(const MgrMap &map)
 
   std::list<std::string> failed_modules;
 
-  std::set<std::string> module_names;
-  list_modules(&module_names);
+  std::set<std::string> module_names = probe_modules();
   // Load python code
   for (const auto& module_name : module_names) {
     dout(1) << "Loading python module '" << module_name << "'" << dendl;
@@ -221,14 +220,16 @@ void PyModuleRegistry::shutdown()
   Py_Finalize();
 }
 
-static void _list_modules(
-  const std::string path,
-  std::set<std::string> *modules)
+std::set<std::string> PyModuleRegistry::probe_modules() const
 {
+  std::string path = g_conf->get_val<std::string>("mgr_module_path");
+
   DIR *dir = opendir(path.c_str());
   if (!dir) {
-    return;
+    return {};
   }
+
+  std::set<std::string> modules_out;
   struct dirent *entry = NULL;
   while ((entry = readdir(dir)) != NULL) {
     string n(entry->d_name);
@@ -239,17 +240,13 @@ static void _list_modules(
       string initfn = fn + "/module.py";
       r = ::stat(initfn.c_str(), &st);
       if (r == 0) {
-       modules->insert(n);
+       modules_out.insert(n);
       }
     }
   }
   closedir(dir);
-}
 
-void PyModuleRegistry::list_modules(std::set<std::string> *modules)
-{
-  g_conf->with_val<std::string>("mgr_module_path",
-                               &_list_modules, modules);
+  return modules_out;
 }
 
 int PyModuleRegistry::handle_command(
index 1064c19b15137b2e34f3811c9c0333098d0dc466..1f5a910d046701785b30b678a36fb6eae8b298f6 100644 (file)
@@ -54,17 +54,27 @@ private:
   // before ClusterState exists.
   MgrMap mgr_map;
 
+  /**
+   * Discover python modules from local disk
+   */
+  std::set<std::string> probe_modules() const;
+
 public:
   static std::string config_prefix;
 
-  void list_modules(std::set<std::string> *modules);
-
-  void get_modules(std::list<PyModuleRef> *modules_out)
+  /**
+   * Get references to all modules (whether they have loaded and/or
+   * errored) or not.
+   */
+  std::list<PyModuleRef> get_modules() const
   {
     Mutex::Locker l(lock);
+    std::list<PyModuleRef> modules_out;
     for (const auto &i : modules) {
-      modules_out->push_back(i.second);
+      modules_out.push_back(i.second);
     }
+
+    return modules_out;
   }
 
   PyModuleRegistry(LogChannelRef clog_)