]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix broken feature toggles 40474/head
authorErnesto Puerta <epuertat@redhat.com>
Wed, 17 Mar 2021 16:31:53 +0000 (17:31 +0100)
committerAlfonso Martínez <almartin@redhat.com>
Mon, 29 Mar 2021 14:58:54 +0000 (16:58 +0200)
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 <epuertat@redhat.com>
(cherry picked from commit 005348ae76613b07767e95d86b4aa1d828221c0f)

src/pybind/mgr/dashboard/plugins/feature_toggles.py
src/pybind/mgr/dashboard/tests/test_feature_toggles.py

index 3085d1977e57c3ec85e1a757a2859f834b610a50..ea50652346a4a678147d0c68f8b9d2f985f1deec 100644 (file)
@@ -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),
                 )
             )
 
index a5088e1a0c5948fa93c896fd74bdb3a72aa699d0..571b8c286c859893c2b058e894fa4016dd39fe8f 100644 (file)
@@ -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):