summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/plugins/debug.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/pybind/mgr/dashboard/plugins/debug.py
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/dashboard/plugins/debug.py')
-rw-r--r--src/pybind/mgr/dashboard/plugins/debug.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/plugins/debug.py b/src/pybind/mgr/dashboard/plugins/debug.py
new file mode 100644
index 000000000..8c6bfb007
--- /dev/null
+++ b/src/pybind/mgr/dashboard/plugins/debug.py
@@ -0,0 +1,94 @@
+# -*- coding: utf-8 -*-
+
+
+import json
+from enum import Enum
+from typing import no_type_check
+
+from . import PLUGIN_MANAGER as PM
+from . import interfaces as I # noqa: E741,N812
+from .plugin import SimplePlugin as SP
+
+
+class Actions(Enum):
+ ENABLE = 'enable'
+ DISABLE = 'disable'
+ STATUS = 'status'
+
+
+@PM.add_plugin # pylint: disable=too-many-ancestors
+class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy, # pylint: disable=too-many-ancestors
+ I.Setupable, I.ConfigNotify):
+ NAME = 'debug'
+
+ OPTIONS = [
+ SP.Option(
+ name=NAME,
+ default=False,
+ type='bool',
+ desc="Enable/disable debug options"
+ )
+ ]
+
+ @no_type_check # https://github.com/python/mypy/issues/7806
+ def _refresh_health_checks(self):
+ debug = self.get_option(self.NAME)
+ if debug:
+ self.mgr.health_checks.update({'DASHBOARD_DEBUG': {
+ 'severity': 'warning',
+ 'summary': 'Dashboard debug mode is enabled',
+ 'detail': [
+ 'Please disable debug mode in production environments using '
+ '"ceph dashboard {} {}"'.format(self.NAME, Actions.DISABLE.value)
+ ]
+ }})
+ else:
+ self.mgr.health_checks.pop('DASHBOARD_DEBUG', None)
+ self.mgr.refresh_health_checks()
+
+ @PM.add_hook
+ def setup(self):
+ self._refresh_health_checks()
+
+ @no_type_check
+ def handler(self, action: Actions):
+ '''
+ Control and report debug status in Ceph-Dashboard
+ '''
+ ret = 0
+ msg = ''
+ if action in [Actions.ENABLE, Actions.DISABLE]:
+ self.set_option(self.NAME, action == Actions.ENABLE)
+ self.mgr.update_cherrypy_config({})
+ self._refresh_health_checks()
+ else:
+ debug = self.get_option(self.NAME)
+ msg = "Debug: '{}'".format('enabled' if debug else 'disabled')
+ return ret, msg, None
+
+ COMMANDS = [
+ SP.Command(
+ prefix="dashboard {name}".format(name=NAME),
+ handler=handler
+ )
+ ]
+
+ def custom_error_response(self, status, message, traceback, version):
+ self.response.headers['Content-Type'] = 'application/json'
+ error_response = dict(status=status, detail=message, request_id=str(self.request.unique_id))
+
+ if self.get_option(self.NAME):
+ error_response.update(dict(traceback=traceback, version=version))
+
+ return json.dumps(error_response)
+
+ @PM.add_hook
+ def configure_cherrypy(self, config):
+ config.update({
+ 'environment': 'test_suite' if self.get_option(self.NAME) else 'production',
+ 'error_page.default': self.custom_error_response,
+ })
+
+ @PM.add_hook
+ def config_notify(self):
+ self._refresh_health_checks()