tests: iptables-test, xlate-test: use `os.unshare` Python function
PATCH 1/1 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 <[email protected]>
--- iptables-test.py | 9 ++++++++- xlate-test.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-)
iptables-test.py +8 -1
@@ -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)
xlate-test.py +8 -1
@@ -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)
Signature · 1 line
2.51.0
Phil Sutter
reviewerQuoted 4 lines · Jeremy Sowden
Since Python 3.12 the standard library has included an
os.unsharefunction. Use it if it is available.Signed-off-by Jeremy Sowden <[email protected]>
Patch applied, thanks!
We have the same pattern in nftables' tests/py/nft-test.py, could you please send a patch for that as well?
Thanks, Phil
Quoted 10 lines · Phil Sutter
Quoted 4 lines · Jeremy Sowden
Since Python 3.12 the standard library has included an
os.unsharefunction. Use it if it is available.Signed-off-by Jeremy Sowden <[email protected]>Patch applied, thanks!
We have the same pattern in nftables'
tests/py/nft-test.py, could you please send a patch for that as well?
Yup.
J.