]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Relocate cluster_log(). Only active modules can use it. 24239/head
authorVolker Theile <vtheile@suse.com>
Fri, 28 Sep 2018 12:55:32 +0000 (14:55 +0200)
committerVolker Theile <vtheile@suse.com>
Fri, 5 Oct 2018 12:46:58 +0000 (14:46 +0200)
Signed-off-by: Volker Theile <vtheile@suse.com>
12 files changed:
qa/tasks/mgr/test_module_selftest.py
src/mgr/ActivePyModule.h
src/mgr/ActivePyModules.cc
src/mgr/ActivePyModules.h
src/mgr/BaseMgrModule.cc
src/mgr/MgrStandby.cc
src/mgr/PyModuleRegistry.cc
src/mgr/PyModuleRegistry.h
src/mgr/PyModuleRunner.cc
src/mgr/PyModuleRunner.h
src/mgr/StandbyPyModules.cc
src/mgr/StandbyPyModules.h

index 44c38b04deddb977a4a512dbeb12a98cf2b85202..780f4751239401761780b52173e6b12e8552d11f 100644 (file)
@@ -296,10 +296,10 @@ class TestModuleSelftest(MgrTestCase):
         Use the selftest module to test the cluster/audit log interface.
         """
         priority_map = {
-            'info': 'INF',
-            'security': 'SEC',
-            'warning': 'WRN',
-            'error': 'ERR'
+            "info": "INF",
+            "security": "SEC",
+            "warning": "WRN",
+            "error": "ERR"
         }
         self._load_module("selftest")
         for priority in priority_map.keys():
@@ -318,3 +318,13 @@ class TestModuleSelftest(MgrTestCase):
                 self.mgr_cluster.mon_manager.raw_cluster_cmd(
                     "mgr", "self-test", "cluster-log", "audit",
                     priority, message)
+
+    def test_selftest_cluster_log_unknown_channel(self):
+        """
+        Use the selftest module to test the cluster/audit log interface.
+        """
+        with self.assertRaises(CommandFailedError) as exc_raised:
+            self.mgr_cluster.mon_manager.raw_cluster_cmd(
+                "mgr", "self-test", "cluster-log", "xyz",
+                "ERR", "The channel does not exist")
+        self.assertEqual(exc_raised.exception.exitstatus, errno.EOPNOTSUPP)
index 6b382bdc863db7187c809b58c844eec3b9aa7bd8..149d297faf13ef37e2872dc6eb43569dcad5d903 100644 (file)
@@ -44,8 +44,8 @@ private:
 
 public:
   ActivePyModule(const PyModuleRef &py_module_,
-      LogChannelRef clog_, LogChannelRef audit_clog_)
-    : PyModuleRunner(py_module_, clog_, audit_clog_)
+      LogChannelRef clog_)
+    : PyModuleRunner(py_module_, clog_)
   {}
 
   int load(ActivePyModules *py_modules);
index 7e22775bac7ced5d6a6c68cbb20d33953d4c7eb6..cb635ab12217cee0203c1fef3d8e20541007d66e 100644 (file)
@@ -377,7 +377,7 @@ int ActivePyModules::start_one(PyModuleRef py_module)
 
   ceph_assert(modules.count(py_module->get_name()) == 0);
 
-  modules[py_module->get_name()].reset(new ActivePyModule(py_module, clog, audit_clog));
+  modules[py_module->get_name()].reset(new ActivePyModule(py_module, clog));
   auto active_module = modules.at(py_module->get_name()).get();
 
   int r = active_module->load(this);
@@ -904,3 +904,15 @@ void ActivePyModules::remove_osd_perf_query(OSDPerfMetricQueryID query_id)
             << cpp_strerror(r) << dendl;
   }
 }
+
+void ActivePyModules::cluster_log(const std::string &channel, clog_type prio,
+  const std::string &message)
+{
+  Mutex::Locker l(lock);
+
+  if (channel == "audit") {
+    audit_clog->do_log(prio, message);
+  } else {
+    clog->do_log(prio, message);
+  }
+}
index 48302d63ac5b7f33b6e70d788866379c46707cd5..16f781e03a75867f20f0c8f7841232adfb3ef9f6 100644 (file)
@@ -157,5 +157,8 @@ public:
   void dump_server(const std::string &hostname,
                    const DaemonStateCollection &dmc,
                    Formatter *f);
+
+  void cluster_log(const std::string &channel, clog_type prio,
+    const std::string &message);
 };
 
index 91687b6c8a108dacb9cf6a13b9bfe14349587b02..5c587b91cbc326ee0edc68872c4fa414bad6cd4f 100644 (file)
@@ -484,13 +484,22 @@ ceph_cluster_log(BaseMgrModule *self, PyObject *args)
   int prio = 0;
   char *channel = nullptr;
   char *message = nullptr;
+  std::vector<std::string> channels = { "audit", "cluster" };
+
   if (!PyArg_ParseTuple(args, "sis:ceph_cluster_log", &channel, &prio, &message)) {
     return nullptr;
   }
 
-  ceph_assert(self->this_module);
+  if (std::find(channels.begin(), channels.end(), std::string(channel)) == channels.end()) {
+    std::string msg("Unknown channel: ");
+    msg.append(channel);
+    PyErr_SetString(PyExc_ValueError, msg.c_str());
+    return nullptr;
+  }
 
-  self->this_module->cluster_log(channel, (clog_type)prio, message);
+  PyThreadState *tstate = PyEval_SaveThread();
+  self->py_modules->cluster_log(channel, (clog_type)prio, message);
+  PyEval_RestoreThread(tstate);
 
   Py_RETURN_NONE;
 }
@@ -709,7 +718,7 @@ PyMethodDef BaseMgrModule_methods[] = {
    "Emit a (local) log message"},
 
   {"_ceph_cluster_log", (PyCFunction)ceph_cluster_log, METH_VARARGS,
-   "Emit an cluster log message"},
+   "Emit a cluster log message"},
 
   {"_ceph_get_version", (PyCFunction)ceph_get_version, METH_VARARGS,
    "Get the ceph version of this process"},
index ae4b853d15928ba33ed1713875eaf49c05736ec7..d90b799f57772346683299a5f58affee13375ab5 100644 (file)
@@ -54,7 +54,7 @@ MgrStandby::MgrStandby(int argc, const char **argv) :
   audit_clog(log_client.create_channel(CLOG_CHANNEL_AUDIT)),
   lock("MgrStandby::lock"),
   timer(g_ceph_context, lock),
-  py_module_registry(clog, audit_clog),
+  py_module_registry(clog),
   active_mgr(nullptr),
   orig_argc(argc),
   orig_argv(argv),
index 0f48d6bbd0e7de7132f3f66c5ce31ed0160d7eee..6966bd1aefa1c6195742736f78d797b5a8b95685 100644 (file)
@@ -141,7 +141,7 @@ void PyModuleRegistry::standby_start(MonClient &mc)
   dout(4) << "Starting modules in standby mode" << dendl;
 
   standby_modules.reset(new StandbyPyModules(
-        mgr_map, module_config, clog, audit_clog, mc));
+        mgr_map, module_config, clog, mc));
 
   std::set<std::string> failed_modules;
   for (const auto &i : modules) {
index 06e49b2e2ad34489eb22f9292e8cc1e5659f73ae..1657d67b38f672deb999387b0f845088901637de 100644 (file)
@@ -38,7 +38,7 @@ class PyModuleRegistry
 {
 private:
   mutable Mutex lock{"PyModuleRegistry::lock"};
-  LogChannelRef clog, audit_clog;
+  LogChannelRef clog;
 
   std::map<std::string, PyModuleRef> modules;
 
@@ -76,8 +76,8 @@ public:
     return modules_out;
   }
 
-  explicit PyModuleRegistry(LogChannelRef clog_, LogChannelRef audit_clog_)
-    : clog(clog_), audit_clog(audit_clog_)
+  explicit PyModuleRegistry(LogChannelRef clog_)
+    : clog(clog_)
   {}
 
   /**
index b6f7f07853fecb10550e7b6ca7dc62c0ea769162..403c8a9f183f30c4972e9c4d93d4f44229fb09cc 100644 (file)
@@ -99,16 +99,6 @@ void PyModuleRunner::log(int level, const std::string &record)
 #define dout_prefix *_dout << "mgr " << __func__ << " "
 }
 
-void PyModuleRunner::cluster_log(const std::string &channel, clog_type prio,
-    const std::string &message)
-{
-    if (std::string(channel) == "audit") {
-        audit_clog->do_log(prio, message);
-    } else {
-        clog->do_log(prio, message);
-    }
-}
-
 void* PyModuleRunner::PyModuleRunnerThread::entry()
 {
   // No need to acquire the GIL here; the module does it.
index 550f544d196ebf51983345bb2e60fb472a902660..fb58bf0c2323f1a0920d8034d80fce261068cb9c 100644 (file)
@@ -33,7 +33,7 @@ protected:
   // Populated by descendent class
   PyObject *pClassInstance = nullptr;
 
-  LogChannelRef clog, audit_clog;
+  LogChannelRef clog;
 
   class PyModuleRunnerThread : public Thread
   {
@@ -52,8 +52,6 @@ public:
   int serve();
   void shutdown();
   void log(int level, const std::string &record);
-  void cluster_log(const std::string &channel, clog_type prio,
-    const std::string &message);
 
   const char *get_thread_name() const
   {
@@ -62,12 +60,10 @@ public:
 
   PyModuleRunner(
       const PyModuleRef &py_module_,
-      LogChannelRef clog_,
-      LogChannelRef audit_clog_)
+      LogChannelRef clog_)
     : 
       py_module(py_module_),
       clog(clog_),
-      audit_clog(audit_clog_),
       thread(this)
   {
     // Shortened name for use as thread name, because thread names
index 259d70fe0b12c80571528b3b4d3533178af0daa1..f2d1eeb45b8d4a01ba6cf65d0f6ba4f9d7ee864b 100644 (file)
@@ -36,11 +36,9 @@ StandbyPyModules::StandbyPyModules(
     const MgrMap &mgr_map_,
     PyModuleConfig &module_config,
     LogChannelRef clog_,
-    LogChannelRef audit_clog_,
     MonClient &monc_)
     : state(module_config, monc_),
-      clog(clog_),
-      audit_clog(audit_clog_)
+      clog(clog_)
 {
   state.set_mgr_map(mgr_map_);
 }
@@ -83,7 +81,7 @@ int StandbyPyModules::start_one(PyModuleRef py_module)
 
   modules[module_name].reset(new StandbyPyModule(
       state,
-      py_module, clog, audit_clog));
+      py_module, clog));
 
   int r = modules[module_name]->load();
   if (r != 0) {
index 28abc2593ac88b59bb8ff509922000520cb99c3a..f443ba67e7947ebeda2ceeb5ae00e279398c048e 100644 (file)
@@ -81,10 +81,9 @@ class StandbyPyModule : public PyModuleRunner
   StandbyPyModule(
       StandbyPyModuleState &state_,
       const PyModuleRef &py_module_,
-      LogChannelRef clog_,
-      LogChannelRef audit_clog_)
+      LogChannelRef clog_)
     :
-      PyModuleRunner(py_module_, clog_, audit_clog_),
+      PyModuleRunner(py_module_, clog_),
       state(state_)
   {
   }
@@ -104,7 +103,7 @@ private:
 
   StandbyPyModuleState state;
 
-  LogChannelRef clog, audit_clog;
+  LogChannelRef clog;
 
 public:
 
@@ -112,7 +111,6 @@ public:
       const MgrMap &mgr_map_,
       PyModuleConfig &module_config,
       LogChannelRef clog_,
-      LogChannelRef audit_clog_,
       MonClient &monc);
 
   int start_one(PyModuleRef py_module);