From 46a8899f20b6513036bb62faf5d0eb7b02b0ad00 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 29 Oct 2014 19:27:45 +0100 Subject: [PATCH] code review --- fail2ban/server/actions.py | 4 +++- fail2ban/tests/servertestcase.py | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index a36802bc..d145f338 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -244,7 +244,7 @@ class Actions(JailThread, Mapping): return True def __getBansMerged(self, mi, idx): - """Helper for lamda to get bans merged once + """Gets bans merged once, a helper for lambda(s), prevents stop of executing action by any exception inside. This function never returns None for ainfo lambdas - always a ticket (merged or single one) and prevents any errors through merging (to guarantee ban actions will be executed). @@ -274,6 +274,8 @@ class Actions(JailThread, Mapping): mi[idx] = jail.database.getBansMerged(ip=ip) elif idx == 'jail': mi[idx] = jail.database.getBansMerged(ip=ip, jail=jail) + else: # pragma: no cover + raise ValueError("Unknown value %r for idx" % (idx,)) except Exception as e: logSys.error( "Failed to get %s bans merged, jail '%s': %s", diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 362f4253..e018ed2f 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -817,10 +817,12 @@ class LoggingTests(LogCaptureTestCase): prev_exchook = sys.__excepthook__ x = [] sys.__excepthook__ = lambda *args: x.append(args) - badThread = _BadThread() - badThread.start() - badThread.join() - self.assertTrue(self._is_logged("Unhandled exception")) - sys.__excepthook__ = prev_exchook + try: + badThread = _BadThread() + badThread.start() + badThread.join() + self.assertTrue(self._is_logged("Unhandled exception")) + finally: + sys.__excepthook__ = prev_exchook self.assertEqual(len(x), 1) self.assertEqual(x[0][0], RuntimeError)