]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: enable coverage for API tests 26851/head
authoralfonsomthd <almartin@redhat.com>
Fri, 8 Mar 2019 16:35:34 +0000 (17:35 +0100)
committeralfonsomthd <almartin@redhat.com>
Fri, 8 Mar 2019 16:35:34 +0000 (17:35 +0100)
* 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 <almartin@redhat.com>
src/pybind/mgr/dashboard/module.py
src/pybind/mgr/dashboard/requirements.txt
src/pybind/mgr/dashboard/run-backend-api-tests.sh

index 9a6f3748324b4aa9c2fe4868a8db605bbda03423..6be074d2a49aa68d8c130d6fdf3a0570a9dd8eb1 100644 (file)
@@ -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):
index 3bc95178126929ff0db09b937a498cb828a5c145..caa1db80e96fbef58fadb3b13036011464a3df9d 100644 (file)
@@ -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
index 630adac9e0a48ccf2ac0c2ae0275e9ff1f39560d..9a3a47fe76386f05b574805f1b7a6416ed50b0eb 100755 (executable)
@@ -33,6 +33,7 @@ setup_teuthology() {
     read -r -d '' TEUTHOLOGY_PY_REQS <<EOF
 apache-libcloud==2.2.1 \
 asn1crypto==0.22.0 \
+backports.ssl-match-hostname==3.5.0.1 \
 bcrypt==3.1.4 \
 certifi==2018.1.18 \
 cffi==1.10.0 \
@@ -89,10 +90,14 @@ EOF
         fi
     fi
 
-#    export COVERAGE_ENABLED=true
-#    export COVERAGE_FILE=.coverage.mgr.dashboard
-
     cd $CURR_DIR
+
+    COVERAGE_VERSION=$(cat requirements.txt | grep coverage)
+    if [[ "$CEPH_MGR_PY_VERSION_MAJOR" == '3' ]]; then
+        pip3 install "$COVERAGE_VERSION"
+    else
+        pip install "$COVERAGE_VERSION"
+    fi
 }
 
 run_teuthology_tests() {
@@ -121,6 +126,10 @@ run_teuthology_tests() {
         export RGW=1
     fi
 
+    export COVERAGE_ENABLED=true
+    export COVERAGE_FILE=.coverage.mgr.dashboard
+    find . -iname "*${COVERAGE_FILE}*" -type f -delete
+
     eval python ../qa/tasks/vstart_runner.py $OPTIONS $TEST_CASES
 
     deactivate
@@ -131,6 +140,11 @@ cleanup_teuthology() {
     cd "$BUILD_DIR"
     killall ceph-mgr
     sleep 10
+    if [[ "$COVERAGE_ENABLED" == 'true' ]]; then
+        source $TEMP_DIR/venv/bin/activate
+        (coverage combine && coverage report) || true
+        deactivate
+    fi
     ../src/stop.sh
     sleep 5