Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run nft tests in netns #18

Merged
merged 1 commit into from
Mar 16, 2024
Merged

Run nft tests in netns #18

merged 1 commit into from
Mar 16, 2024

Conversation

jwhb
Copy link
Member

@jwhb jwhb commented Mar 15, 2024

Tests that use nft command alter the system's nftables.
By creating a fresh net namespace for each run, tests will not break system networking.

Tests that use nft command alter the system's
nftables. By creating a fresh net namespace for
each run, tests will not break system networking.
@jwhb jwhb marked this pull request as ready for review March 16, 2024 00:01
@jwhb jwhb merged commit 6ca0019 into main Mar 16, 2024
1 check passed
@jwhb jwhb deleted the netns-test branch March 16, 2024 00:06
(ip netns ls | grep -Fx "$NETNS" 2>/dev/null) || ip netns add "$NETNS"

nft --version;
nsexec cargo test --verbose -- --ignored
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, it should be much simpler to just use unshare -n cargo ... to create a new netns here, no need to manage any ip netns "names". You can also do unshare -rn as normal user (assuming unprivileged user namespaces are enabled, which is the default for most distros) so not even a need for sudo.
Because the netns is only tied to the process once the process exits the netns will be gone so you also can skip the clean-up logic as well

@jwhb jwhb mentioned this pull request Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants