mirror of https://github.com/fail2ban/fail2ban
clean all after test setup (removes a build directory in current root of fail2ban)
parent
7d4f071d4b
commit
a71a64733a
|
@ -68,49 +68,53 @@ class SetupTest(unittest.TestCase):
|
||||||
def testSetupInstallRoot(self):
|
def testSetupInstallRoot(self):
|
||||||
if not self.setup: return # if verbose skip didn't work out
|
if not self.setup: return # if verbose skip didn't work out
|
||||||
tmp = tempfile.mkdtemp()
|
tmp = tempfile.mkdtemp()
|
||||||
os.system("%s %s install --root=%s >/dev/null"
|
try:
|
||||||
% (sys.executable, self.setup, tmp))
|
os.system("%s %s install --root=%s >/dev/null"
|
||||||
|
% (sys.executable, self.setup, tmp))
|
||||||
|
|
||||||
def strippath(l):
|
def strippath(l):
|
||||||
return [x[len(tmp)+1:] for x in l]
|
return [x[len(tmp)+1:] for x in l]
|
||||||
|
|
||||||
got = strippath(sorted(glob('%s/*' % tmp)))
|
got = strippath(sorted(glob('%s/*' % tmp)))
|
||||||
need = ['etc', 'usr', 'var']
|
need = ['etc', 'usr', 'var']
|
||||||
|
|
||||||
# if anything is missing
|
# if anything is missing
|
||||||
if set(need).difference(got): # pragma: no cover
|
if set(need).difference(got): # pragma: no cover
|
||||||
# below code was actually to print out not missing but
|
# below code was actually to print out not missing but
|
||||||
# rather files in 'excess'. Left in place in case we
|
# rather files in 'excess'. Left in place in case we
|
||||||
# decide to revert to such more strict test
|
# decide to revert to such more strict test
|
||||||
|
|
||||||
# based on
|
# based on
|
||||||
# http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
|
# http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
|
||||||
def recursive_glob(treeroot, pattern):
|
def recursive_glob(treeroot, pattern):
|
||||||
results = []
|
results = []
|
||||||
for base, dirs, files in os.walk(treeroot):
|
for base, dirs, files in os.walk(treeroot):
|
||||||
goodfiles = fnmatch.filter(dirs + files, pattern)
|
goodfiles = fnmatch.filter(dirs + files, pattern)
|
||||||
results.extend(os.path.join(base, f) for f in goodfiles)
|
results.extend(os.path.join(base, f) for f in goodfiles)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
files = {}
|
files = {}
|
||||||
for missing in set(got).difference(need):
|
for missing in set(got).difference(need):
|
||||||
missing_full = os.path.join(tmp, missing)
|
missing_full = os.path.join(tmp, missing)
|
||||||
files[missing] = os.path.exists(missing_full) \
|
files[missing] = os.path.exists(missing_full) \
|
||||||
and strippath(recursive_glob(missing_full, '*')) or None
|
and strippath(recursive_glob(missing_full, '*')) or None
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
got, need,
|
got, need,
|
||||||
msg="Got: %s Needed: %s under %s. Files under new paths: %s"
|
msg="Got: %s Needed: %s under %s. Files under new paths: %s"
|
||||||
% (got, need, tmp, files))
|
% (got, need, tmp, files))
|
||||||
|
|
||||||
# Assure presence of some files we expect to see in the installation
|
# Assure presence of some files we expect to see in the installation
|
||||||
for f in ('etc/fail2ban/fail2ban.conf',
|
for f in ('etc/fail2ban/fail2ban.conf',
|
||||||
'etc/fail2ban/jail.conf'):
|
'etc/fail2ban/jail.conf'):
|
||||||
self.assertTrue(os.path.exists(os.path.join(tmp, f)),
|
self.assertTrue(os.path.exists(os.path.join(tmp, f)),
|
||||||
msg="Can't find %s" % f)
|
msg="Can't find %s" % f)
|
||||||
|
finally:
|
||||||
# clean up
|
# clean up
|
||||||
shutil.rmtree(tmp)
|
shutil.rmtree(tmp)
|
||||||
|
# remove build directory
|
||||||
|
os.system("%s %s clean --all >/dev/null"
|
||||||
|
% (sys.executable, self.setup))
|
||||||
|
|
||||||
class TestsUtilsTest(unittest.TestCase):
|
class TestsUtilsTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue