]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: implement can_run checks for dashboard v2 20728/head
authorJohn Spray <john.spray@redhat.com>
Fri, 2 Mar 2018 14:57:35 +0000 (09:57 -0500)
committerJohn Spray <john.spray@redhat.com>
Mon, 12 Mar 2018 15:20:50 +0000 (15:20 +0000)
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 <john.spray@redhat.com>
src/pybind/mgr/dashboard_v2/module.py

index 502e2c5d1002d0245fa8987be60c8e39bc6d758e..d66438a270ebc08920c5803b8c7182943675bb3b 100644 (file)
@@ -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'
             }
         }