From: Ernesto Puerta Date: Wed, 17 Mar 2021 16:31:53 +0000 (+0100) Subject: mgr/dashboard: fix broken feature toggles X-Git-Tag: v16.2.2~3^2~2^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=35ca939e1c1a2ab8919c5e6faaf5849e915ee666;p=ceph.git mgr/dashboard: fix broken feature toggles Fixes the feature toggles functionality broken in the refactoring of the CLI commands (3c431a54d96ebc9bdb911161468d0f6bedbbcbfe, PR #38722). Fixes: https://tracker.ceph.com/issues/49869 Signed-off-by: Ernesto Puerta (cherry picked from commit 005348ae76613b07767e95d86b4aa1d828221c0f) --- diff --git a/src/pybind/mgr/dashboard/plugins/feature_toggles.py b/src/pybind/mgr/dashboard/plugins/feature_toggles.py index 3085d1977e57c..ea50652346a4a 100644 --- a/src/pybind/mgr/dashboard/plugins/feature_toggles.py +++ b/src/pybind/mgr/dashboard/plugins/feature_toggles.py @@ -57,7 +57,7 @@ class Actions(Enum): class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, I.HasCommands, I.FilterRequest.BeforeHandler, I.HasControllers): - OPTION_FMT = 'FEATURE_TOGGLE_{}' + OPTION_FMT = 'FEATURE_TOGGLE_{.name}' CACHE_MAX_SIZE = 128 # Optimum performance with 2^N sizes CACHE_TTL = 10 # seconds @@ -72,7 +72,7 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, @PM.add_hook def get_options(self): return [Option( - name=self.OPTION_FMT.format(feature.value), + name=self.OPTION_FMT.format(feature), default=(feature not in PREDISABLED_FEATURES), type='bool',) for feature in Features] @@ -80,14 +80,14 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, def register_commands(self): @CLICommand("dashboard feature") def cmd(mgr, - action: Actions, + action: Actions = Actions.STATUS, features: Optional[List[Features]] = None): ''' Enable or disable features in Ceph-Mgr Dashboard ''' ret = 0 msg = [] - if action in [Actions.ENABLE.value, Actions.DISABLE.value]: + if action in [Actions.ENABLE, Actions.DISABLE]: if features is None: ret = 1 msg = ["At least one feature must be specified"] @@ -95,15 +95,15 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, for feature in features: mgr.set_module_option( self.OPTION_FMT.format(feature), - action == Actions.ENABLE.value) - msg += ["Feature '{}': {}".format( + action == Actions.ENABLE) + msg += ["Feature '{.value}': {}".format( feature, - 'enabled' if action == Actions.ENABLE.value else + 'enabled' if action == Actions.ENABLE else 'disabled')] else: - for feature in features or [f.value for f in Features]: + for feature in features or list(Features): enabled = mgr.get_module_option(self.OPTION_FMT.format(feature)) - msg += ["Feature '{}': {}".format( + msg += ["Feature '{.value}': {}".format( feature, 'enabled' if enabled else 'disabled')] return ret, '\n'.join(msg), '' @@ -120,7 +120,7 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, @ttl_cache(ttl=CACHE_TTL, maxsize=CACHE_MAX_SIZE) @no_type_check # https://github.com/python/mypy/issues/7806 def _is_feature_enabled(self, feature): - return self.mgr.get_module_option(self.OPTION_FMT.format(feature.value)) + return self.mgr.get_module_option(self.OPTION_FMT.format(feature)) @PM.add_hook def filter_request_before_handler(self, request): @@ -132,7 +132,7 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions, raise cherrypy.HTTPError( 404, "Feature='{}' disabled by option '{}'".format( feature.value, - self.OPTION_FMT.format(feature.value), + self.OPTION_FMT.format(feature), ) ) diff --git a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py index a5088e1a0c594..571b8c286c859 100644 --- a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py +++ b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py @@ -8,7 +8,7 @@ try: except ImportError: from unittest.mock import Mock, patch -from ..plugins.feature_toggles import Features, FeatureToggles +from ..plugins.feature_toggles import Actions, Features, FeatureToggles from . import KVStoreMockMixin # pylint: disable=no-name-in-module @@ -56,7 +56,7 @@ class SettingsTest(unittest.TestCase, KVStoreMockMixin): import cherrypy self.plugin.register_commands()['handle_command']( - self.mgr, 'disable', ['cephfs']) + self.mgr, Actions.DISABLE, [Features.CEPHFS]) with patch.object(self.plugin, '_get_feature_from_request', return_value=Features.CEPHFS):