diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index 73042434..f98c6682 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -276,8 +276,10 @@ class Actions(JailThread, Mapping): exc_info=logSys.getEffectiveLevel()<=logging.DEBUG) while self.active: if self.idle: + logSys.debug("Actions: enter idle mode") Utils.wait_for(lambda: not self.active or not self.idle, - self.sleeptime * 10, self.sleeptime) + lambda: False, self.sleeptime) + logSys.debug("Actions: leave idle mode") continue if not Utils.wait_for(lambda: not self.active or self.__checkBan(), self.sleeptime): self.__checkUnBan() diff --git a/fail2ban/tests/actiontestcase.py b/fail2ban/tests/actiontestcase.py index cbd0aaca..4c92057b 100644 --- a/fail2ban/tests/actiontestcase.py +++ b/fail2ban/tests/actiontestcase.py @@ -30,9 +30,10 @@ import time import unittest from ..server.action import CommandAction, CallingMap, substituteRecursiveTags -from ..server.actions import OrderedDict +from ..server.actions import OrderedDict, Actions from ..server.utils import Utils +from .dummyjail import DummyJail from .utils import LogCaptureTestCase from .utils import pid_exists @@ -568,3 +569,19 @@ class CommandActionTest(LogCaptureTestCase): self.assertIn("'b': 11", s) self.assertIn("'c': ", s) # presents as callable self.assertNotIn("'c': ''", s) # but not empty + + def testActionsIdleMode(self): + a = Actions(DummyJail()) + a.sleeptime = 0.0001; # don't need to wait long + # enter idle mode right now (start idle): + a.idle = True; + # start: + a.start() + # wait for enter/leave of idle mode: + self.assertLogged("Actions: enter idle mode", wait=10) + # leave idle mode: + a.idle = False + self.assertLogged("Actions: leave idle mode", wait=10) + # stop it: + a.active = False + a.join() \ No newline at end of file