selftests: net: Add python context manager for netns entering
authorXiao Liang <shaw.leon@gmail.com>
Wed, 19 Feb 2025 12:50:38 +0000 (20:50 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 21 Feb 2025 23:28:03 +0000 (15:28 -0800)
commit030329416232ff9f2e3e4bb065b29e6c9a7d5050
treef3a21746dcb001af24c8148945e662d0775777fc
parent7ca486d08a30936e3b45f535d920848828fefb33
selftests: net: Add python context manager for netns entering

Change netns of current thread and switch back on context exit.
For example:

    with NetNSEnter("ns1"):
        ip("link add dummy0 type dummy")

The command be executed in netns "ns1".

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Link: https://patch.msgid.link/20250219125039.18024-13-shaw.leon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/lib/py/__init__.py
tools/testing/selftests/net/lib/py/netns.py