Skip to content

Commit f6476de

Browse files
liuhangbindavem330
authored andcommitted
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: David Ahern <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b84c2fa commit f6476de

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

tools/testing/selftests/net/netns-name.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
source lib.sh
45
set -o pipefail
56

6-
NS=netns-name-test
77
DEV=dummy-dev0
88
DEV2=dummy-dev1
99
ALT_NAME=some-alt-name
1010

1111
RET_CODE=0
1212

1313
cleanup() {
14-
ip netns del $NS
14+
cleanup_ns $NS $test_ns
1515
}
1616

1717
trap cleanup EXIT
@@ -21,62 +21,62 @@ fail() {
2121
RET_CODE=1
2222
}
2323

24-
ip netns add $NS
24+
setup_ns NS test_ns
2525

2626
#
2727
# Test basic move without a rename
2828
#
2929
ip -netns $NS link add name $DEV type dummy || fail
30-
ip -netns $NS link set dev $DEV netns 1 ||
30+
ip -netns $NS link set dev $DEV netns $test_ns ||
3131
fail "Can't perform a netns move"
32-
ip link show dev $DEV >> /dev/null || fail "Device not found after move"
33-
ip link del $DEV || fail
32+
ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
33+
ip -netns $test_ns link del $DEV || fail
3434

3535
#
3636
# Test move with a conflict
3737
#
38-
ip link add name $DEV type dummy
38+
ip -netns $test_ns link add name $DEV type dummy
3939
ip -netns $NS link add name $DEV type dummy || fail
40-
ip -netns $NS link set dev $DEV netns 1 2> /dev/null &&
40+
ip -netns $NS link set dev $DEV netns $test_ns 2> /dev/null &&
4141
fail "Performed a netns move with a name conflict"
42-
ip link show dev $DEV >> /dev/null || fail "Device not found after move"
42+
ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found after move"
4343
ip -netns $NS link del $DEV || fail
44-
ip link del $DEV || fail
44+
ip -netns $test_ns link del $DEV || fail
4545

4646
#
4747
# Test move with a conflict and rename
4848
#
49-
ip link add name $DEV type dummy
49+
ip -netns $test_ns link add name $DEV type dummy
5050
ip -netns $NS link add name $DEV type dummy || fail
51-
ip -netns $NS link set dev $DEV netns 1 name $DEV2 ||
51+
ip -netns $NS link set dev $DEV netns $test_ns name $DEV2 ||
5252
fail "Can't perform a netns move with rename"
53-
ip link del $DEV2 || fail
54-
ip link del $DEV || fail
53+
ip -netns $test_ns link del $DEV2 || fail
54+
ip -netns $test_ns link del $DEV || fail
5555

5656
#
5757
# Test dup alt-name with netns move
5858
#
59-
ip link add name $DEV type dummy || fail
60-
ip link property add dev $DEV altname $ALT_NAME || fail
59+
ip -netns $test_ns link add name $DEV type dummy || fail
60+
ip -netns $test_ns link property add dev $DEV altname $ALT_NAME || fail
6161
ip -netns $NS link add name $DEV2 type dummy || fail
6262
ip -netns $NS link property add dev $DEV2 altname $ALT_NAME || fail
6363

64-
ip -netns $NS link set dev $DEV2 netns 1 2> /dev/null &&
64+
ip -netns $NS link set dev $DEV2 netns $test_ns 2> /dev/null &&
6565
fail "Moved with alt-name dup"
6666

67-
ip link del $DEV || fail
67+
ip -netns $test_ns link del $DEV || fail
6868
ip -netns $NS link del $DEV2 || fail
6969

7070
#
7171
# Test creating alt-name in one net-ns and using in another
7272
#
7373
ip -netns $NS link add name $DEV type dummy || fail
7474
ip -netns $NS link property add dev $DEV altname $ALT_NAME || fail
75-
ip -netns $NS link set dev $DEV netns 1 || fail
76-
ip link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move"
77-
ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
75+
ip -netns $NS link set dev $DEV netns $test_ns || fail
76+
ip -netns $test_ns link show dev $ALT_NAME >> /dev/null || fail "Can't find alt-name after move"
77+
ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
7878
fail "Can still find alt-name after move"
79-
ip link del $DEV || fail
79+
ip -netns $test_ns link del $DEV || fail
8080

8181
echo -ne "$(basename $0) \t\t\t\t"
8282
if [ $RET_CODE -eq 0 ]; then

0 commit comments

Comments
 (0)