From 0f814f38e5d811d84fe07fe2d443c1038d53ca9a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 17 Dec 2018 15:06:49 -0600 Subject: [PATCH] pybind/mgr/mgr_module: make use of defined default value Signed-off-by: Sage Weil --- src/mgr/PyModule.cc | 24 ++++++++++++++++-------- src/pybind/mgr/mgr_module.py | 11 +++++++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index 7507144d06c..1233e72d9fe 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -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); } } } diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index e143468b20d..b620f630a46 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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 -- 2.39.5