mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests/int/netdev: slight refactoring
Move the repetitive code and comment into setup_netns. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
load helpers
|
||||
|
||||
function create_netns() {
|
||||
function setup_netns() {
|
||||
local tmp
|
||||
|
||||
# Create a temporary name for the test network namespace.
|
||||
tmp=$(mktemp -u)
|
||||
ns_name=$(basename "$tmp")
|
||||
@@ -10,6 +12,9 @@ function create_netns() {
|
||||
# Create the network namespace.
|
||||
ip netns add "$ns_name"
|
||||
ns_path=$(ip netns add "$ns_name" 2>&1 | sed -e 's/.*"\(.*\)".*/\1/')
|
||||
|
||||
# Tell runc to use it.
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
}
|
||||
|
||||
function delete_netns() {
|
||||
@@ -40,10 +45,7 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to container network namespace and restore it back" {
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= {"dummy0": {} }'
|
||||
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
|
||||
@@ -61,13 +63,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= {"dummy0": {} }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
runc run test_busybox
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
@@ -76,13 +75,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace and set ip address with global scope" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= {"dummy0": {} }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
global_ip="169.254.169.77/32"
|
||||
|
||||
# Set the interface down to avoid possible network problems.
|
||||
@@ -101,13 +97,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace and set ip address without global scope" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= {"dummy0": {} }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
non_global_ip="127.0.0.33"
|
||||
|
||||
# Set the interface down to avoid possible network problems.
|
||||
@@ -124,15 +117,12 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace and set mtu" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= {"dummy0": {} }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
mtu_value=1789
|
||||
# Cet a custom mtu to the interface.
|
||||
# Set a custom mtu to the interface.
|
||||
ip link set mtu "$mtu_value" dev dummy0
|
||||
|
||||
runc run test_busybox
|
||||
@@ -146,13 +136,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@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"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
mac_address="00:11:22:33:44:55"
|
||||
# set a custom mac address to the interface
|
||||
ip link set address "$mac_address" dev dummy0
|
||||
@@ -168,13 +155,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace and rename" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
runc run test_busybox
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
@@ -183,13 +167,10 @@ function teardown() {
|
||||
}
|
||||
|
||||
@test "move network device to precreated container network namespace and rename and set mtu and mac and ip address" {
|
||||
setup_netns
|
||||
update_config ' .linux.netDevices |= { "dummy0": { "name" : "ctr_dummy0" } }
|
||||
| .process.args |= ["ip", "address", "show", "dev", "ctr_dummy0"]'
|
||||
|
||||
# Tell runc which network namespace to use.
|
||||
create_netns
|
||||
update_config '(.. | select(.type? == "network")) .path |= "'"$ns_path"'"'
|
||||
|
||||
mtu_value=1789
|
||||
mac_address="00:11:22:33:44:55"
|
||||
global_ip="169.254.169.77/32"
|
||||
|
||||
Reference in New Issue
Block a user