diff --git a/.travis.yml b/.travis.yml index 8cfeeff1..4d312575 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,6 @@ script: - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc setup.py test; else python setup.py test; fi 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 diff --git a/.travis_coveragerc b/.travis_coveragerc index 49fc3134..70cdc3e3 100644 --- a/.travis_coveragerc +++ b/.travis_coveragerc @@ -5,3 +5,11 @@ omit = /usr/* /home/travis/virtualenv/* fail2ban/server/filtersystemd.py + +[report] +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # systemd backend related + pragma: systemd no cover diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index 4e892acb..51d9fd94 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -648,7 +648,7 @@ class FileContainer: # # Base interface class for systemd journal filters -class JournalFilter(Filter): +class JournalFilter(Filter): # pragma: systemd no cover def addJournalMatch(self, match): pass diff --git a/fail2ban/server/filtersystemd.py b/fail2ban/server/filtersystemd.py index 3664a5bf..2c3ca0ae 100644 --- a/fail2ban/server/filtersystemd.py +++ b/fail2ban/server/filtersystemd.py @@ -45,7 +45,7 @@ logSys = logging.getLogger("fail2ban.filter") # else that matches a given regular expression. This class is instantiated by # a Jail object. -class FilterSystemd(JournalFilter): +class FilterSystemd(JournalFilter): # pragma: systemd no cover ## # Constructor. # diff --git a/fail2ban/server/jail.py b/fail2ban/server/jail.py index a53f1c0d..86b901af 100644 --- a/fail2ban/server/jail.py +++ b/fail2ban/server/jail.py @@ -101,7 +101,7 @@ class Jail: from filterpyinotify import FilterPyinotify self.__filter = FilterPyinotify(self) - def _initSystemd(self): + def _initSystemd(self): # pragma: systemd no cover # Try to import systemd import systemd logSys.info("Jail '%s' uses systemd" % self.__name) diff --git a/fail2ban/server/server.py b/fail2ban/server/server.py index c411820c..436aa40e 100644 --- a/fail2ban/server/server.py +++ b/fail2ban/server/server.py @@ -184,21 +184,21 @@ class Server: if isinstance(filter_, FileFilter): return [m.getFileName() for m in filter_.getLogPath()] - else: + else: # pragma: systemd no cover logSys.info("Jail %s is not a FileFilter instance" % name) return [] - def addJournalMatch(self, name, match): + def addJournalMatch(self, name, match): # pragma: systemd no cover filter_ = self.__jails.getFilter(name) if isinstance(filter_, JournalFilter): filter_.addJournalMatch(match) - def delJournalMatch(self, name, match): + def delJournalMatch(self, name, match): # pragma: systemd no cover filter_ = self.__jails.getFilter(name) if isinstance(filter_, JournalFilter): filter_.delJournalMatch(match) - def getJournalMatch(self, name): + def getJournalMatch(self, name): # pragma: systemd no cover filter_ = self.__jails.getFilter(name) if isinstance(filter_, JournalFilter): return filter_.getJournalMatch() diff --git a/fail2ban/server/transmitter.py b/fail2ban/server/transmitter.py index c012ceac..8bacdd0a 100644 --- a/fail2ban/server/transmitter.py +++ b/fail2ban/server/transmitter.py @@ -144,11 +144,11 @@ class Transmitter: value = command[2] self.__server.setLogEncoding(name, value) return self.__server.getLogEncoding(name) - elif command[1] == "addjournalmatch": + elif command[1] == "addjournalmatch": # pragma: systemd no cover value = ' '.join(command[2:]) self.__server.addJournalMatch(name, value) return self.__server.getJournalMatch(name) - elif command[1] == "deljournalmatch": + elif command[1] == "deljournalmatch": # pragma: systemd no cover value = ' '.join(command[2:]) self.__server.delJournalMatch(name, value) return self.__server.getJournalMatch(name) @@ -258,7 +258,7 @@ class Transmitter: return self.__server.getLogPath(name) elif command[1] == "logencoding": return self.__server.getLogEncoding(name) - elif command[1] == "journalmatch": + elif command[1] == "journalmatch": # pragma: systemd no cover return self.__server.getJournalMatch(name) elif command[1] == "ignoreip": return self.__server.getIgnoreIP(name) diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index 0fe2367a..c2f43fb4 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -165,7 +165,7 @@ def _copy_lines_between_files(in_, fout, n=None, skip=0, mode='a', terminal_line time.sleep(0.1) return fout -def _copy_lines_to_journal(in_, fields={},n=None, skip=0, terminal_line=""): +def _copy_lines_to_journal(in_, fields={},n=None, skip=0, terminal_line=""): # pragma: systemd no cover """Copy lines from one file to systemd journal Returns None @@ -607,7 +607,7 @@ def get_monitor_failures_testcase(Filter_): % (Filter_.__name__, testclass_name) # 'tempfile') return MonitorFailures -def get_monitor_failures_journal_testcase(Filter_): +def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover """Generator of TestCase's for journal based filters/backends """ diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 2e089445..160dc802 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -201,7 +201,7 @@ def gatherTests(regexps=None, no_network=False): for Filter_ in filters: tests.addTest(unittest.makeSuite( filtertestcase.get_monitor_failures_testcase(Filter_))) - try: + try: # pragma: systemd no cover from fail2ban.server.filtersystemd import FilterSystemd tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd))) except Exception, e: # pragma: no cover