* [PATCH iptables] tests: iptables-test, xlate-test: use `os.unshare` Python function
@ 2026-03-04 18:13 Jeremy Sowden
2026-03-05 11:11 ` Phil Sutter
0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Sowden @ 2026-03-04 18:13 UTC (permalink / raw)
To: Netfilter Devel
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>
---
iptables-test.py | 9 ++++++++-
xlate-test.py | 9 ++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/iptables-test.py b/iptables-test.py
index 66db552185bc..40ed77035c02 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 1c8cfe71ffd4..247852939c9e 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)
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iptables] tests: iptables-test, xlate-test: use `os.unshare` Python function
2026-03-04 18:13 [PATCH iptables] tests: iptables-test, xlate-test: use `os.unshare` Python function Jeremy Sowden
@ 2026-03-05 11:11 ` Phil Sutter
2026-03-05 11:55 ` Jeremy Sowden
0 siblings, 1 reply; 3+ messages in thread
From: Phil Sutter @ 2026-03-05 11:11 UTC (permalink / raw)
To: Jeremy Sowden; +Cc: Netfilter Devel
On Wed, Mar 04, 2026 at 06:13:03PM +0000, Jeremy Sowden wrote:
> 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>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iptables] tests: iptables-test, xlate-test: use `os.unshare` Python function
2026-03-05 11:11 ` Phil Sutter
@ 2026-03-05 11:55 ` Jeremy Sowden
0 siblings, 0 replies; 3+ messages in thread
From: Jeremy Sowden @ 2026-03-05 11:55 UTC (permalink / raw)
To: Phil Sutter; +Cc: Netfilter Devel
[-- Attachment #1: Type: text/plain, Size: 458 bytes --]
On 2026-03-05, at 12:11:57 +0100, Phil Sutter wrote:
> On Wed, Mar 04, 2026 at 06:13:03PM +0000, Jeremy Sowden wrote:
> > 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>
>
> 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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 931 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-05 11:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 18:13 [PATCH iptables] tests: iptables-test, xlate-test: use `os.unshare` Python function Jeremy Sowden
2026-03-05 11:11 ` Phil Sutter
2026-03-05 11:55 ` Jeremy Sowden
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox