]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: rename get_option -> get_ceph_option 25402/head
authorSage Weil <sage@redhat.com>
Tue, 4 Dec 2018 23:34:18 +0000 (17:34 -0600)
committerSage Weil <sage@redhat.com>
Tue, 11 Dec 2018 09:54:52 +0000 (03:54 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
15 files changed:
doc/mgr/plugins.rst
src/pybind/mgr/balancer/module.py
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/dashboard/settings.py
src/pybind/mgr/dashboard/tests/test_access_control.py
src/pybind/mgr/dashboard/tests/test_api_auditing.py
src/pybind/mgr/dashboard/tests/test_grafana.py
src/pybind/mgr/dashboard/tests/test_rest_client.py
src/pybind/mgr/dashboard/tests/test_rgw_client.py
src/pybind/mgr/dashboard/tests/test_settings.py
src/pybind/mgr/dashboard/tests/test_sso.py
src/pybind/mgr/devicehealth/module.py
src/pybind/mgr/diskprediction_cloud/module.py
src/pybind/mgr/diskprediction_local/module.py
src/pybind/mgr/mgr_module.py

index d1196dea6f7c5739fd4cd70797f7120605f12c06..c3c2c8c587070f07c712e819c3c1eba02ae8a9ac 100644 (file)
@@ -96,38 +96,38 @@ Configuration options
 ---------------------
 
 Modules can load and store configuration options using the
-``set_config`` and ``get_config`` methods.
+``set_module_option`` and ``get_module_option`` methods.
 
-.. note:: Use ``set_config`` and ``get_config`` to manage user-visible
-   configuration options that are not blobs (like certificates). If you want to
-   persist module-internal data or binary configuration data consider using
-   the `KV store`_.
+.. note:: Use ``set_module_option`` and ``get_module_option`` to
+   manage user-visible configuration options that are not blobs (like
+   certificates). If you want to persist module-internal data or
+   binary configuration data consider using the `KV store`_.
 
 You must declare your available configuration options in the
-``OPTIONS`` class attribute, like this:
+``MODULE_OPTIONS`` class attribute, like this:
 
 ::
 
-    OPTIONS = [
+    MODULE_OPTIONS = [
         {
             "name": "my_option"
         }
     ]
 
-If you try to use set_config or get_config on options not declared
-in ``OPTIONS``, an exception will be raised.
+If you try to use set_module_option or get_module_option on options not declared
+in ``MODULE_OPTIONS``, an exception will be raised.
 
 You may choose to provide setter commands in your module to perform
 high level validation.  Users can also modify configuration using
 the normal `ceph config set` command, where the configuration options
 for a mgr module are named like `mgr/<module name>/<option>`.
 
-If a configuration option is different depending on which node
-the mgr is running on, then use *localized* configuration (
-``get_localized_config``, ``set_localized_config``).  This may be necessary
-for options such as what address to listen on.  Localized options may
-also be set externally with ``ceph config set``, where they key name
-is like ``mgr/<module name>/<mgr id>/<option>``
+If a configuration option is different depending on which node the mgr
+is running on, then use *localized* configuration (
+``get_localized_module_option``, ``set_localized_module_option``).
+This may be necessary for options such as what address to listen on.
+Localized options may also be set externally with ``ceph config set``,
+where they key name is like ``mgr/<module name>/<mgr id>/<option>``
 
 If you need to load and store data (e.g. something larger, binary, or multiline),
 use the KV store instead of configuration options (see next section).
@@ -135,21 +135,21 @@ use the KV store instead of configuration options (see next section).
 Hints for using config options:
 
 * Reads are fast: ceph-mgr keeps a local in-memory copy, so in many cases
-  you can just do a get_config every time you use a option, rather than
+  you can just do a get_module_option every time you use a option, rather than
   copying it out into a variable.
 * Writes block until the value is persisted (i.e. round trip to the monitor),
   but reads from another thread will see the new value immediately.
 * If a user has used `config set` from the command line, then the new
-  value will become visible to `get_config` immediately, although the
+  value will become visible to `get_module_option` immediately, although the
   mon->mgr update is asynchronous, so `config set` will return a fraction
   of a second before the new value is visible on the mgr.
 * To delete a config value (i.e. revert to default), just pass ``None`` to
-  set_config.
+  set_module_option.
 
-.. automethod:: MgrModule.get_config
-.. automethod:: MgrModule.set_config
-.. automethod:: MgrModule.get_localized_config
-.. automethod:: MgrModule.set_localized_config
+.. automethod:: MgrModule.get_module_option
+.. automethod:: MgrModule.set_module_option
+.. automethod:: MgrModule.get_localized_module_option
+.. automethod:: MgrModule.set_localized_module_option
 
 KV store
 --------
@@ -373,7 +373,7 @@ Limitations
 -----------
 
 It is not possible to call back into C++ code from a module's
-``__init__()`` method.  For example calling ``self.get_config()`` at
+``__init__()`` method.  For example calling ``self.get_module_option()`` at
 this point will result in an assertion failure in ceph-mgr.  For modules
 that implement the ``serve()`` method, it usually makes sense to do most
 initialization inside that method instead.
index 330a4fde28d4b3bfbfd39ada1126ad087cbbf570..fb910c2f1ff3571bab55a14e27c357bc7fda8ad0 100644 (file)
@@ -647,7 +647,7 @@ class Module(MgrModule):
     def optimize(self, plan):
         self.log.info('Optimize plan %s' % plan.name)
         plan.mode = self.get_module_option('mode', default_mode)
-        max_misplaced = float(self.get_option('target_max_misplaced_ratio'))
+        max_misplaced = float(self.get_ceph_option('target_max_misplaced_ratio'))
         self.log.info('Mode %s, max misplaced %f' %
                       (plan.mode, max_misplaced))
 
@@ -731,7 +731,7 @@ class Module(MgrModule):
         step = float(self.get_module_option('crush_compat_step', .5))
         if step <= 0 or step >= 1.0:
             return -errno.EINVAL, '"crush_compat_step" must be in (0, 1)'
-        max_misplaced = float(self.get_option('target_max_misplaced_ratio'))
+        max_misplaced = float(self.get_ceph_option('target_max_misplaced_ratio'))
         min_pg_per_osd = 2
 
         ms = plan.initial
index c7fb0368a6419c6fbd1a82ac9b8a73f05cea169b..35560e7bc27d91d00ebebd7e3336b8ab38aa93ec 100644 (file)
@@ -180,7 +180,7 @@ class CherryPyConfig(object):
         cherrypy.config.update(config)
 
         self._url_prefix = prepare_url_prefix(self.get_module_option('url_prefix',
-                                                              default=''))
+                                                                     default=''))
 
         uri = "{0}://{1}:{2}{3}/".format(
             'https' if ssl else 'http',
index 502181ba3b412e95d6f01c37262d3a87af0ff49d..7c0ea15411af096effa986eb1f8c72647ce8583b 100644 (file)
@@ -49,8 +49,9 @@ class Options(object):
 class SettingsMeta(type):
     def __getattr__(cls, attr):
         default, stype = getattr(Options, attr)
-        if stype == bool and str(mgr.get_module_option(attr,
-                                                default)).lower() == 'false':
+        if stype == bool and str(mgr.get_module_option(
+                attr,
+                default)).lower() == 'false':
             value = False
         else:
             value = stype(mgr.get_module_option(attr, default))
index 74414aa23e365571d3a63a13d2f377eb0bc596ee..bad47a42a45766955f96a7b56b0c80b8b2939d25 100644 (file)
@@ -20,19 +20,20 @@ class AccessControlTest(unittest.TestCase):
     CONFIG_KEY_DICT = {}
 
     @classmethod
-    def mock_set_config(cls, attr, val):
+    def mock_set_module_option(cls, attr, val):
         cls.CONFIG_KEY_DICT[attr] = val
 
     @classmethod
-    def mock_get_config(cls, attr, default=None):
+    def mock_get_module_option(cls, attr, default=None):
         return cls.CONFIG_KEY_DICT.get(attr, default)
 
     @classmethod
     def setUpClass(cls):
-        mgr.set_config.side_effect = cls.mock_set_config
-        mgr.get_config.side_effect = cls.mock_get_config
-        mgr.set_store.side_effect = cls.mock_set_config
-        mgr.get_store.side_effect = cls.mock_get_config
+        mgr.set_module_option.side_effect = cls.mock_set_module_option
+        mgr.get_module_option.side_effect = cls.mock_get_module_option
+        # kludge below
+        mgr.set_store.side_effect = cls.mock_set_module_option
+        mgr.get_store.side_effect = cls.mock_get_module_option
 
     def setUp(self):
         self.CONFIG_KEY_DICT.clear()
index d22410e847b81c9599f50551c8dc1df4cd203219..ed5362d9a3d1e5bc86af7c9181462cd5824c3eba 100644 (file)
@@ -37,17 +37,17 @@ class ApiAuditingTest(ControllerTestCase):
         super(ApiAuditingTest, self).__init__(*args, **kwargs)
 
     @classmethod
-    def mock_set_config(cls, key, val):
+    def mock_set_module_option(cls, key, val):
         cls.settings[key] = val
 
     @classmethod
-    def mock_get_config(cls, key, default=None):
+    def mock_get_module_option(cls, key, default=None):
         return cls.settings.get(key, default)
 
     @classmethod
     def setUpClass(cls):
-        mgr.get_config.side_effect = cls.mock_get_config
-        mgr.set_config.side_effect = cls.mock_set_config
+        mgr.get_module_option.side_effect = cls.mock_get_module_option
+        mgr.set_module_option.side_effect = cls.mock_set_module_option
 
     @classmethod
     def setup_server(cls):
@@ -55,8 +55,8 @@ class ApiAuditingTest(ControllerTestCase):
 
     def setUp(self):
         mgr.cluster_log = mock.Mock()
-        mgr.set_config('AUDIT_API_ENABLED', True)
-        mgr.set_config('AUDIT_API_LOG_PAYLOAD', True)
+        mgr.set_module_option('AUDIT_API_ENABLED', True)
+        mgr.set_module_option('AUDIT_API_LOG_PAYLOAD', True)
 
     def _validate_cluster_log_msg(self, path, method, user, params):
         channel, _, msg = mgr.cluster_log.call_args_list[0][0]
@@ -70,12 +70,12 @@ class ApiAuditingTest(ControllerTestCase):
         self.assertDictEqual(json.loads(m.group(5)), params)
 
     def test_no_audit(self):
-        mgr.set_config('AUDIT_API_ENABLED', False)
+        mgr.set_module_option('AUDIT_API_ENABLED', False)
         self._delete('/foo/test1')
         mgr.cluster_log.assert_not_called()
 
     def test_no_payload(self):
-        mgr.set_config('AUDIT_API_LOG_PAYLOAD', False)
+        mgr.set_module_option('AUDIT_API_LOG_PAYLOAD', False)
         self._delete('/foo/test1')
         _, _, msg = mgr.cluster_log.call_args_list[0][0]
         self.assertNotIn('params=', msg)
index 1a0665269b4f300d115def571d30521a2a825ad4..503ad00f60502ade0b39cf937f440ce44e1c0711 100644 (file)
@@ -35,7 +35,7 @@ class GrafanaControllerTestCase(ControllerTestCase):
             'GRAFANA_API_USERNAME': 'admin',
             'GRAFANA_API_PASSWORD': 'admin'
         }
-        mgr.get_config.side_effect = settings.get
+        mgr.get_module_option.side_effect = settings.get
         GrafanaProxy._cp_config['tools.authenticate.on'] = False  # pylint: disable=protected-access
 
         cls.setup_controllers([GrafanaProxy, GrafanaMockInstance])
index f1f0267abd545514dccf25296aa5b86696978094..36ecd51a334b4612f553da146a72164bbeb94156 100644 (file)
@@ -11,7 +11,7 @@ from ..rest_client import RequestException, RestClient
 class RestClientTest(unittest.TestCase):
     def setUp(self):
         settings = {'REST_REQUESTS_TIMEOUT': 45}
-        mgr.get_config.side_effect = settings.get
+        mgr.get_module_option.side_effect = settings.get
 
     def test_timeout_auto_set(self):
         with patch('requests.Session.request') as mock_request:
index 1502cdeb55b9561e284ef8cc440790bfd2871fbf..8bdb01a1b5c379c6ef9fe76bb44d8ba409c3e106 100644 (file)
@@ -14,27 +14,27 @@ class RgwClientTest(unittest.TestCase):
     }
 
     @classmethod
-    def mock_set_config(cls, key, val):
+    def mock_set_module_option(cls, key, val):
         cls.settings[key] = val
 
     @classmethod
-    def mock_get_config(cls, key, default):
+    def mock_get_module_option(cls, key, default):
         return cls.settings.get(key, default)
 
     @classmethod
     def setUpClass(cls):
-        mgr.get_config.side_effect = cls.mock_get_config
-        mgr.set_config.side_effect = cls.mock_set_config
+        mgr.get_module_option.side_effect = cls.mock_get_module_option
+        mgr.set_module_option.side_effect = cls.mock_set_module_option
 
     def setUp(self):
         RgwClient._user_instances.clear()  # pylint: disable=protected-access
 
     def test_ssl_verify(self):
-        mgr.set_config('RGW_API_SSL_VERIFY', True)
+        mgr.set_module_option('RGW_API_SSL_VERIFY', True)
         instance = RgwClient.admin_instance()
         self.assertTrue(instance.session.verify)
 
     def test_no_ssl_verify(self):
-        mgr.set_config('RGW_API_SSL_VERIFY', False)
+        mgr.set_module_option('RGW_API_SSL_VERIFY', False)
         instance = RgwClient.admin_instance()
         self.assertFalse(instance.session.verify)
index a29931cc956acac22b11de43048b213b240205d5..3965bde95410ddd2885ddd6d20389d92ecbb4b3d 100644 (file)
@@ -22,17 +22,17 @@ class SettingsTest(unittest.TestCase):
         settings._OPTIONS_COMMAND_MAP = settings._options_command_map()
 
     @classmethod
-    def mock_set_config(cls, attr, val):
+    def mock_set_module_option(cls, attr, val):
         cls.CONFIG_KEY_DICT[attr] = val
 
     @classmethod
-    def mock_get_config(cls, attr, default):
+    def mock_get_module_option(cls, attr, default):
         return cls.CONFIG_KEY_DICT.get(attr, default)
 
     def setUp(self):
         self.CONFIG_KEY_DICT.clear()
-        mgr.set_config.side_effect = self.mock_set_config
-        mgr.get_config.side_effect = self.mock_get_config
+        mgr.set_module_option.side_effect = self.mock_set_module_option
+        mgr.get_module_option.side_effect = self.mock_get_module_option
         if Settings.GRAFANA_API_HOST != 'localhost':
             Settings.GRAFANA_API_HOST = 'localhost'
         if Settings.GRAFANA_API_PORT != 3000:
@@ -119,17 +119,17 @@ class SettingsControllerTest(ControllerTestCase):
         cls.setup_controllers([SettingsController])
 
     @classmethod
-    def mock_set_config(cls, attr, val):
+    def mock_set_module_option(cls, attr, val):
         cls.config_values[attr] = val
 
     @classmethod
-    def mock_get_config(cls, attr, default):
+    def mock_get_module_option(cls, attr, default):
         return cls.config_values.get(attr, default)
 
     def setUp(self):
         self.config_values.clear()
-        mgr.set_config.side_effect = self.mock_set_config
-        mgr.get_config.side_effect = self.mock_get_config
+        mgr.set_module_option.side_effect = self.mock_set_module_option
+        mgr.get_module_option.side_effect = self.mock_get_module_option
 
     def test_settings_list(self):
         self._get('/api/settings')
index 35cb5df855a1473bb0ee873e18bae1ccbbac3838..583da425610fc4299d22bd20878466ae874d38a2 100644 (file)
@@ -14,11 +14,11 @@ class AccessControlTest(unittest.TestCase):
     CONFIG_KEY_DICT = {}
 
     @classmethod
-    def mock_set_config(cls, attr, val):
+    def mock_set_module_option(cls, attr, val):
         cls.CONFIG_KEY_DICT[attr] = val
 
     @classmethod
-    def mock_get_config(cls, attr, default):
+    def mock_get_module_option(cls, attr, default):
         return cls.CONFIG_KEY_DICT.get(attr, default)
 
     IDP_METADATA = '''<?xml version="1.0"?>
@@ -71,10 +71,11 @@ class AccessControlTest(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
-        mgr.set_config.side_effect = cls.mock_set_config
-        mgr.get_config.side_effect = cls.mock_get_config
-        mgr.set_store.side_effect = cls.mock_set_config
-        mgr.get_store.side_effect = cls.mock_get_config
+        mgr.set_module_option.side_effect = cls.mock_set_module_option
+        mgr.get_module_option.side_effect = cls.mock_get_module_option
+        # kludge below
+        mgr.set_store.side_effect = cls.mock_set_module_option
+        mgr.get_store.side_effect = cls.mock_get_module_option
 
     def setUp(self):
         self.CONFIG_KEY_DICT.clear()
index a769f7e99b9bea877edd0187d1072842df2eed32..6cd8fdac5b2f84f846c720734099b98d10e85e7e 100644 (file)
@@ -577,7 +577,7 @@ class Module(MgrModule):
 
     def predict_lift_expectancy(self, devid):
         plugin_name = ''
-        model = self.get_option('device_failure_prediction_mode')
+        model = self.get_ceph_option('device_failure_prediction_mode')
         if model and model.lower() == 'cloud':
             plugin_name = 'diskprediction_cloud'
         elif model and model.lower() == 'local':
@@ -593,7 +593,7 @@ class Module(MgrModule):
 
     def predict_all_devices(self):
         plugin_name = ''
-        model = self.get_option('device_failure_prediction_mode')
+        model = self.get_ceph_option('device_failure_prediction_mode')
         if model and model.lower() == 'cloud':
             plugin_name = 'diskprediction_cloud'
         elif model and model.lower() == 'local':
index 4cbfb4de78744c5b6e91804ee604072d965450c2..cb323d6a615af67d3daa7bb8a2c2daff0c1bce7a 100644 (file)
@@ -133,9 +133,9 @@ class Module(MgrModule):
                     opt['name'],
                     self.get_module_option(opt['name']) or opt['default'])
             self.log.debug(' %s = %s', opt['name'], getattr(self, opt['name']))
-        if not self._activated_cloud and self.get_option('device_failure_prediction_mode') == 'cloud':
+        if not self._activated_cloud and self.get_ceph_option('device_failure_prediction_mode') == 'cloud':
             self._event.set()
-        if self._activated_cloud and self.get_option('device_failure_prediction_mode') != 'cloud':
+        if self._activated_cloud and self.get_ceph_option('device_failure_prediction_mode') != 'cloud':
             self._event.set()
 
     @property
@@ -370,7 +370,7 @@ class Module(MgrModule):
 
         while self._run:
             self.refresh_config()
-            mode = self.get_option('device_failure_prediction_mode')
+            mode = self.get_ceph_option('device_failure_prediction_mode')
             if mode == 'cloud':
                 if not self._activated_cloud:
                     self.start_cloud_disk_prediction()
index 1cdea759e66ea1a865273903f9072f1786ad3c09..191b25cdb468fd3b221a51ba28ad9dcd01b5d787 100644 (file)
@@ -44,7 +44,7 @@ class Module(MgrModule):
                     opt['name'],
                     self.get_module_option(opt['name']) or opt['default'])
             self.log.debug(' %s = %s', opt['name'], getattr(self, opt['name']))
-        if self.get_option('device_failure_prediction_mode') == 'local':
+        if self.get_ceph_option('device_failure_prediction_mode') == 'local':
             self._event.set()
 
     def refresh_config(self):
@@ -77,7 +77,7 @@ class Module(MgrModule):
 
         while self._run:
             self.refresh_config()
-            mode = self.get_option('device_failure_prediction_mode')
+            mode = self.get_ceph_option('device_failure_prediction_mode')
             if mode == 'local':
                 now = datetime.datetime.utcnow()
                 if not last_predicted:
index 8808d7a9b8adf5be9bbd555c770e08df601d19a2..e143468b20dbc55545216fb0f6c3ff20372fc134 100644 (file)
@@ -678,7 +678,7 @@ class MgrModule(ceph_module.BaseMgrModule):
         """
         return self._ceph_get_mgr_id()
 
-    def get_option(self, key):
+    def get_ceph_option(self, key):
         return self._ceph_get_option(key)
 
     def _validate_module_option(self, key):