From: Jeremy Sowden Date: Wed, 4 Mar 2026 18:13:03 +0000 (+0000) Subject: tests: iptables-test, xlate-test: use `os.unshare` Python function X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=4986dbaefd1c8b79de92f7d8ac2aea5de04b029e;p=thirdparty%2Fiptables.git tests: iptables-test, xlate-test: use `os.unshare` Python function Since Python 3.12 the standard library has included an `os.unshare` function. Use it if it is available. Signed-off-by: Jeremy Sowden Signed-off-by: Phil Sutter --- diff --git a/iptables-test.py b/iptables-test.py index 66db5521..40ed7703 100755 --- a/iptables-test.py +++ b/iptables-test.py @@ -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) diff --git a/xlate-test.py b/xlate-test.py index 1c8cfe71..24785293 100755 --- a/xlate-test.py +++ b/xlate-test.py @@ -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)