Add network namespace leak check

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2024-09-17 10:41:32 -06:00
parent b3da5be2b1
commit 7fcf94d7b5

View File

@ -35,6 +35,9 @@ function setup_suite() {
# Canary file. Will be removed if any individual test fails.
touch "$BATS_SUITE_TMPDIR/all-tests-passed"
# Track network namespaces, so we can check for leaks at test end
ip netns list > $BATS_SUITE_TMPDIR/netns-pre
}
# Run at the very end of all tests. Useful for cleanup of non-BATS tmpdirs.
@ -49,6 +52,15 @@ function teardown_suite() {
if [ $? -gt 0 ]; then
exit_code=$((exit_code + 1))
fi
# Network namespace leak check. List should match what we saw above.
echo
ip netns list > $BATS_SUITE_TMPDIR/netns-post
if ! diff -u $BATS_SUITE_TMPDIR/netns-{pre,post}; then
echo
echo "^^^^^ Leaks found in /run/netns ^^^^^"
exit_code=$((exit_code + 1))
fi
fi
return $exit_code