Skip to contentSkip to conversation

iptables-test.py: Accept multiple test files on commandline

PATCH New Phil Sutter 1 participant 2 messages Nov 17, 2020 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/2 iptables-test.py: Accept multiple test files on commandline

This allows to call the script like so:

| # ./iptables-test.py -n extensions/libebt_*.t

---
 iptables-test.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
iptables-test.py +2 -2
index 6b6eb611a7290..52897a5d93ced 100755
@@ -310,7 +310,7 @@ def show_missing():
 #
 def main():
     parser = argparse.ArgumentParser(description='Run iptables tests')
-    parser.add_argument('filename', nargs='?',
+    parser.add_argument('filename', nargs='*',
                         metavar='path/to/file.t',
                         help='Run only this test')
     parser.add_argument('-H', '--host', action='store_true',
@@ -359,7 +359,7 @@ def main():
         return
 
     if args.filename:
-        file_list = [args.filename]
+        file_list = args.filename
     else:
         file_list = [os.path.join(EXTENSIONS_PATH, i)
                      for i in os.listdir(EXTENSIONS_PATH)
Signature · 1 line
2.28.0
author reviewer
#1 lore raw

PATCH 2/2 iptables-test.py: Try to unshare netns by default

If user did not explicitly requst to "test netnamespace path", try an import of 'unshare' module and call unshare() to avoid killing the local host's network by accident.

---
 iptables-test.py | 7 +++++++
 1 file changed, 7 insertions(+)
iptables-test.py +7 -0
index 52897a5d93ced..ca5efb1b6670b 100755
@@ -366,6 +366,13 @@ def main():
                      if i.endswith('.t')]
         file_list.sort()
 
+    if not args.netns:
+        try:
+            import unshare
+            unshare.unshare(unshare.CLONE_NEWNET)
+        except:
+            print("Cannot run in own namespace, connectivity might break")
+
     for filename in file_list:
         file_tests, file_passed = run_test_file(filename, args.netns)
         if file_tests:
Signature · 1 line
2.28.0