summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Johannes Messner <manuel.johannes.messner@hs-furtwangen.de>2016-09-05 20:20:12 +0200
committerFlorian Westphal <fw@strlen.de>2016-09-06 13:09:41 +0200
commit3e5b0e406cf2b635200f9ee05ba8a158528fe622 (patch)
tree4b252ff313a2091856ea8a8aadebe36f7f025b66
parentbc4908b79a80fba8ce5c02aac52e40d16ec95aad (diff)
tests: py: nft-tests.py: Add function for loading and removing kernel modules
Some tests use the dummy kernel module. This commit adds a function to automatically load that module and remove it afterwards. Signed-off-by: Manuel Johannes Messner <manuel.johannes.messner@hs-furtwangen.de> Signed-off-by: Florian Westphal <fw@strlen.de>
-rwxr-xr-xtests/py/nft-test.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index fc7ae608..c1217bbb 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -28,6 +28,7 @@ table_list = []
chain_list = []
all_set = dict()
signal_received = 0
+modules = []
class Colors:
@@ -114,6 +115,30 @@ def print_differences_error(filename, lineno, cmd):
str(lineno + 1) + ": '" + cmd + "': " + reason
+def cleanup_modules():
+ for i in modules:
+ modprobe(i, remove=True)
+
+
+def modprobe(name, remove=False):
+ '''
+ Loads or removes a kernel module
+ '''
+ if name is None:
+ return -1
+
+ cmds = {
+ 'ins': ['modprobe', '--first-time', '--quiet', name],
+ 'del': ['modprobe', '-r', name],
+ }
+
+ ret = subprocess.call(cmds['del' if remove else 'ins']) == 0
+ if ret and not remove:
+ # the kernel module has been loaded -> remove it afterwards
+ global modules
+ modules.append(name)
+
+
def table_exist(table, filename, lineno):
'''
Exists a table.
@@ -686,6 +711,8 @@ def cleanup_on_exit():
set_delete(table)
table_delete(table)
+ cleanup_modules()
+
def signal_handler(signal, frame):
global signal_received
@@ -965,6 +992,8 @@ def main():
print "The nft binary does not exist. You need to build the project."
return
+ modprobe('dummy')
+
test_files = files_ok = run_total = 0
tests = passed = warnings = errors = 0
global log_file
@@ -972,6 +1001,7 @@ def main():
log_file = open(LOGFILE, 'w')
except IOError:
print "Cannot open log file %s" % LOGFILE
+ cleanup_modules()
return
file_list = []
@@ -1020,6 +1050,8 @@ def main():
"%d error, %d warning" \
% (test_files, files_ok, tests, errors, warnings)
+ cleanup_modules()
+
if __name__ == '__main__':
main()