]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/mgr_module: make use of defined default value
authorSage Weil <sage@redhat.com>
Mon, 17 Dec 2018 21:06:49 +0000 (15:06 -0600)
committerSage Weil <sage@redhat.com>
Fri, 21 Dec 2018 04:11:04 +0000 (22:11 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/PyModule.cc
src/pybind/mgr/mgr_module.py

index 7507144d06c15354c5f738894a4f94b95642a00f..1233e72d9fe1067408ebaf92bc433d8c3584bf5b 100644 (file)
@@ -538,23 +538,31 @@ int PyModule::load_options()
       option.long_desc = PyString_AsString(p);
     }
     p = PyDict_GetItemString(pOption, "default");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      option.default_value = PyString_AsString(p);
+    if (p) {
+      auto q = PyObject_Str(p);
+      option.default_value = PyString_AsString(q);
+      Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "min");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      option.min = PyString_AsString(p);
+    if (p) {
+      auto q = PyObject_Str(p);
+      option.min = PyString_AsString(q);
+      Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "max");
-    if (p && PyObject_TypeCheck(p, &PyString_Type)) {
-      option.max = PyString_AsString(p);
+    if (p) {
+      auto q = PyObject_Str(p);
+      option.max = PyString_AsString(q);
+      Py_DECREF(q);
     }
     p = PyDict_GetItemString(pOption, "enum_allowed");
     if (p && PyObject_TypeCheck(p, &PyList_Type)) {
       for (unsigned i = 0; i < PyList_Size(p); ++i) {
        auto q = PyList_GetItem(p, i);
-       if (q && PyObject_TypeCheck(q, &PyString_Type)) {
-         option.enum_allowed.insert(PyString_AsString(q));
+       if (q) {
+         auto r = PyObject_Str(q);
+         option.enum_allowed.insert(PyString_AsString(r));
+         Py_DECREF(r);
        }
       }
     }
index e143468b20dbc55545216fb0f6c3ff20372fc134..b620f630a46306b6188567834323ca97a675f29c 100644 (file)
@@ -242,7 +242,8 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
         """
         r = self._ceph_get_module_option(key)
         if r is None:
-            return default
+            final_key = key.split('/')[-1]
+            return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
         else:
             return r
 
@@ -273,6 +274,7 @@ class MgrStandbyModule(ceph_module.BaseMgrStandbyModule):
 class MgrModule(ceph_module.BaseMgrModule):
     COMMANDS = []
     MODULE_OPTIONS = []
+    MODULE_OPTION_DEFAULTS = {}
 
     # Priority definitions for perf counters
     PRIO_CRITICAL = 10
@@ -319,6 +321,10 @@ class MgrModule(ceph_module.BaseMgrModule):
         # Keep a librados instance for those that need it.
         self._rados = None
 
+        for o in self.MODULE_OPTIONS:
+            if 'default' in o:
+                self.MODULE_OPTION_DEFAULTS[o['name']] = o['default']
+
     def __del__(self):
         unconfigure_logger(self, self.module_name)
 
@@ -694,7 +700,8 @@ class MgrModule(ceph_module.BaseMgrModule):
     def _get_module_option(self, key, default):
         r = self._ceph_get_module_option(key)
         if r is None:
-            return default
+            final_key = key.split('/')[-1]
+            return str(self.MODULE_OPTION_DEFAULTS.get(final_key, default))
         else:
             return r