[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241109170102.05a5c3f7@kernel.org>
Date: Sat, 9 Nov 2024 17:01:02 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Xiao Liang <shaw.leon@...il.com>
Cc: netdev@...r.kernel.org, linux-kselftest@...r.kernel.org, Kuniyuki
Iwashima <kuniyu@...zon.com>, "David S. Miller" <davem@...emloft.net>,
David Ahern <dsahern@...nel.org>, Eric Dumazet <edumazet@...gle.com>, Paolo
Abeni <pabeni@...hat.com>, Ido Schimmel <idosch@...dia.com>, Andrew Lunn
<andrew+netdev@...n.ch>, Simon Horman <horms@...nel.org>, Donald Hunter
<donald.hunter@...il.com>, Shuah Khan <shuah@...nel.org>, Jiri Pirko
<jiri@...nulli.us>, Hangbin Liu <liuhangbin@...il.com>
Subject: Re: [PATCH net-next v2 8/8] selftests: net: Add two test cases for
link netns
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
Powered by blists - more mailing lists