From da52919f69e332b3f25fff1d22ffdf83f7a62420 Mon Sep 17 00:00:00 2001 From: alfonsomthd Date: Fri, 8 Mar 2019 17:35:34 +0100 Subject: [PATCH] mgr/dashboard: enable coverage for API tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Fixed: install in system the 'coverage' version set in requirements.txt as dashboard/module.py uses system version. * Updated 'coverage' to latest stable version. * Added teuthology missing dependency: backports.ssl-match-hostname * More precise coverage measurement through CherryPy Bus API. * Coverage report shown when no ceph-mgr running (cleanup_teuthology). Fixes: https://tracker.ceph.com/issues/36176 Signed-off-by: Alfonso Martínez --- src/pybind/mgr/dashboard/module.py | 14 ++++++------- src/pybind/mgr/dashboard/requirements.txt | 2 +- .../mgr/dashboard/run-backend-api-tests.sh | 20 ++++++++++++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 9a6f3748324..6be074d2a49 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -63,8 +63,12 @@ if cherrypy is not None: if 'COVERAGE_ENABLED' in os.environ: import coverage - _cov = coverage.Coverage(config_file="{}/.coveragerc".format(os.path.dirname(__file__))) - _cov.start() + __cov = coverage.Coverage(config_file="{}/.coveragerc".format(os.path.dirname(__file__)), + data_suffix=True) + + cherrypy.engine.subscribe('start', __cov.start) + cherrypy.engine.subscribe('after_request', __cov.save) + cherrypy.engine.subscribe('stop', __cov.stop) # pylint: disable=wrong-import-position from . import logger, mgr @@ -305,9 +309,6 @@ class Module(MgrModule, CherryPyConfig): return os.path.join(current_dir, 'frontend/dist') def serve(self): - if 'COVERAGE_ENABLED' in os.environ: - _cov.start() - AuthManager.initialize() load_sso_db() @@ -346,9 +347,6 @@ class Module(MgrModule, CherryPyConfig): self.shutdown_event.clear() NotificationQueue.stop() cherrypy.engine.stop() - if 'COVERAGE_ENABLED' in os.environ: - _cov.stop() - _cov.save() logger.info('Engine stopped') def shutdown(self): diff --git a/src/pybind/mgr/dashboard/requirements.txt b/src/pybind/mgr/dashboard/requirements.txt index 3bc95178126..caa1db80e96 100644 --- a/src/pybind/mgr/dashboard/requirements.txt +++ b/src/pybind/mgr/dashboard/requirements.txt @@ -4,7 +4,7 @@ bcrypt==3.1.4 cheroot==6.0.0 CherryPy==13.1.0 configparser==3.5.0 -coverage==4.4.2 +coverage==4.5.2 enum34==1.1.6 funcsigs==1.0.2 isort==4.2.15 diff --git a/src/pybind/mgr/dashboard/run-backend-api-tests.sh b/src/pybind/mgr/dashboard/run-backend-api-tests.sh index 630adac9e0a..9a3a47fe763 100755 --- a/src/pybind/mgr/dashboard/run-backend-api-tests.sh +++ b/src/pybind/mgr/dashboard/run-backend-api-tests.sh @@ -33,6 +33,7 @@ setup_teuthology() { read -r -d '' TEUTHOLOGY_PY_REQS <