]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr/mgr_module: normalize defaults to str when type is missing
authorSage Weil <sage@redhat.com>
Wed, 19 Dec 2018 22:59:09 +0000 (16:59 -0600)
committerSage Weil <sage@redhat.com>
Fri, 21 Dec 2018 04:11:40 +0000 (22:11 -0600)
If the module doesn't specify a type for the option, it is probably
an older module.  Make sure that the default value we provide is normalized
to a string, just in case the module declares something like

  {
     'name': 'my_option',
     'default': True,
  }

where the default is *not* a string, but an user-set value coming from
the config infrastructure would be a string.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/mgr_module.py

index 3fdd46d502106b080075a7a4232653b4d06a0952..617fe5429d4ec3d4d6dbe3c43b37ea4f052a81fc 100644 (file)
@@ -323,7 +323,15 @@ class MgrModule(ceph_module.BaseMgrModule):
 
         for o in self.MODULE_OPTIONS:
             if 'default' in o:
-                self.MODULE_OPTION_DEFAULTS[o['name']] = o['default']
+                if 'type' in o:
+                    # we'll assume the declared type matches the
+                    # supplied default value's type.
+                    self.MODULE_OPTION_DEFAULTS[o['name']] = o['default']
+                else:
+                    # module not declaring it's type, so normalize the
+                    # default value to be a string for consistent behavior
+                    # with default and user-supplied option values.
+                    self.MODULE_OPTION_DEFAULTS[o['name']] = str(o['default'])
 
     def __del__(self):
         unconfigure_logger(self, self.module_name)