]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/PyModule: initialize options on standby class too 33897/head
authorSage Weil <sage@redhat.com>
Wed, 11 Mar 2020 17:14:59 +0000 (12:14 -0500)
committerSage Weil <sage@redhat.com>
Thu, 12 Mar 2020 03:42:23 +0000 (22:42 -0500)
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 <sage@redhat.com>
src/mgr/PyModule.cc
src/mgr/PyModule.h
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/mgr_module.py

index 004325a3c6f5a0144b0703c596f2c3825baaa6e5..016a6cf7df5ec138fe96c772aa676a0b0f4cfaf8 100644 (file)
@@ -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<char*>("_register_options"), const_cast<char*>("(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,
index 2f980bdf50997d8fd974a877b3a574eaf0905c53..6d555a81a2deb1c06a91f768d3b506ad4f6392c0 100644 (file)
@@ -81,6 +81,7 @@ private:
   int load_commands();
   std::vector<ModuleCommand> commands;
 
+  int register_options(PyObject *cls);
   int load_options();
   std::map<std::string, MgrMap::ModuleOption> options;
 
index 445c9a75b33b0bf55b42ef5ff981a30f3d78dc3c..247cb7e2ad531aed7a5f546dd4d5be9da16e10df 100644 (file)
@@ -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 = {
index c91d405f4c56c7f61b74fc63682a367e454d1df4..72386e236a8d14e0654f9b3ae3f2e4f3cfcb1007 100644 (file)
@@ -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