mirror of https://github.com/fail2ban/fail2ban
code review (e. g. remove code duplication) and coverage
parent
5b40309052
commit
7f8c48d59e
|
@ -310,7 +310,7 @@ class Fail2banClient(Fail2banCmdLine, Thread):
|
|||
# stop options - jail name or --all
|
||||
break
|
||||
if self.__ping(timeout=-1):
|
||||
if len(cmd) == 1:
|
||||
if len(cmd) == 1 or cmd[1] == '--all':
|
||||
jail = '--all'
|
||||
ret, stream = self.readConfig()
|
||||
else:
|
||||
|
|
|
@ -81,12 +81,12 @@ class Server:
|
|||
}
|
||||
self.__prev_signals = {}
|
||||
|
||||
def __sigTERMhandler(self, signum, frame):
|
||||
logSys.debug("Caught signal %d. Exiting" % signum)
|
||||
def __sigTERMhandler(self, signum, frame): # pragma: no cover - indirect tested
|
||||
logSys.debug("Caught signal %d. Exiting", signum)
|
||||
self.quit()
|
||||
|
||||
def __sigUSR1handler(self, signum, fname):
|
||||
logSys.debug("Caught signal %d. Flushing logs" % signum)
|
||||
def __sigUSR1handler(self, signum, fname): # pragma: no cover - indirect tested
|
||||
logSys.debug("Caught signal %d. Flushing logs", signum)
|
||||
self.flushLogs()
|
||||
|
||||
def _rebindSignal(self, s, new):
|
||||
|
@ -137,12 +137,12 @@ class Server:
|
|||
|
||||
# Creates a PID file.
|
||||
try:
|
||||
logSys.debug("Creating PID file %s" % pidfile)
|
||||
logSys.debug("Creating PID file %s", pidfile)
|
||||
pidFile = open(pidfile, 'w')
|
||||
pidFile.write("%s\n" % os.getpid())
|
||||
pidFile.close()
|
||||
except IOError as e:
|
||||
logSys.error("Unable to create PID file: %s" % e)
|
||||
except (OSError, IOError) as e: # pragma: no cover
|
||||
logSys.error("Unable to create PID file: %s", e)
|
||||
|
||||
# Start the communication
|
||||
logSys.debug("Starting communication")
|
||||
|
@ -154,10 +154,10 @@ class Server:
|
|||
logSys.error("Could not start server: %s", e)
|
||||
# Removes the PID file.
|
||||
try:
|
||||
logSys.debug("Remove PID file %s" % pidfile)
|
||||
logSys.debug("Remove PID file %s", pidfile)
|
||||
os.remove(pidfile)
|
||||
except OSError as e:
|
||||
logSys.error("Unable to remove PID file: %s" % e)
|
||||
except (OSError, IOError) as e: # pragma: no cover
|
||||
logSys.error("Unable to remove PID file: %s", e)
|
||||
logSys.info("Exiting Fail2ban")
|
||||
|
||||
def quit(self):
|
||||
|
@ -250,7 +250,7 @@ class Server:
|
|||
def reloadJails(self, name, opts, begin):
|
||||
if begin:
|
||||
# begin reload:
|
||||
if self.__reload_state and (name == '--all' or self.__reload_state.get(name)):
|
||||
if self.__reload_state and (name == '--all' or self.__reload_state.get(name)): # pragma: no cover
|
||||
raise ValueError('Reload already in progress')
|
||||
logSys.info("Reload " + (("jail %s" % name) if name != '--all' else "all jails"))
|
||||
with self.__lock:
|
||||
|
@ -381,11 +381,8 @@ class Server:
|
|||
|
||||
def addFailRegex(self, name, value, multiple=False):
|
||||
flt = self.__jails[name].filter
|
||||
if multiple:
|
||||
for value in value:
|
||||
logSys.debug(" failregex: %r", value)
|
||||
flt.addFailRegex(value)
|
||||
else:
|
||||
if not multiple: value = (value,)
|
||||
for value in value:
|
||||
logSys.debug(" failregex: %r", value)
|
||||
flt.addFailRegex(value)
|
||||
|
||||
|
@ -397,11 +394,8 @@ class Server:
|
|||
|
||||
def addIgnoreRegex(self, name, value, multiple=False):
|
||||
flt = self.__jails[name].filter
|
||||
if multiple:
|
||||
for value in value:
|
||||
logSys.debug(" ignoreregex: %r", value)
|
||||
flt.addIgnoreRegex(value)
|
||||
else:
|
||||
if not multiple: value = (value,)
|
||||
for value in value:
|
||||
logSys.debug(" ignoreregex: %r", value)
|
||||
flt.addIgnoreRegex(value)
|
||||
|
||||
|
@ -671,7 +665,7 @@ class Server:
|
|||
if Fail2BanDb is not None:
|
||||
self.__db = Fail2BanDb(filename)
|
||||
self.__db.delAllJails()
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
logSys.error(
|
||||
"Unable to import fail2ban database module as sqlite "
|
||||
"is not available.")
|
||||
|
|
|
@ -1026,4 +1026,11 @@ class Fail2banServerTest(Fail2banClientServerBase):
|
|||
self.assertNotLogged(
|
||||
"Creating new jail 'test-jail2'",
|
||||
"Jail 'test-jail2' started", all=True)
|
||||
self.pruneLog()
|
||||
|
||||
# restart all jails (without restart server):
|
||||
self.pruneLog("[test-phase end-2]")
|
||||
self.execSuccess(startparams,
|
||||
"--async", "reload", "--restart", "--all")
|
||||
self.assertLogged(
|
||||
"Jail 'test-jail1' stopped",
|
||||
"Jail 'test-jail1' started", all=True)
|
||||
|
|
Loading…
Reference in New Issue