tests/checkpoint.bats: Move netdev code outside of setup()

We are creating the interface for every test, but there is only one
using it. Let's just call the function to create the netdev on the test
that uses it.

I guess that was the reason we had the "ip link del ..." in teardown.
Because in a lot of tests we were just creating and deleting the
interface on the host.

While we are there, as suggested by lifubang, let's make the "ip link
add" line specify the mtu and mac addr. This way, the interface is not
created without that info and we race with host daemons (like udev) that
_might_ want to change it.

Signed-off-by: Rodrigo Campos <rodrigo@amutable.com>
(cherry picked from commit b16ed9a0b8)
This commit is contained in:
Rodrigo Campos
2026-06-17 12:53:47 +02:00
committed by Rodrigo Campos Catelin
parent 5514481f13
commit 591db7d0ca
+15 -14
View File
@@ -3,6 +3,17 @@
load helpers load helpers
function create_netns() { function create_netns() {
mtu_value=1789
mac_address="00:11:22:33:44:55"
global_ip="169.254.169.77/32"
# Create a dummy interface to move to the container.
# Specify all link-level parameters at creation time, this way it is not created without
# those values unassigned and we might race with host's daemons to set them.
ip link add dummy0 address "$mac_address" mtu $mtu_value type dummy
udevadm settle
ip address add "$global_ip" dev dummy0
# Create a temporary name for the test network namespace. # Create a temporary name for the test network namespace.
tmp=$(mktemp -u) tmp=$(mktemp -u)
ns_name=$(basename "$tmp") ns_name=$(basename "$tmp")
@@ -13,6 +24,10 @@ function create_netns() {
} }
function delete_netns() { function delete_netns() {
# The interface shouldn't be on the host, but if we failed to move it to the container, it
# might. Let's delete it if we created one (i.e. if ns_name is defined).
[ -v ns_name ] && ip link del dev dummy0 2>/dev/null
# Delete the namespace only if the ns_name variable is set. # Delete the namespace only if the ns_name variable is set.
[ -v ns_name ] && ip netns del "$ns_name" [ -v ns_name ] && ip netns del "$ns_name"
} }
@@ -22,14 +37,9 @@ function setup() {
requires criu root requires criu root
setup_busybox setup_busybox
# Create a dummy interface to move to the container.
ip link add dummy0 type dummy
udevadm settle
} }
function teardown() { function teardown() {
ip link del dev dummy0
delete_netns delete_netns
teardown_bundle teardown_bundle
} }
@@ -140,15 +150,6 @@ function simple_cr() {
} }
@test "checkpoint and restore with netdevice" { @test "checkpoint and restore with netdevice" {
# Set custom parameters to the netdevice to validate those are respected
mtu_value=1789
mac_address="00:11:22:33:44:55"
global_ip="169.254.169.77/32"
ip link set mtu "$mtu_value" dev dummy0
ip link set address "$mac_address" dev dummy0
ip address add "$global_ip" dev dummy0
# Tell runc which network namespace to use. # Tell runc which network namespace to use.
create_netns create_netns
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"' update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'