From: Ricardo Dias Date: Thu, 8 Feb 2018 08:21:31 +0000 (+0000) Subject: mgr/dashboard_v2: Added coverage tracking to module code X-Git-Tag: v13.0.2~84^2~90 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a71f7c6f8e7c9dc643b3b2579b3729293035a657;p=ceph.git mgr/dashboard_v2: Added coverage tracking to module code This will allow to collect code coverage information when the module is running within the ceph-mgr daemon. Signed-off-by: Ricardo Dias --- diff --git a/src/pybind/mgr/dashboard_v2/.coveragerc b/src/pybind/mgr/dashboard_v2/.coveragerc index 3832b81dbe0..29a63192c3f 100644 --- a/src/pybind/mgr/dashboard_v2/.coveragerc +++ b/src/pybind/mgr/dashboard_v2/.coveragerc @@ -3,4 +3,5 @@ omit = tests/* */python*/* ceph_module_mock.py __init__.py + */mgr_module.py diff --git a/src/pybind/mgr/dashboard_v2/module.py b/src/pybind/mgr/dashboard_v2/module.py index 5643e1bb328..37cd99323a4 100644 --- a/src/pybind/mgr/dashboard_v2/module.py +++ b/src/pybind/mgr/dashboard_v2/module.py @@ -14,6 +14,12 @@ except ImportError: import cherrypy from mgr_module import MgrModule +if 'COVERAGE_ENABLED' in os.environ: + import coverage + _cov = coverage.Coverage(config_file="{}/.coveragerc".format(os.path.dirname(__file__))) + _cov.start() + +# pylint: disable=wrong-import-position from .controllers.auth import Auth from .tools import load_controllers, json_error_page, SessionExpireAtBrowserCloseTool, \ NotificationQueue @@ -105,6 +111,8 @@ class Module(MgrModule): cherrypy.tree.mount(Module.StaticRoot(), '/', config=config) def serve(self): + if 'COVERAGE_ENABLED' in os.environ: + _cov.start() self.configure_cherrypy() cherrypy.engine.start() @@ -112,6 +120,9 @@ class Module(MgrModule): logger.info('Waiting for engine...') self.log.info('Waiting for engine...') cherrypy.engine.block() + if 'COVERAGE_ENABLED' in os.environ: + _cov.stop() + _cov.save() logger.info('Engine done') def shutdown(self):