From b4190bed6fa5ebcfb97f3975c3d57326bebd330b Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 2 Mar 2018 09:57:35 -0500 Subject: [PATCH] mgr/dashboard: implement can_run checks for dashboard v2 Should be especially handy in development environments for giving a clear message for people who have forgotten to build frontend bits. Signed-off-by: John Spray --- src/pybind/mgr/dashboard_v2/module.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/dashboard_v2/module.py b/src/pybind/mgr/dashboard_v2/module.py index 502e2c5d100..d66438a270e 100644 --- a/src/pybind/mgr/dashboard_v2/module.py +++ b/src/pybind/mgr/dashboard_v2/module.py @@ -11,7 +11,12 @@ try: from urlparse import urljoin except ImportError: from urllib.parse import urljoin -import cherrypy +try: + import cherrypy +except ImportError: + # To be picked up and reported by .can_run() + cherrypy = None + from mgr_module import MgrModule, MgrStandbyModule if 'COVERAGE_ENABLED' in os.environ: @@ -74,6 +79,21 @@ class Module(MgrModule): mgr.init(self) self._url_prefix = '' + @classmethod + def can_run(cls): + if cherrypy is None: + return False, "Missing dependency: cherrypy" + + if not os.path.exists(cls.get_frontend_path()): + return False, "Frontend assets not found: incomplete build?" + + return True, "" + + @classmethod + def get_frontend_path(cls): + current_dir = os.path.dirname(os.path.abspath(__file__)) + return os.path.join(current_dir, 'frontend/dist') + def configure_cherrypy(self): server_addr = self.get_localized_config('server_addr', '::') server_port = self.get_localized_config('server_port', '8080') @@ -101,12 +121,10 @@ class Module(MgrModule): } cherrypy.config.update(config) - current_dir = os.path.dirname(os.path.abspath(__file__)) - fe_dir = os.path.join(current_dir, 'frontend/dist') config = { '/': { 'tools.staticdir.on': True, - 'tools.staticdir.dir': fe_dir, + 'tools.staticdir.dir': self.get_frontend_path(), 'tools.staticdir.index': 'index.html' } }