Files
infix/test/nsenter
Tobias Waldekranz b9907fa7ae test: Add nsenter helper script to enter Infamy namespaces
When a test starts an isolated MACVLAN namespace, it is often useful
to interactively join that namespace to investigate issues. To do
this, we need to find the "sleeper" process backing the namespace, and
`nsenter` into that process's network namespace.

Add a script that automates this process.

To start a shell in the netns of the MACVLAN stacked on top of d1b,
start a shell in the test environment:

    infix/test $ ./shell
    13:37:00 infamy0:test # ./nsenter d1b
    13:37:01 infamy0(netns:d1b):test #
2024-05-20 16:21:06 +02:00

25 lines
588 B
Bash
Executable File

#!/bin/sh
set -e
testdir=$(dirname "$(readlink -f "$0")")
. "$testdir/.env"
lower=$1
shift
[ $# -gt 0 ] || set sh
for pid in $(pgrep -fx "sleep infinity"); do
ifidxs=$(nsenter -t $pid -U -n ip -j link show | \
jq '.[] | select(has("link_netnsid")) | .link_index')
for ifidx in $ifidxs; do
ifname=$(ip -j link show | jq -r ".[] | select(.ifindex == $ifidx) | .ifname")
if [ "$ifname" = "$lower" ]; then
exec nsenter -t $pid -U -n env PS1="$(build_ps1 "(netns:$ifname)")" "$@"
fi
done
done
echo Found no namespace with interface stacked on $lower >&2
exit 1