mirror of
https://github.com/containers/podman.git
synced 2025-08-23 09:18:19 +08:00
test/system: netns leak check for rootless as well
This fixes the problem where even as root we check the netns files from root. But in order to catch any rootless bugs we must check the rootless files from $XDG_RUNTIME_DIR/netns. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -37,7 +37,7 @@ function setup_suite() {
|
|||||||
touch "$BATS_SUITE_TMPDIR/all-tests-passed"
|
touch "$BATS_SUITE_TMPDIR/all-tests-passed"
|
||||||
|
|
||||||
# Track network namespaces, so we can check for leaks at test end
|
# Track network namespaces, so we can check for leaks at test end
|
||||||
ip netns list > $BATS_SUITE_TMPDIR/netns-pre
|
check_netns_files > $BATS_SUITE_TMPDIR/netns-pre
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run at the very end of all tests. Useful for cleanup of non-BATS tmpdirs.
|
# Run at the very end of all tests. Useful for cleanup of non-BATS tmpdirs.
|
||||||
@ -54,14 +54,30 @@ function teardown_suite() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Network namespace leak check. List should match what we saw above.
|
# Network namespace leak check. List should match what we saw above.
|
||||||
|
# When they leak we indefinitely leak resources which is bad.
|
||||||
echo
|
echo
|
||||||
ip netns list > $BATS_SUITE_TMPDIR/netns-post
|
check_netns_files > $BATS_SUITE_TMPDIR/netns-post
|
||||||
if ! diff -u $BATS_SUITE_TMPDIR/netns-{pre,post}; then
|
if ! diff -u $BATS_SUITE_TMPDIR/netns-{pre,post}; then
|
||||||
echo
|
echo
|
||||||
echo "^^^^^ Leaks found in /run/netns ^^^^^"
|
echo "^^^^^ Leaks found in $NETNS_DIR ^^^^^"
|
||||||
exit_code=$((exit_code + 1))
|
exit_code=$((exit_code + 1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $exit_code
|
return $exit_code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NETNS_DIR=
|
||||||
|
# List a files in the common netns dir that is used to bind the netns files.
|
||||||
|
function check_netns_files() {
|
||||||
|
if is_rootless; then
|
||||||
|
NETNS_DIR=$XDG_RUNTIME_DIR/netns
|
||||||
|
else
|
||||||
|
NETNS_DIR=/run/netns
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The dir may not exists which is fine
|
||||||
|
if [ -d "$NETNS_DIR" ]; then
|
||||||
|
ls -1 "$NETNS_DIR"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user