netns_helper.sh: cleanup
cover netns_helper.sh: cleanup
Petr Vorel (3):
netns_helper.sh: Check for ping netns_helper.sh: Check veth with TST_NEEDS_DRIVERS netns_helper.sh: Formatting and style cleanup
.../kernel/containers/netns/netns_helper.sh | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/3 netns_helper.sh: Check for ping
to give more informative message than just:netns_comm 1 TFAIL: ns_exec 48906 net ping -q -c2 -I veth0 192.168.0.3 failed unexpectedly netns_comm 1 TFAIL: ns_exec 48908 net ping -q -c2 -I veth1 192.168.0.2 failed unexpectedly netns_comm 1 TFAIL: ns_exec 48906 net ping -q -c2 -I lo 127.0.0.1 failed unexpectedly
Use the same approach implemented in d57ac0b7a for tst_net.sh: for IPv6 ping6 is preferred (but still require ping), but fallback with warning if only ping is available (some distros may still miss ping6 symlink required by upstream since iputils s20150815).
---
Reported in https://github.com/linux-test-project/ltp/issues/840
testcases/kernel/containers/netns/netns_helper.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +5 -3
@@ -1,11 +1,11 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) Linux Test Project, 2014-2020 +# Copyright (c) Linux Test Project, 2014-2021 # Copyright (c) 2015 Red Hat, Inc. TST_CLEANUP=netns_ns_exec_cleanup TST_NEEDS_ROOT=1 -TST_NEEDS_CMDS="ip modprobe" +TST_NEEDS_CMDS="ip modprobe ping" . tst_test.sh # Set to 1 only for test cases using ifconfig (ioctl).
@@ -132,10 +132,12 @@ netns_setup() ipv6) IFCONF_IN6_ARG="inet6 add" IP0=$6; IP1=$7; - if which ping6 >/dev/null 2>&1; then + + if tst_cmd_available ping6; then tping="ping6" else tping="ping -6" + tst_res_ TINFO "ping6 binary/symlink is missing, using workaround. Please, report missing ping6 to your distribution." fi NETMASK=64 ;;
Signature · 1 line
2.32.0
PATCH 2/3 netns_helper.sh: Check veth with TST_NEEDS_DRIVERS
In reply to Petr Vorelinstead loading it with modprobe. ip link can load veth itself (use the same approach as in tst_net.sh).
--- testcases/kernel/containers/netns/netns_helper.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +2 -4
@@ -5,7 +5,8 @@ TST_CLEANUP=netns_ns_exec_cleanup TST_NEEDS_ROOT=1 -TST_NEEDS_CMDS="ip modprobe ping" +TST_NEEDS_CMDS="ip ping" +TST_NEEDS_DRIVERS="veth" . tst_test.sh # Set to 1 only for test cases using ifconfig (ioctl).
@@ -75,9 +76,6 @@ IFCONF_IN6_ARG= # On success function returns, on error tst_brk is called and TC is terminated. netns_setup() { - - modprobe veth > /dev/null 2>&1 - case "$1" in ns_exec) setns_check
Signature · 1 line
2.32.0
PATCH 3/3 netns_helper.sh: Formatting and style cleanup
In reply to Petr VorelReplace spaces with tabs, use shorter if clauses, add missing local.
--- .../kernel/containers/netns/netns_helper.sh | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +17 -24
@@ -79,9 +79,8 @@ netns_setup() case "$1" in ns_exec) setns_check - if [ $? -eq 32 ]; then - tst_brk TCONF "setns not supported" - fi + [ $? -eq 32 ] && tst_brk TCONF "setns not supported" + NS_TYPE="net" netns_ns_exec_setup TST_CLEANUP=netns_ns_exec_cleanup
@@ -124,17 +123,20 @@ netns_setup() case "$2" in ipv4) - IP0=$4; IP1=$5 - tping="ping"; NETMASK=24 + IP0=$4 + IP1=$5 + tping="ping" + NETMASK=24 ;; ipv6) IFCONF_IN6_ARG="inet6 add" - IP0=$6; IP1=$7; + IP0=$6 + IP1=$7 if tst_cmd_available ping6; then - tping="ping6" + tping="ping6" else - tping="ping -6" + tping="ping -6" tst_res_ TINFO "ping6 binary/symlink is missing, using workaround. Please, report missing ping6 to your distribution." fi NETMASK=64
@@ -153,6 +155,8 @@ netns_setup() # ethernet device is then created for each namespace. netns_ns_exec_setup() { + local ret + NS_EXEC="ns_exec" NS_HANDLE0=$(ns_create $NS_TYPE)
@@ -172,13 +176,8 @@ netns_ns_exec_setup() $NS_EXEC $NS_HANDLE0 $NS_TYPE ns_ifmove veth1 $NS_HANDLE1 ret=$? - if [ $ret -eq 0 ]; then - return; - fi - - if [ $ret -eq 32 ]; then - tst_brk TCONF "IFLA_NET_NS_PID not supported" - fi + [ $ret -eq 0 ] && return + [ $ret -eq 32 ] && tst_brk TCONF "IFLA_NET_NS_PID not supported" tst_brk TBROK "unable to add device veth1 to the separate network namespace" }
@@ -215,9 +214,7 @@ netns_ip_setup() # of them (IPv4/IPv6 variant is decided by netns_setup() function). netns_set_ip() { - if [ -z "$NS_EXEC" ]; then - tst_brk TBROK "netns_setup() function must be called first" - fi + [ "$NS_EXEC" ] || tst_brk TBROK "netns_setup() function must be called first" # This applies only for ipv6 variant: # Do not accept Router Advertisements (accept_ra) and do not use
@@ -259,9 +256,7 @@ netns_set_ip() netns_ns_exec_cleanup() { - if [ -z "$NS_EXEC" ]; then - return - fi + [ "$NS_EXEC" ] || return # removes veth0 device (which also removes the paired veth1 device) $NS_EXEC $NS_HANDLE0 $NS_TYPE ip link delete veth0
@@ -273,9 +268,7 @@ netns_ns_exec_cleanup() netns_ip_cleanup() { - if [ -z "$NS_EXEC" ]; then - return - fi + [ "$NS_EXEC" ] || return # removes veth0 device (which also removes the paired veth1 device) $NS_EXEC $NS_HANDLE0 ip link delete veth0
Signature · 1 line
2.32.0
cover netns_helper.sh: cleanup
In reply to Petr VorelHi,
Quoted 7 lines
Petr Vorel (3):
netns_helper.sh: Check for pingnetns_helper.sh: Check veth withTST_NEEDS_DRIVERSnetns_helper.sh: Formatting and style cleanup.../kernel/containers/netns/netns_helper.sh | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-)
whole patchset merged
Kind regards,
Petr