Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
load helpers

function create_netns() {
mtu_value=1789
global_ip="169.254.169.77/32"

# Create a dummy interface to move to the container.
ip link add dummy0 mtu $mtu_value type dummy
udevadm settle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

udevadm settle has to be after the interface is created, that is when the udev event is generated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment just as note for self

ip address add "$global_ip" dev dummy0

# Create a temporary name for the test network namespace.
tmp=$(mktemp -u)
ns_name=$(basename "$tmp")
Expand All @@ -13,22 +21,27 @@ function create_netns() {
}

function delete_netns() {
Comment thread
rata marked this conversation as resolved.
[ -v ns_name ] || return

# 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).
ip link del dev dummy0 2>/dev/null

# Delete the namespace only if the ns_name variable is set.
[ -v ns_name ] && ip netns del "$ns_name"
ip netns del "$ns_name"

unset ns_name
unset ns_path
}

function setup() {
# XXX: currently criu require root containers.
requires criu root

setup_busybox

# Create a dummy interface to move to the container.
ip link add dummy0 type dummy
}

function teardown() {
ip link del dev dummy0
delete_netns
teardown_bundle
}
Expand Down Expand Up @@ -141,15 +154,6 @@ function simple_cr() {
}

@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.
create_netns
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
Expand All @@ -161,7 +165,6 @@ function simple_cr() {
runc exec test_busybox_netdevice ip address show dev dummy0
[ "$status" -eq 0 ]
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
[[ "$output" == *"mtu $mtu_value "* ]]

for _ in $(seq 2); do
Expand All @@ -177,7 +180,6 @@ function simple_cr() {
runc exec test_busybox_netdevice ip address show dev dummy0
[ "$status" -eq 0 ]
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
[[ "$output" == *"mtu $mtu_value "* ]]
done
}
Expand Down
38 changes: 12 additions & 26 deletions tests/integration/netdev.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ function setup_netns() {
}

function delete_netns() {
[ -v ns_name ] || return

# Delete the namespace only if the ns_name variable is set.
[ -v ns_name ] && ip netns del "$ns_name"
ip netns del "$ns_name"

unset ns_name
unset ns_path
}

function setup() {
Expand All @@ -28,10 +33,14 @@ function setup() {

# Create a dummy interface to move to the container.
ip link add dummy0 type dummy
udevadm settle
Comment thread
rata marked this conversation as resolved.
}

function teardown() {
ip link del dev dummy0
# The interface might be on the host or not, depending the test. If it's on the host, let's
# delete it.
ip link del dev dummy0 2>/dev/null

delete_netns
teardown_bundle
}
Expand Down Expand Up @@ -133,24 +142,6 @@ function teardown() {
[[ "$output" == *"mtu $mtu_value "* ]]
}

@test "move network device to precreated container network namespace and set mac address" {
setup_netns
update_config ' .linux.netDevices |= {"dummy0": {} }
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'

mac_address="00:11:22:33:44:55"
# set a custom mac address to the interface
ip link set address "$mac_address" dev dummy0

runc run test_busybox
[ "$status" -eq 0 ]
[[ "$output" == *"ether $mac_address "* ]]

# Verify the interface is still present in the network namespace.
run -0 ip netns exec "$ns_name" ip address show dev dummy0
[[ "$output" == *"ether $mac_address "* ]]
}

@test "move network device to precreated container network namespace and rename" {
setup_netns
update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } }
Expand All @@ -163,31 +154,26 @@ function teardown() {
ip netns exec "$ns_name" ip address show dev ctr_dummy0
}

@test "move network device to precreated container network namespace and rename and set mtu and mac and ip address" {
@test "move network device to precreated container network namespace and rename and set mtu and ip address" {
setup_netns
update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } }
| .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]'

mtu_value=1789
mac_address="00:11:22:33:44:55"
global_ip="169.254.169.77/32"

# Set a custom mtu to the interface.
ip link set mtu "$mtu_value" dev dummy0
# Set a custom mac address to the interface.
ip link set address "$mac_address" dev dummy0
# Set a custom ip address to the interface.
ip address add "$global_ip" dev dummy0

runc run test_busybox
[ "$status" -eq 0 ]
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
[[ "$output" == *"mtu $mtu_value "* ]]

# Verify the interface is still present in the network namespace.
run -0 ip netns exec "$ns_name" ip address show dev ctr_dummy0
[[ "$output" == *" $global_ip "* ]]
[[ "$output" == *"ether $mac_address "* ]]
[[ "$output" == *"mtu $mtu_value "* ]]
}
2 changes: 2 additions & 0 deletions tests/integration/userns.bats
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function teardown() {

# Create a dummy interface to move to the container.
ip link add dummy0 type dummy
udevadm settle

update_config ' .linux.netDevices |= {"dummy0": {} }
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'
Expand All @@ -269,6 +270,7 @@ function teardown() {

# Create a dummy interface to move to the container.
ip link add dummy0 type dummy
udevadm settle

update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } }
| .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]'
Expand Down
Loading