]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: handle commands sent to unavailable modules 21607/head
authorJohn Spray <john.spray@redhat.com>
Mon, 23 Apr 2018 21:15:22 +0000 (17:15 -0400)
committerJohn Spray <john.spray@redhat.com>
Mon, 23 Apr 2018 21:32:36 +0000 (17:32 -0400)
There are some up-front checks in DaemonServer
but it shouldn't assume that its checks are
necessarily going to match the choices about
how ActivePyModules composes its ::modules member,
so let's have some extra checks to avoid
risk of crashing mgr on commands sent to
unhealthy/unloaded modules.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/ActivePyModule.cc
src/mgr/ActivePyModules.cc

index 185ef445428849e40bce90a7be4462ff1562be95..2f52dd622620acaa90fcb56ceaa653fbe44455a8 100644 (file)
@@ -110,6 +110,13 @@ int ActivePyModule::handle_command(
   assert(ss != nullptr);
   assert(ds != nullptr);
 
+  if (pClassInstance == nullptr) {
+    // Not the friendliest error string, but we could only
+    // hit this in quite niche cases, if at all.
+    *ss << "Module not instantiated";
+    return -EINVAL;
+  }
+
   Gil gil(py_module->pMyThreadState, true);
 
   PyFormatter f;
index cc604d175a9eb316739d49a12ab5ba011f3d6f0a..4cb8a0883a9e247c345d0a0b4f85037c18b25403 100644 (file)
@@ -756,9 +756,14 @@ int ActivePyModules::handle_command(
   std::stringstream *ss)
 {
   lock.Lock();
-  auto mod = modules.at(module_name).get();
+  auto mod_iter = modules.find(module_name);
+  if (mod_iter == modules.end()) {
+    *ss << "Module '" << module_name << "' is not available";
+    return -ENOENT;
+  }
+
   lock.Unlock();
-  return mod->handle_command(cmdmap, ds, ss);
+  return mod_iter->second->handle_command(cmdmap, ds, ss);
 }
 
 void ActivePyModules::get_health_checks(health_check_map_t *checks)