From 3eeaefddb98b76e319b47891d6cb41cff48cccff Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 11 Mar 2020 12:14:59 -0500 Subject: [PATCH] mgr/PyModule: initialize options on standby class too Create a separate callback (_register_options) and call that on both the regular MgrModule and MgrStandbyModule. Fixes: https://tracker.ceph.com/issues/44562 Signed-off-by: Sage Weil --- src/mgr/PyModule.cc | 18 ++++++++++++++++++ src/mgr/PyModule.h | 1 + src/pybind/mgr/cephadm/tests/fixtures.py | 1 + src/pybind/mgr/mgr_module.py | 22 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index 004325a3c6f..016a6cf7df5 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -371,6 +371,7 @@ int PyModule::load(PyThreadState *pMainThreadState) return r; } + register_options(pClass); r = load_options(); if (r != 0) { derr << "Missing or invalid MODULE_OPTIONS attribute in module '" @@ -388,6 +389,7 @@ int PyModule::load(PyThreadState *pMainThreadState) if (!r) { dout(4) << "Standby mode available in module '" << module_name << "'" << dendl; + register_options(pStandbyClass); } else { dout(4) << "Standby mode not provided by module '" << module_name << "'" << dendl; @@ -473,6 +475,22 @@ int PyModule::walk_dict_list( return r; } +int PyModule::register_options(PyObject *cls) +{ + PyObject *pRegCmd = PyObject_CallMethod( + cls, + const_cast("_register_options"), const_cast("(s)"), + module_name.c_str()); + if (pRegCmd != nullptr) { + Py_DECREF(pRegCmd); + } else { + derr << "Exception calling _register_options on " << get_name() + << dendl; + derr << handle_pyerror() << dendl; + } + return 0; +} + int PyModule::load_commands() { PyObject *pRegCmd = PyObject_CallMethod(pClass, diff --git a/src/mgr/PyModule.h b/src/mgr/PyModule.h index 2f980bdf509..6d555a81a2d 100644 --- a/src/mgr/PyModule.h +++ b/src/mgr/PyModule.h @@ -81,6 +81,7 @@ private: int load_commands(); std::vector commands; + int register_options(PyObject *cls); int load_options(); std::map options; diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index 445c9a75b33..247cb7e2ad5 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -64,6 +64,7 @@ def cephadm_module(): mock.patch("cephadm.module.CephadmOrchestrator.get_store_prefix", get_store_prefix): CephadmOrchestrator._register_commands('') + CephadmOrchestrator._register_options('') m = CephadmOrchestrator.__new__ (CephadmOrchestrator) m._root_logger = mock.MagicMock() m._store = { diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index c91d405f4c5..72386e236a8 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -601,6 +601,24 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule, MgrModuleLoggingMixin): def __del__(self): self._unconfigure_logging() + @classmethod + def _register_options(cls, module_name): + cls.MODULE_OPTIONS.append( + Option(name='log_level', type='str', default="", runtime=True, + enum_allowed=['info', 'debug', 'critical', 'error', + 'warning', ''])) + cls.MODULE_OPTIONS.append( + Option(name='log_to_file', type='bool', default=False, runtime=True)) + if not [x for x in cls.MODULE_OPTIONS if x['name'] == 'log_to_cluster']: + cls.MODULE_OPTIONS.append( + Option(name='log_to_cluster', type='bool', default=False, + runtime=True)) + cls.MODULE_OPTIONS.append( + Option(name='log_to_cluster_level', type='str', default='info', + runtime=True, + enum_allowed=['info', 'debug', 'critical', 'error', + 'warning', ''])) + @property def log(self): return self._logger @@ -724,7 +742,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): self._unconfigure_logging() @classmethod - def _register_commands(cls, module_name): + def _register_options(cls, module_name): cls.MODULE_OPTIONS.append( Option(name='log_level', type='str', default="", runtime=True, enum_allowed=['info', 'debug', 'critical', 'error', @@ -741,6 +759,8 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): enum_allowed=['info', 'debug', 'critical', 'error', 'warning', ''])) + @classmethod + def _register_commands(cls, module_name): cls.COMMANDS.extend(CLICommand.dump_cmd_list()) @property -- 2.39.5