One more relative path in test configs + tests from upstream PR

pull/2221/head
Yaroslav Halchenko 2018-01-21 21:49:14 -05:00
parent b2688c6c11
commit 404dbc98d3
6 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,34 @@
From 1200f6388a9602e0248171b1a6cb75e073cb96b2 Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <debian@onerussian.com>
Date: Sun, 21 Jan 2018 20:15:56 -0500
Subject: [PATCH 1/4] BF: use tests.utils.CONFIG_DIR instead of hardcoded
"config" in fail2banclienttestcase
Since otherwise cannot provide custom path to the config via env var
and thus cannot test in a build directory which is out of source
---
fail2ban/tests/fail2banclienttestcase.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fail2ban/tests/fail2banclienttestcase.py b/fail2ban/tests/fail2banclienttestcase.py
index 1e2d1b33..65653a8e 100644
--- a/fail2ban/tests/fail2banclienttestcase.py
+++ b/fail2ban/tests/fail2banclienttestcase.py
@@ -44,13 +44,13 @@ from ..server import server
from ..server.mytime import MyTime
from ..server.utils import Utils
from .utils import LogCaptureTestCase, logSys as DefLogSys, with_tmpdir, shutil, logging
+from .utils import CONFIG_DIR as STOCK_CONF_DIR
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getLogger(__name__)
-STOCK_CONF_DIR = "config"
STOCK = exists(pjoin(STOCK_CONF_DIR, 'fail2ban.conf'))
CLIENT = "fail2ban-client"
--
2.15.1

View File

@ -0,0 +1,28 @@
From d1afbb566f0304487b5d578b4aacef8e647ee74b Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <debian@onerussian.com>
Date: Sun, 21 Jan 2018 20:16:43 -0500
Subject: [PATCH 2/4] ENH: verify that use_stock_cfg was not provided while
overriding it
Just found this possibly confusing to outside programmer aspect
so decided to make it more explicit
---
fail2ban/tests/fail2banclienttestcase.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fail2ban/tests/fail2banclienttestcase.py b/fail2ban/tests/fail2banclienttestcase.py
index 65653a8e..94790b04 100644
--- a/fail2ban/tests/fail2banclienttestcase.py
+++ b/fail2ban/tests/fail2banclienttestcase.py
@@ -153,6 +153,8 @@ def _start_params(tmp, use_stock=False, use_stock_cfg=None,
"""Filters list of 'files' to contain only directories (under dir)"""
return [f for f in files if isdir(pjoin(dir, f))]
shutil.copytree(STOCK_CONF_DIR, cfg, ignore=ig_dirs)
+ assert use_stock_cfg is None, \
+ "We are about to overload use_stock_cfg from the one provided %s" % repr(use_stock_cfg)
use_stock_cfg = ('action.d', 'filter.d')
# replace fail2ban params (database with memory):
r = re.compile(r'^dbfile\s*=')
--
2.15.1

View File

@ -0,0 +1,46 @@
From 1618356ad52fbc79e4f7b4d0759ef05bec0ae7f1 Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <debian@onerussian.com>
Date: Sun, 21 Jan 2018 21:05:32 -0500
Subject: [PATCH 3/4] BF: look for system.journal also under system-state-logs
(i.e. /var/log)
as it happens on Debian systems
---
fail2ban/tests/filtertestcase.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py
index 1803974b..b707beb5 100644
--- a/fail2ban/tests/filtertestcase.py
+++ b/fail2ban/tests/filtertestcase.py
@@ -1173,11 +1173,22 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover
super(MonitorJournalFailures, self).tearDown()
def _getRuntimeJournal(self):
- # retrieve current system journal path
- tmp = Utils.executeCmd('find "$(systemd-path system-runtime-logs)" -name system.journal',
- timeout=10, shell=True, output=True);
- self.assertTrue(tmp)
- return str(tmp[1].decode('utf-8')).split('\n')[0]
+ """Retrieve current system journal path
+
+ If none found, None will be returned
+ """
+ # Depending on the system, it could be found under /run or /var/log (e.g. Debian)
+ # which are pointed by different systemd-path variables. We will
+ # check one at at time until the first hit
+ for systemd_var in 'system-runtime-logs', 'system-state-logs':
+ tmp = Utils.executeCmd(
+ 'find "$(systemd-path %s)" -name system.journal' % systemd_var,
+ timeout=10, shell=True, output=True
+ )
+ self.assertTrue(tmp)
+ out = str(tmp[1].decode('utf-8')).split('\n')[0]
+ if out:
+ return out
def testJournalFilesArg(self):
# retrieve current system journal path
--
2.15.1

View File

@ -0,0 +1,34 @@
From 4d2fdd72e7463a9f6ed7ded9b58f81f4fd7688dc Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <debian@onerussian.com>
Date: Sun, 21 Jan 2018 21:23:02 -0500
Subject: [PATCH 4/4] BF: use build_*_2to3 if in _2to3
On Debian systems py helpers first do python setup.py build
so conversion should happen then. Manual invocation of
./fail2ban-2to3 is least preferred since modifies in place
and would require additional special handling to monitor
changed files etc
---
setup.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/setup.py b/setup.py
index 8da29268..850f748f 100755
--- a/setup.py
+++ b/setup.py
@@ -208,8 +208,10 @@ setup(
license = "GPL",
platforms = "Posix",
cmdclass = {
- 'build_py': build_py, 'build_scripts': build_scripts,
- 'install_scripts': install_scripts_f2b, 'install': install_command_f2b
+ 'build_py': build_py_2to3 if _2to3 else build_py,
+ 'build_scripts': build_scripts_2to3 if _2to3 else build_scripts,
+ 'install_scripts': install_scripts_f2b,
+ 'install': install_command_f2b
},
scripts = [
'bin/fail2ban-client',
--
2.15.1

View File

@ -9,3 +9,14 @@
[Definition]
--- a/fail2ban/tests/config/filter.d/zzz-sshd-obsolete-multiline.conf
+++ b/fail2ban/tests/config/filter.d/zzz-sshd-obsolete-multiline.conf
@@ -5,7 +5,7 @@
# Read common prefixes. If any customizations available -- read them from
# common.local
-before = ../../../../config/filter.d/common.conf
+before = ../../../../../../../config/filter.d/common.conf
[DEFAULT]

View File

@ -1,3 +1,7 @@
deb_path_to_common
deb_init_paths
deb_manpages_reportbug
0001-BF-use-tests.utils.CONFIG_DIR-instead-of-hardcoded-c.patch
0002-ENH-verify-that-use_stock_cfg-was-not-provided-while.patch
0003-BF-look-for-system.journal-also-under-system-state-l.patch
0004-BF-use-build_-_2to3-if-in-_2to3.patch