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

From: Jakub Kicinski <[email-masked]>
Date: Sat, 9 Nov 2024 17:01:02 -0800

On Thu,  7 Nov 2024 21:30:03 +0800 Xiao Liang wrote:
> +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