Commit e1f0da9b authored by Hangbin Liu's avatar Hangbin Liu Committed by Jakub Kicinski

selftests: bonding: use slowwait instead of hard code sleep

Use slowwait instead of hard code sleep for bonding tests.

In function setup_prepare(), the client_create() will be called after
server_create(). So I think there is no need to sleep in server_create()
and remove it.

For lab_lib.sh, remove bonding module may affect other running bonding tests.
And some test env may buildin bond which can't be removed. The bonding
link should be removed by lag_reset_network() or netns delete.
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20240205130048.282087-5-liuhangbin@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 45bf79bc
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
# +----------------+ # +----------------+
# #
# We use veths instead of physical interfaces # We use veths instead of physical interfaces
REQUIRE_MZ=no
NUM_NETIFS=0
lib_dir=$(dirname "$0")
source "$lib_dir"/../../../net/forwarding/lib.sh
sw="sw-$(mktemp -u XXXXXX)" sw="sw-$(mktemp -u XXXXXX)"
host="ns-$(mktemp -u XXXXXX)" host="ns-$(mktemp -u XXXXXX)"
...@@ -26,6 +31,16 @@ cleanup() ...@@ -26,6 +31,16 @@ cleanup()
ip netns del $host ip netns del $host
} }
wait_lladdr_dad()
{
$@ | grep fe80 | grep -qv tentative
}
wait_bond_up()
{
$@ | grep -q 'state UP'
}
trap cleanup 0 1 2 trap cleanup 0 1 2
ip netns add $sw ip netns add $sw
...@@ -37,8 +52,8 @@ ip -n $host link add veth1 type veth peer name veth1 netns $sw ...@@ -37,8 +52,8 @@ ip -n $host link add veth1 type veth peer name veth1 netns $sw
ip -n $sw link add br0 type bridge ip -n $sw link add br0 type bridge
ip -n $sw link set br0 up ip -n $sw link set br0 up
sw_lladdr=$(ip -n $sw addr show br0 | awk '/fe80/{print $2}' | cut -d'/' -f1) sw_lladdr=$(ip -n $sw addr show br0 | awk '/fe80/{print $2}' | cut -d'/' -f1)
# sleep some time to make sure bridge lladdr pass DAD # wait some time to make sure bridge lladdr pass DAD
sleep 2 slowwait 2 wait_lladdr_dad ip -n $sw addr show br0
ip -n $host link add bond0 type bond mode 1 ns_ip6_target ${sw_lladdr} \ ip -n $host link add bond0 type bond mode 1 ns_ip6_target ${sw_lladdr} \
arp_validate 3 arp_interval 1000 arp_validate 3 arp_interval 1000
...@@ -53,7 +68,7 @@ ip -n $sw link set veth1 master br0 ...@@ -53,7 +68,7 @@ ip -n $sw link set veth1 master br0
ip -n $sw link set veth0 up ip -n $sw link set veth0 up
ip -n $sw link set veth1 up ip -n $sw link set veth1 up
sleep 5 slowwait 5 wait_bond_up ip -n $host link show bond0
rc=0 rc=0
if ip -n $host link show bond0 | grep -q LOWER_UP; then if ip -n $host link show bond0 | grep -q LOWER_UP; then
......
...@@ -73,7 +73,6 @@ server_create() ...@@ -73,7 +73,6 @@ server_create()
ip -n ${s_ns} link set bond0 up ip -n ${s_ns} link set bond0 up
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0 ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0 ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
sleep 2
} }
# Reset bond with new mode and options # Reset bond with new mode and options
...@@ -96,7 +95,8 @@ bond_reset() ...@@ -96,7 +95,8 @@ bond_reset()
ip -n ${s_ns} link set bond0 up ip -n ${s_ns} link set bond0 up
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0 ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0 ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
sleep 2 # Wait for IPv6 address ready as it needs DAD
slowwait 2 ip netns exec ${s_ns} ping6 ${c_ip6} -c 1 -W 0.1 &> /dev/null
} }
server_destroy() server_destroy()
...@@ -150,7 +150,7 @@ bond_check_connection() ...@@ -150,7 +150,7 @@ bond_check_connection()
{ {
local msg=${1:-"check connection"} local msg=${1:-"check connection"}
sleep 2 slowwait 2 ip netns exec ${s_ns} ping ${c_ip4} -c 1 -W 0.1 &> /dev/null
ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null
check_err $? "${msg}: ping failed" check_err $? "${msg}: ping failed"
ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null
......
...@@ -107,13 +107,12 @@ lag_setup2x2() ...@@ -107,13 +107,12 @@ lag_setup2x2()
NAMESPACES="${namespaces}" NAMESPACES="${namespaces}"
} }
# cleanup all lag related namespaces and remove the bonding module # cleanup all lag related namespaces
lag_cleanup() lag_cleanup()
{ {
for n in ${NAMESPACES}; do for n in ${NAMESPACES}; do
ip netns delete ${n} >/dev/null 2>&1 || true ip netns delete ${n} >/dev/null 2>&1 || true
done done
modprobe -r bonding
} }
SWITCH="lag_node1" SWITCH="lag_node1"
...@@ -159,7 +158,7 @@ test_bond_recovery() ...@@ -159,7 +158,7 @@ test_bond_recovery()
create_bond $@ create_bond $@
# verify connectivity # verify connectivity
ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 >/dev/null 2>&1 slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
check_err $? "No connectivity" check_err $? "No connectivity"
# force the links of the bond down # force the links of the bond down
...@@ -169,7 +168,7 @@ test_bond_recovery() ...@@ -169,7 +168,7 @@ test_bond_recovery()
ip netns exec ${SWITCH} ip link set eth1 down ip netns exec ${SWITCH} ip link set eth1 down
# re-verify connectivity # re-verify connectivity
ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 >/dev/null 2>&1 slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
local rc=$? local rc=$?
check_err $rc "Bond failed to recover" check_err $rc "Bond failed to recover"
......
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