From b1022a4fe462eddf364d4503f285ececaeeb82b4 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 7 Jul 2015 20:03:34 -0400 Subject: [PATCH 1/7] DOC: Use coverage report and optionally coverage html --- DEVELOP | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DEVELOP b/DEVELOP index b71f5274..bb7de5c8 100644 --- a/DEVELOP +++ b/DEVELOP @@ -56,9 +56,12 @@ following (note: on Debian-based systems, the script is called `python-coverage`):: coverage run bin/fail2ban-testcases + coverage report + +Optionally: coverage html -Then look at htmlcov/index.html and see how much coverage your test cases +And then browse htmlcov/index.html and see how much coverage your test cases exert over the code base. Full coverage is a good thing however it may not be complete. Try to ensure tests cover as many independent paths through the code. From f50dcf76587415fb8eb151e82880b17f1c06275b Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 7 Jul 2015 20:04:16 -0400 Subject: [PATCH 2/7] Remove shebang from setup.py --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 44f11e62..6a803e49 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- # vi: set ft=python sts=4 ts=4 sw=4 noet : From 94bc77aac8148164e3bafb652bf914fd93c46bbe Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 7 Jul 2015 20:09:56 -0400 Subject: [PATCH 3/7] Consolidate coveragerc configs into .coveragerc (delete .travis_coveragerc) --- .coveragerc | 9 ++++++++- .travis_coveragerc | 7 ------- 2 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 .travis_coveragerc diff --git a/.coveragerc b/.coveragerc index 3bffd79a..19bc3db4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,11 @@ [run] branch = True -omit = /usr* +source = + config + fail2ban + +[report] +exclude_lines = + pragma: no cover + pragma: systemd no cover diff --git a/.travis_coveragerc b/.travis_coveragerc deleted file mode 100644 index 49fc3134..00000000 --- a/.travis_coveragerc +++ /dev/null @@ -1,7 +0,0 @@ - -[run] -branch = True -omit = - /usr/* - /home/travis/virtualenv/* - fail2ban/server/filtersystemd.py From 675767ad4f495e5ea4311a30dba6655f27344219 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 7 Jul 2015 20:10:14 -0400 Subject: [PATCH 4/7] Exclude coverage traceback in smoke test (misctestcase) --- fail2ban/tests/misctestcase.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index 393d6be6..c95efa43 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -155,8 +155,10 @@ class TestsUtilsTest(unittest.TestCase): # we must be calling it from setup or nosetests but using at least # nose's core etc self.assertTrue('>' in s, msg="no '>' in %r" % s) - else: - self.assertFalse('>' in s, msg="'>' present in %r" % s) # There is only "fail2ban-testcases" in this case, no true traceback + elif not ('coverage' in s): + # There is only "fail2ban-testcases" in this case, no true traceback + self.assertFalse('>' in s, msg="'>' present in %r" % s) + self.assertTrue(':' in s, msg="no ':' in %r" % s) def testFormatterWithTraceBack(self): From fc2b7f80123221fef5c29701a863ed0401827637 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 7 Jul 2015 20:10:26 -0400 Subject: [PATCH 5/7] Multiple Travis and coverage related changes Reorganize .travis.yml Separate coverage tests for Python 2 and Python 3 Execute setup.py install using the environment's Python exe Sanitize Travis execution order --- .travis.yml | 67 +++++++++++++++++++++++++++++++++++++---------------- ChangeLog | 1 + 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index c48b6335..8a72163a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,56 @@ # vim ft=yaml # travis-ci.org definition for Fail2Ban build +# https://travis-ci.org/fail2ban/fail2ban/ language: python python: - - "2.6" - - "2.7" - - "3.2" - - "3.3" - - "3.4" -# - "pypy" # disabled for now due to frequent unreproducable failures # gh-1089 - - "pypy3" + - 2.6 + - 2.7 + - pypy + - 3.2 + - 3.3 + - 3.4 + - pypy3 before_install: - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then travis_retry sudo apt-get update -qq; fi + - if [[ $TRAVIS_PYTHON_VERSION == 2* || $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then export F2B_PY_2=true && echo "Set F2B_PY_2"; fi + - if [[ $TRAVIS_PYTHON_VERSION == 3* || $TRAVIS_PYTHON_VERSION == 'pypy3' ]]; then export F2B_PY_3=true && echo "Set F2B_PY_3"; fi + - travis_retry sudo apt-get update -qq + # Set this so sudo executes the correct python binary + # Anything not using sudo will already have the correct environment + - export PYTHON_CMD="$VIRTUAL_ENV/bin/python" && echo "PYTHON_CMD set to $PYTHON_CMD" install: + # Install Python packages / dependencies + # coverage + - travis_retry pip install coverage + # coveralls + - travis_retry pip install coveralls + # dnspython or dnspython3 + - if [[ "$F2B_PY_2" ]]; then travis_retry pip install dnspython; fi + - if [[ "$F2B_PY_3" ]]; then travis_retry pip install dnspython3; fi + # gamin - install manually (not in PyPI) - travis-ci system Python is 2.7 + - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then travis_retry sudo apt-get install -qq python-gamin && cp /usr/share/pyshared/gamin.py /usr/lib/pyshared/python2.7/_gamin.so $VIRTUAL_ENV/lib/python2.7/site-packages/; fi + # pyinotify - travis_retry pip install pyinotify - - if [[ $TRAVIS_PYTHON_VERSION == 2* || $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then travis_retry pip install dnspython; fi - - if [[ $TRAVIS_PYTHON_VERSION == 3* || $TRAVIS_PYTHON_VERSION == 'pypy3' ]]; then travis_retry pip install dnspython3; fi - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then travis_retry sudo apt-get install -qq python-gamin; cp /usr/share/pyshared/gamin.py /usr/lib/pyshared/python2.7/_gamin.so $VIRTUAL_ENV/lib/python2.7/site-packages/; fi - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then cd ..; travis_retry pip install -q coveralls; cd -; fi - # overcome buggy pypy - - if [[ $TRAVIS_PYTHON_VERSION == pypy ]] ; then dpkg --compare-versions $(pypy --version 2>&1 | awk '/PyPy/{print $2;}') ge 2.5.1 || { d=$PWD; cd /tmp; wget --no-check-certificate https://bitbucket.org/pypy/pypy/downloads/pypy-2.5.1-linux64.tar.bz2; tar -xjvf pypy*bz2; cd pypy-*/bin/; export PATH=$PWD:$PATH; cd $d; } ; fi +before_script: + # Manually execute 2to3 for now + - if [[ "$F2B_PY_3" ]]; then ./fail2ban-2to3; fi script: - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc setup.py test; else python setup.py test; fi -# test installation - - sudo python setup.py install + # Keep the legacy setup.py test approach of checking coverage for python2 + - if [[ "$F2B_PY_2" ]]; then coverage run setup.py test; fi + # Coverage doesn't pick up setup.py test with python3, so run it directly + - if [[ "$F2B_PY_3" ]]; then coverage run bin/fail2ban-testcases; fi + # Use $PYTHON_CMD (not python) or else sudo will always run the system's python (2.7) + - sudo $PYTHON_CMD setup.py install after_success: -# Coverage config file must be .coveragerc for coveralls - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then cp -v .travis_coveragerc .coveragerc; fi - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi + - coveralls +matrix: + fast_finish: true +# Might be worth looking into +#notifications: +# email: true +# irc: +# channels: "irc.freenode.org#fail2ban" +# template: +# - "%{repository}@%{branch}: %{message} (%{build_url})" +# on_success: change +# on_failure: change +# skip_join: true diff --git a/ChangeLog b/ChangeLog index 6821a5f9..a1c39ad8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,7 @@ ver. 0.9.3 (2015/XX/XXX) - wanna-be-released * fail2ban-testcases man page * filter.d/apache-badbots.conf, filter.d/nginx-botsearch.conf - add HEAD method verb + * Revamp of Travis and coverage automated testing ver. 0.9.2 (2015/04/29) - better-quick-now-than-later From c56785685b4e2a8fa28bae75a6ff1ce12b46ca2a Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Thu, 9 Jul 2015 10:46:12 -0400 Subject: [PATCH 6/7] Set VENV path and use pip to install --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a72163a..f65e4896 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_install: - travis_retry sudo apt-get update -qq # Set this so sudo executes the correct python binary # Anything not using sudo will already have the correct environment - - export PYTHON_CMD="$VIRTUAL_ENV/bin/python" && echo "PYTHON_CMD set to $PYTHON_CMD" + - export VENV_BIN="$VIRTUAL_ENV/bin" && echo "VENV_BIN set to $VENV_BIN" install: # Install Python packages / dependencies # coverage @@ -38,8 +38,8 @@ script: - if [[ "$F2B_PY_2" ]]; then coverage run setup.py test; fi # Coverage doesn't pick up setup.py test with python3, so run it directly - if [[ "$F2B_PY_3" ]]; then coverage run bin/fail2ban-testcases; fi - # Use $PYTHON_CMD (not python) or else sudo will always run the system's python (2.7) - - sudo $PYTHON_CMD setup.py install + # Use $VENV_BIN (not python) or else sudo will always run the system's python (2.7) + - sudo $VENV_BIN/pip install . after_success: - coveralls matrix: From 7f68516c5c8e1451f94b513aac65ad7faf6e696f Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Thu, 9 Jul 2015 16:48:01 -0400 Subject: [PATCH 7/7] Re-add shebang to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 6a803e49..44f11e62 100755 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/python # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*- # vi: set ft=python sts=4 ts=4 sw=4 noet :