Commit f6476ded authored by Hangbin Liu's avatar Hangbin Liu Committed by David S. Miller

selftests/net: convert netns-name.sh to run it in unique namespace

This test will move the device to netns 1. Add a new test_ns to do this.
Here is the test result after conversion.

 # ./netns-name.sh
 netns-name.sh                           [  OK  ]
Acked-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b84c2fae
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
source lib.sh
set -o pipefail set -o pipefail
NS=netns-name-test
DEV=dummy-dev0 DEV=dummy-dev0
DEV2=dummy-dev1 DEV2=dummy-dev1
ALT_NAME=some-alt-name ALT_NAME=some-alt-name
...@@ -11,7 +11,7 @@ ALT_NAME=some-alt-name ...@@ -11,7 +11,7 @@ ALT_NAME=some-alt-name
RET_CODE=0 RET_CODE=0
cleanup() { cleanup() {
ip netns del $NS cleanup_ns $NS $test_ns
} }
trap cleanup EXIT trap cleanup EXIT
...@@ -21,50 +21,50 @@ fail() { ...@@ -21,50 +21,50 @@ fail() {
RET_CODE=1 RET_CODE=1
} }
ip netns add $NS setup_ns NS test_ns
# #
# Test basic move without a rename # Test basic move without a rename
# #
ip -netns $NS link add name $DEV type dummy || fail ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 || ip -netns $NS link set dev $DEV netns $test_ns ||
fail "Can't perform a netns move" fail "Can't perform a netns move"
ip link show dev $DEV >> /dev/null || fail "Device not found after move" ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
ip link del $DEV || fail ip -netns $test_ns link del $DEV || fail
# #
# Test move with a conflict # Test move with a conflict
# #
ip link add name $DEV type dummy ip -netns $test_ns link add name $DEV type dummy
ip -netns $NS link add name $DEV type dummy || fail ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 2> /dev/null && ip -netns $NS link set dev $DEV netns $test_ns 2> /dev/null &&
fail "Performed a netns move with a name conflict" fail "Performed a netns move with a name conflict"
ip link show dev $DEV >> /dev/null || fail "Device not found after move" ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
ip -netns $NS link del $DEV || fail ip -netns $NS link del $DEV || fail
ip link del $DEV || fail ip -netns $test_ns link del $DEV || fail
# #
# Test move with a conflict and rename # Test move with a conflict and rename
# #
ip link add name $DEV type dummy ip -netns $test_ns link add name $DEV type dummy
ip -netns $NS link add name $DEV type dummy || fail ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link set dev $DEV netns 1 name $DEV2 || ip -netns $NS link set dev $DEV netns $test_ns name $DEV2 ||
fail "Can't perform a netns move with rename" fail "Can't perform a netns move with rename"
ip link del $DEV2 || fail ip -netns $test_ns link del $DEV2 || fail
ip link del $DEV || fail ip -netns $test_ns link del $DEV || fail
# #
# Test dup alt-name with netns move # Test dup alt-name with netns move
# #
ip link add name $DEV type dummy || fail ip -netns $test_ns link add name $DEV type dummy || fail
ip link property add dev $DEV altname $ALT_NAME || fail ip -netns $test_ns link property add dev $DEV altname $ALT_NAME || fail
ip -netns $NS link add name $DEV2 type dummy || fail ip -netns $NS link add name $DEV2 type dummy || fail
ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail
ip -netns $NS link set dev $DEV2 netns 1 2> /dev/null && ip -netns $NS link set dev $DEV2 netns $test_ns 2> /dev/null &&
fail "Moved with alt-name dup" fail "Moved with alt-name dup"
ip link del $DEV || fail ip -netns $test_ns link del $DEV || fail
ip -netns $NS link del $DEV2 || fail ip -netns $NS link del $DEV2 || fail
# #
...@@ -72,11 +72,11 @@ ip -netns $NS link del $DEV2 || fail ...@@ -72,11 +72,11 @@ ip -netns $NS link del $DEV2 || fail
# #
ip -netns $NS link add name $DEV type dummy || fail ip -netns $NS link add name $DEV type dummy || fail
ip -netns $NS link property add dev $DEV altname $ALT_NAME || fail ip -netns $NS link property add dev $DEV altname $ALT_NAME || fail
ip -netns $NS link set dev $DEV netns 1 || fail ip -netns $NS link set dev $DEV netns $test_ns || fail
ip link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move" ip -netns $test_ns link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move"
ip -netns $NS link show dev $ALT_NAME 2> /dev/null && ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
fail "Can still find alt-name after move" fail "Can still find alt-name after move"
ip link del $DEV || fail ip -netns $test_ns link del $DEV || fail
echo -ne "$(basename $0) \t\t\t\t" echo -ne "$(basename $0) \t\t\t\t"
if [ $RET_CODE -eq 0 ]; then if [ $RET_CODE -eq 0 ]; then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment