Whamcloud - gitweb
LU-17989 tests: Cleanup fake interface usage 65/55465/6
authorChris Horn <chris.horn@hpe.com>
Mon, 17 Jun 2024 17:58:41 +0000 (11:58 -0600)
committerOleg Drokin <green@whamcloud.com>
Thu, 8 Aug 2024 00:16:11 +0000 (00:16 +0000)
Callers of have_interface() are using it to check that setup_fakeif()
completed successfully. Update setup_fakeif() to perform its own
validation. Both IPv4 and IPv6 addresses should be assigned to the
fake interface, so setup_fakeif() now checks for both of these.

Test cases that use the non-default namespace should call
setup_netns()/cleanup_netns() themselves rather than relying on the
test suite to setup this environment.

Test-Parameters: trivial
Signed-off-by: Chris Horn <chris.horn@hpe.com>
Change-Id: I80451c55b8b7b6919b7d7e94e72265f2e6aa2854
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55465
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-lnet.sh

index be08658..3a11dd0 100755 (executable)
@@ -73,21 +73,29 @@ do_ns() {
 setup_fakeif() {
        local netns="$1"
 
-       local netns_arg=""
-       [[ -n $netns ]] &&
+       local netns_arg netns_exec
+       if [[ -n $netns ]]; then
                netns_arg="netns $netns"
+               netns_exec="ip netns exec $netns"
+       fi
 
+       echo "ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg"
        ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
+       echo "ip link set 'test1pl' up"
        ip link set 'test1pl' up
-       if [[ -n $netns ]]; then
-               do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
-               do_ns ip -6 addr add "${FAKE_IPV6}/64" dev $FAKE_IF
-               do_ns ip link set $FAKE_IF up
-       else
-               ip addr add "${FAKE_IP}/31" dev $FAKE_IF
-               ip -6 addr add "${FAKE_IPV6}/64" dev $FAKE_IF
-               ip link set $FAKE_IF up
-       fi
+       echo "$netns_exec ip addr add \"${FAKE_IP}/31\" dev $FAKE_IF"
+       $netns_exec ip addr add "${FAKE_IP}/31" dev $FAKE_IF
+       echo "$netns_exec ip -6 addr add \"${FAKE_IPV6}/64\" dev $FAKE_IF"
+       $netns_exec ip -6 addr add "${FAKE_IPV6}/64" dev $FAKE_IF
+       echo "$netns_exec ip link set $FAKE_IF up"
+       $netns_exec ip link set $FAKE_IF up
+
+       local ip4=$($netns_exec ip -o -4 a s $FAKE_IF 2>/dev/null |
+                   grep $FAKE_IP)
+       local ip6=$($netns_exec ip -o -6 a s $FAKE_IF 2>/dev/null |
+                   grep $FAKE_IPV6)
+
+       [[ -n $ip4 && -n $ip6 ]] || error "Failed setup $FAKE_IF"
 }
 
 cleanup_fakeif() {
@@ -261,7 +269,6 @@ intf_has_ipv4() {
 }
 
 cleanupall -f
-setup_netns || error "setup_netns failed with $?"
 
 # Determine the local interface(s) used for LNet
 load_lnet "config_on_load=1" || error "Failed to load modules"
@@ -1164,12 +1171,6 @@ EOF
 }
 run_test 99b "Invalid value for Multi-Rail in yaml import"
 
-have_interface() {
-       local if="$1"
-       local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
-       [[ -n $ip ]]
-}
-
 add_net() {
        local net="$1"
        local if="$2"
@@ -1650,12 +1651,9 @@ run_test 106 "Deleting GW peer should fail"
 test_107() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        reinit_dlc || return $?
 
@@ -1666,19 +1664,15 @@ test_107() {
 
        cleanup_fakeif
        cleanup_lnet
-       setup_netns
 }
 run_test 107 "Deleting extra interface doesn't crash node"
 
 test_108() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        reinit_dlc || return $?
 
@@ -1697,7 +1691,6 @@ EOF
 
        cleanup_fakeif
        cleanup_lnet
-       setup_netns
 
        return 0
 }
@@ -1706,12 +1699,9 @@ run_test 108 "Check Multi-Rail setup"
 test_109() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        FAKE_IF_ALIAS="${FAKE_IF}"
        FAKE_IF_ALIAS+=":0"
@@ -1737,7 +1727,6 @@ test_109() {
 
        cleanup_fakeif
        cleanup_lnet
-       setup_netns
 }
 run_test 109 "Add NI using a network interface alias (LU-16859)"
 
@@ -1817,10 +1806,13 @@ test_200() {
        [[ ${NETTYPE} == tcp* ]] ||
                skip "Need tcp NETTYPE"
        cleanup_lnet || return $?
+       setup_netns || error "setup_netns failed with $?"
        load_lnet "networks=\"\""
        do_ns $LNETCTL lnet configure $LNET_CONFIG_INIT_OPT ||
                error "Failed to configure LNet in non-default namespace rc = $?"
-       $LNETCTL net show --net tcp | grep -q "nid: $FAKE_NID$"
+       $LNETCTL net show --net tcp | grep -q "nid: $FAKE_NID$" ||
+               error "$FAKE_NID is not configured as expected"
+       cleanup_netns
 }
 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
 
@@ -1828,10 +1820,13 @@ test_201() {
        [[ ${NETTYPE} == tcp* ]] ||
                skip "Need tcp NETTYPE"
        cleanup_lnet || return $?
+       setup_netns || error "setup_netns failed with $?"
        load_lnet "networks=tcp($FAKE_IF)"
        do_ns $LNETCTL lnet configure $LNET_CONFIG_INIT_OPT ||
                error "Failed to configure LNet in non-default namespace rc = $?"
-       $LNETCTL net show --net tcp | grep -q "nid: $FAKE_NID$"
+       $LNETCTL net show --net tcp | grep -q "nid: $FAKE_NID$" ||
+               error "$FAKE_NID is not configured as expected"
+       cleanup_netns
 }
 run_test 201 "load lnet using networks module options in a non-default namespace"
 
@@ -1839,10 +1834,13 @@ test_202() {
        [[ ${NETTYPE} == tcp* ]] ||
                skip "Need tcp NETTYPE"
        cleanup_lnet || return $?
+       setup_netns || error "setup_netns failed with $?"
        load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
        do_ns $LNETCTL lnet configure --all ||
                error "Failed to configure LNet in non-default namespace rc = $?"
-       $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
+       $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$" ||
+               error "$FAKE_IP@tcp is not configured as expected"
+       cleanup_netns
 }
 run_test 202 "load lnet using ip2nets in a non-default namespace"
 
@@ -1852,12 +1850,15 @@ test_203() {
        [[ ${NETTYPE} == tcp* ]] ||
                skip "Need tcp NETTYPE"
        cleanup_lnet || return $?
+       setup_netns || error "setup_netns failed with $?"
        load_lnet
        do_lnetctl lnet configure $LNET_CONFIG_OPT ||
                error "Failed to configure LNet in non-default namespace rc = $?"
        do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF ||
                error "Failed to add net in non-default namespace"
-       do_ns $LNETCTL net show | grep -q "nid: $FAKE_NID$"
+       do_ns $LNETCTL net show | grep -q "nid: $FAKE_NID$" ||
+               error "$FAKE_NID is not configured as expected"
+       cleanup_netns
 }
 run_test 203 "add a network using an interface in the non-default namespace"
 
@@ -2273,13 +2274,9 @@ test_208_load_and_check_lnet() {
 test_208() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
        setup_fakeif || error "Failed to add fake IF"
 
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
-
        local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
                       awk '/inet /{print $4}' |
                       sed 's:/.*::')
@@ -2752,12 +2749,9 @@ run_test 212 "Check discovery refcount loss bug (LU-14627)"
 test_213() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        reinit_dlc || return $?
 
@@ -2796,12 +2790,9 @@ function check_ni_status() {
 test_214() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        reinit_dlc || return $?
 
@@ -2871,7 +2862,6 @@ ni_stat_changed() {
 }
 
 test_215() {
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        reinit_dlc || return $?
@@ -4119,10 +4109,7 @@ test_303() {
 
        setup_health_test true || return $?
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        add_net "${NETTYPE}99" "$FAKE_IF" || return $?
 
@@ -4159,12 +4146,9 @@ run_test 303 "Check peer NI health after link down"
 test_304() {
        [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        cleanup_lnet || error "Failed to unload modules before test execution"
 
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        reinit_dlc || return $?
 
@@ -4455,10 +4439,7 @@ run_test 402 "Destination net rule should not panic"
 test_500() {
        reinit_dlc || return $?
 
-       cleanup_netns || error "Failed to cleanup netns before test execution"
        setup_fakeif || error "Failed to add fake IF"
-       have_interface "$FAKE_IF" ||
-               error "Expect $FAKE_IF configured but not found"
 
        add_net "tcp" "${INTERFACES[0]}"
        add_net "tcp" "${FAKE_IF}"