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
@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]
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"]
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), ''
@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):
raise cherrypy.HTTPError(
404, "Feature='{}' disabled by option '{}'".format(
feature.value,
- self.OPTION_FMT.format(feature.value),
+ self.OPTION_FMT.format(feature),
)
)
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
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):