Re: [PATCH net-next v2 8/8] selftests: net: Add two test cases for link netns

From
Jakub Kicinski <kuba@kernel.org>
Date
2024-11-10 01:01:04
Also in
linux-kselftest
Reply to
Xiao Liang, 2024-11-07
On Thu,  7 Nov 2024 21:30:03 +0800 Xiao Liang wrote:
quoted hunk ↗ jump to hunk
+class NSEnter:
+    def __init__(self, ns_name):
+        self.ns_path = f"/run/netns/{ns_name}"
+
+    def __enter__(self):
+        self.saved = open("/proc/thread-self/ns/net")
+        with open(self.ns_path) as ns_file:
+            libc.setns(ns_file.fileno(), 0)
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        libc.setns(self.saved.fileno(), 0)
+        self.saved.close()
This is quite nice, why not move it to
tools/testing/selftests/net/lib/py/netns.py
so others can use it too
Thread (26 messages) 26 messages, 4 authors, last reply 2024-11-12
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help