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():
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)
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);
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);
<< 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);
+ }
+}
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);
};
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;
}
"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"},
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),
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) {
{
private:
mutable Mutex lock{"PyModuleRegistry::lock"};
- LogChannelRef clog, audit_clog;
+ LogChannelRef clog;
std::map<std::string, PyModuleRef> modules;
return modules_out;
}
- explicit PyModuleRegistry(LogChannelRef clog_, LogChannelRef audit_clog_)
- : clog(clog_), audit_clog(audit_clog_)
+ explicit PyModuleRegistry(LogChannelRef clog_)
+ : clog(clog_)
{}
/**
#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.
// Populated by descendent class
PyObject *pClassInstance = nullptr;
- LogChannelRef clog, audit_clog;
+ LogChannelRef clog;
class PyModuleRunnerThread : public Thread
{
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
{
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
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_);
}
modules[module_name].reset(new StandbyPyModule(
state,
- py_module, clog, audit_clog));
+ py_module, clog));
int r = modules[module_name]->load();
if (r != 0) {
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_)
{
}
StandbyPyModuleState state;
- LogChannelRef clog, audit_clog;
+ LogChannelRef clog;
public:
const MgrMap &mgr_map_,
PyModuleConfig &module_config,
LogChannelRef clog_,
- LogChannelRef audit_clog_,
MonClient &monc);
int start_one(PyModuleRef py_module);