]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: add Debug plugin
authorErnesto Puerta <epuertat@redhat.com>
Thu, 10 Oct 2019 09:24:54 +0000 (11:24 +0200)
committerErnesto Puerta <epuertat@redhat.com>
Thu, 10 Oct 2019 10:58:56 +0000 (12:58 +0200)
Fixes: https://tracker.ceph.com/issues/41990
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
src/pybind/mgr/dashboard/plugins/debug.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/dashboard/plugins/debug.py b/src/pybind/mgr/dashboard/plugins/debug.py
new file mode 100644 (file)
index 0000000..f0cbf24
--- /dev/null
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+
+from enum import Enum
+import json
+import uuid
+
+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, I.FilterRequest.BeforeHandler):
+    NAME = 'debug'
+
+    OPTIONS = [
+        SP.Option(
+            name=NAME,
+            default=False,
+            type='bool',
+            desc="Enable/disable debug options"
+        )
+    ]
+
+    def handler(self, action):
+        ret = 0
+        msg = ''
+        if action in [Actions.ENABLE.value, Actions.DISABLE.value]:
+            self.set_option(self.NAME, action == Actions.ENABLE.value)
+            self.mgr.update_cherrypy_config({})
+        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),
+            args="name=action,type=CephChoices,strings={states}".format(
+                states="|".join(a.value for a in Actions)),
+            desc="Control and report debug status in Ceph-Dashboard",
+            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=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 filter_request_before_handler(self, request):
+        if not hasattr(request, 'unique_id'):
+            # Cherrypy v8.9.1 doesn't have this property
+            request.unique_id = str(uuid.uuid4())