]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests: iptables-test, xlate-test: use `os.unshare` Python function
authorJeremy Sowden <jeremy@azazel.net>
Wed, 4 Mar 2026 18:13:03 +0000 (18:13 +0000)
committerPhil Sutter <phil@nwl.cc>
Thu, 5 Mar 2026 10:53:57 +0000 (11:53 +0100)
Since Python 3.12 the standard library has included an `os.unshare` function.
Use it if it is available.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables-test.py
xlate-test.py

index 66db552185bc348d6b7b315cf3857fb04ba7e2bf..40ed77035c02e7b09184c0d8783b5dfccb01cf99 100755 (executable)
@@ -572,7 +572,14 @@ def show_missing():
     print('\n'.join(missing))
 
 def spawn_netns():
-    # prefer unshare module
+    # prefer stdlib unshare function ...
+    try:
+        os.unshare(os.CLONE_NEWNET)
+        return True
+    except Exception as e:
+        pass
+
+    # ... or unshare module
     try:
         import unshare
         unshare.unshare(unshare.CLONE_NEWNET)
index 1c8cfe71ffd46eb6bf898c7232a4da074799f7c4..247852939c9eae1c7649d15357266831ef11b11e 100755 (executable)
@@ -203,7 +203,14 @@ def load_test_files():
 
 
 def spawn_netns():
-    # prefer unshare module
+    # prefer stdlib unshare function ...
+    try:
+        os.unshare(os.CLONE_NEWNET)
+        return True
+    except Exception as e:
+        pass
+
+    # ... or unshare module
     try:
         import unshare
         unshare.unshare(unshare.CLONE_NEWNET)