|
|
@ -77,10 +77,10 @@ verbosity = {'debug': 3,
|
|
|
|
'fatal': 0,
|
|
|
|
'fatal': 0,
|
|
|
|
None: 1}[opts.log_level]
|
|
|
|
None: 1}[opts.log_level]
|
|
|
|
|
|
|
|
|
|
|
|
if opts.log_level is not None:
|
|
|
|
if opts.log_level is not None: # pragma: no cover
|
|
|
|
# so we had explicit settings
|
|
|
|
# so we had explicit settings
|
|
|
|
logSys.setLevel(getattr(logging, opts.log_level.upper()))
|
|
|
|
logSys.setLevel(getattr(logging, opts.log_level.upper()))
|
|
|
|
else:
|
|
|
|
else: # pragma: no cover
|
|
|
|
# suppress the logging but it would leave unittests' progress dots
|
|
|
|
# suppress the logging but it would leave unittests' progress dots
|
|
|
|
# ticking, unless like with '-l fatal' which would be silent
|
|
|
|
# ticking, unless like with '-l fatal' which would be silent
|
|
|
|
# unless error occurs
|
|
|
|
# unless error occurs
|
|
|
@ -89,9 +89,9 @@ else:
|
|
|
|
# Add the default logging handler
|
|
|
|
# Add the default logging handler
|
|
|
|
stdout = logging.StreamHandler(sys.stdout)
|
|
|
|
stdout = logging.StreamHandler(sys.stdout)
|
|
|
|
# Custom log format for the verbose tests runs
|
|
|
|
# Custom log format for the verbose tests runs
|
|
|
|
if verbosity > 1:
|
|
|
|
if verbosity > 1: # pragma: no cover
|
|
|
|
stdout.setFormatter(logging.Formatter(' %(asctime)-15s %(thread)s %(message)s'))
|
|
|
|
stdout.setFormatter(logging.Formatter(' %(asctime)-15s %(thread)s %(message)s'))
|
|
|
|
else:
|
|
|
|
else: # pragma: no cover
|
|
|
|
# just prefix with the space
|
|
|
|
# just prefix with the space
|
|
|
|
stdout.setFormatter(logging.Formatter(' %(message)s'))
|
|
|
|
stdout.setFormatter(logging.Formatter(' %(message)s'))
|
|
|
|
logSys.addHandler(stdout)
|
|
|
|
logSys.addHandler(stdout)
|
|
|
@ -99,7 +99,7 @@ logSys.addHandler(stdout)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Let know the version
|
|
|
|
# Let know the version
|
|
|
|
#
|
|
|
|
#
|
|
|
|
if not opts.log_level or opts.log_level != 'fatal':
|
|
|
|
if not opts.log_level or opts.log_level != 'fatal': # pragma: no cover
|
|
|
|
print "Fail2ban %s test suite. Python %s. Please wait..." \
|
|
|
|
print "Fail2ban %s test suite. Python %s. Please wait..." \
|
|
|
|
% (version, str(sys.version).replace('\n', ''))
|
|
|
|
% (version, str(sys.version).replace('\n', ''))
|
|
|
|
|
|
|
|
|
|
|
@ -107,9 +107,9 @@ if not opts.log_level or opts.log_level != 'fatal':
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Gather the tests
|
|
|
|
# Gather the tests
|
|
|
|
#
|
|
|
|
#
|
|
|
|
if not len(regexps):
|
|
|
|
if not len(regexps): # pragma: no cover
|
|
|
|
tests = unittest.TestSuite()
|
|
|
|
tests = unittest.TestSuite()
|
|
|
|
else:
|
|
|
|
else: # pragma: no cover
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
class FilteredTestSuite(unittest.TestSuite):
|
|
|
|
class FilteredTestSuite(unittest.TestSuite):
|
|
|
|
_regexps = [re.compile(r) for r in regexps]
|
|
|
|
_regexps = [re.compile(r) for r in regexps]
|
|
|
@ -159,13 +159,13 @@ filters = [FilterPoll] # always available
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from server.filtergamin import FilterGamin
|
|
|
|
from server.filtergamin import FilterGamin
|
|
|
|
filters.append(FilterGamin)
|
|
|
|
filters.append(FilterGamin)
|
|
|
|
except Exception, e:
|
|
|
|
except Exception, e: # pragma: no cover
|
|
|
|
print "I: Skipping gamin backend testing. Got exception '%s'" % e
|
|
|
|
print "I: Skipping gamin backend testing. Got exception '%s'" % e
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from server.filterpyinotify import FilterPyinotify
|
|
|
|
from server.filterpyinotify import FilterPyinotify
|
|
|
|
filters.append(FilterPyinotify)
|
|
|
|
filters.append(FilterPyinotify)
|
|
|
|
except Exception, e:
|
|
|
|
except Exception, e: # pragma: no cover
|
|
|
|
print "I: Skipping pyinotify backend testing. Got exception '%s'" % e
|
|
|
|
print "I: Skipping pyinotify backend testing. Got exception '%s'" % e
|
|
|
|
|
|
|
|
|
|
|
|
for Filter_ in filters:
|
|
|
|
for Filter_ in filters:
|
|
|
@ -189,7 +189,7 @@ try:
|
|
|
|
|
|
|
|
|
|
|
|
tests_results = testRunner.run(tests)
|
|
|
|
tests_results = testRunner.run(tests)
|
|
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
finally: # pragma: no cover
|
|
|
|
# Just for the sake of it reset the TZ
|
|
|
|
# Just for the sake of it reset the TZ
|
|
|
|
# yoh: move all this into setup/teardown methods within tests
|
|
|
|
# yoh: move all this into setup/teardown methods within tests
|
|
|
|
os.environ.pop('TZ')
|
|
|
|
os.environ.pop('TZ')
|
|
|
@ -197,5 +197,5 @@ finally:
|
|
|
|
os.environ['TZ'] = old_TZ
|
|
|
|
os.environ['TZ'] = old_TZ
|
|
|
|
time.tzset()
|
|
|
|
time.tzset()
|
|
|
|
|
|
|
|
|
|
|
|
if not tests_results.wasSuccessful():
|
|
|
|
if not tests_results.wasSuccessful(): # pragma: no cover
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|