3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 # skip the grant tests for ARM until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17 # bug number: LU-14067
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
25 . $LUSTRE/tests/test-framework.sh
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 [[ -z $LNETCTL ]] && skip "Need lnetctl"
38 if is_mounted $MOUNT || is_mounted $MOUNT2; then
39 cleanupall || error "Failed cleanup prior to test execution"
44 echo "Cleaning up LNet"
45 lsmod | grep -q lnet &&
46 $LNETCTL lnet unconfigure 2>/dev/null
51 if module_loaded lnet ; then
52 cleanup_lnet || error "Failed to unload modules before test execution"
58 # Cleanup any tmp files created by the sub tests
59 rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
62 if $restore_mounts; then
63 setupall || error "Failed to setup Lustre after test execution"
64 elif $restore_modules; then
66 error "Couldn't load modules after test execution"
75 echo "ip netns exec $TESTNS $*"
76 ip netns exec $TESTNS "$@"
84 netns_arg="netns $netns"
86 ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
87 ip link set 'test1pl' up
88 if [[ -n $netns ]]; then
89 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
90 do_ns ip link set $FAKE_IF up
92 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
93 ip link set $FAKE_IF up
98 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
109 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
114 echo "Loading LNet and configuring DLC"
116 do_lnetctl lnet configure
119 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
120 define_global_yaml() {
121 $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
122 error "Failed to export global yaml $?"
126 if lsmod | grep -q lnet; then
127 do_lnetctl lnet unconfigure ||
128 error "lnetctl lnet unconfigure failed $?"
129 do_lnetctl lnet configure ||
130 error "lnetctl lnet configure failed $?"
132 configure_dlc || error "configure_dlc failed $?"
137 append_global_yaml() {
138 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
139 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
141 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
144 create_base_yaml_file() {
148 compare_yaml_files() {
149 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
150 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
152 ! [[ -e $expected ]] && echo "$expected not found" && return 1
153 ! [[ -e $actual ]] && echo "$actual not found" && return 1
154 diff -upN ${actual} ${expected} || rc=$?
164 local net="${nid//*@/}"
165 local addr="${nid//@*/}"
167 local num_re='[0-9]\+'
168 local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
170 if [[ $net =~ gni[0-9]* ]]; then
171 [[ $addr =~ ${num_re} ]] && return 0
173 [[ $addr =~ ${ip_re} ]] && return 0
178 local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
179 local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
180 local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
181 local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
184 for nid in $primary_nids $secondary_nids; do
185 validate_nid "$nid" || error "Bad NID \"${nid}\""
190 validate_peer_nids() {
192 local nids_per_peer="$2"
194 local expect_p="$num_peers"
195 # The primary nid also shows up in the list of secondary nids
196 local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
198 local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
199 local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
200 if [[ $expect_p -ne $actual_p ]]; then
202 error "Expected $expect_p but found $actual_p primary nids"
203 elif [[ $expect_s -ne $actual_s ]]; then
205 error "Expected $expect_s but found $actual_s secondary nids"
210 validate_gateway_nids() {
211 local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
212 local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
213 if [[ $expect_gw -ne $actual_gw ]]; then
215 error "Expected $expect_gw gateways but found $actual_gw gateways"
221 setup_netns || error "setup_netns failed with $?"
223 # Determine the local interface(s) used for LNet
224 load_lnet "config_on_load=1" || error "Failed to load modules"
229 INTERFACES=( $(lnet_if_list) )
231 cleanup_lnet || error "Failed to cleanup LNet"
233 stack_trap 'cleanup_testsuite' EXIT
236 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
237 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
239 reinit_dlc || return $?
240 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
241 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
242 create_base_yaml_file
243 compare_yaml_files || error "Configuration changed after import"
245 run_test 0 "Export empty config, import the config, compare"
248 local prim_nid="${1:+--prim_nid $1}"
249 local nid="${2:+--nid $2}"
251 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
253 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
254 $LNETCTL export --backup > $actual || error "export failed $?"
260 reinit_dlc || return $?
261 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
263 - primary nid: 1.1.1.1@tcp
269 compare_peer_add "1.1.1.1@tcp"
271 run_test 1 "Add peer with single nid (tcp)"
274 reinit_dlc || return $?
275 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
277 - primary nid: 2.2.2.2@o2ib
283 compare_peer_add "2.2.2.2@o2ib"
285 run_test 2 "Add peer with single nid (o2ib)"
288 reinit_dlc || return $?
289 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
291 - primary nid: 3.3.3.3@tcp
298 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
300 run_test 3 "Add peer with tcp primary o2ib secondary"
303 reinit_dlc || return $?
304 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
306 - primary nid: 4.4.4.4@tcp
315 echo "Add peer with nidrange (tcp)"
316 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
318 echo "Add peer with nidrange that overlaps primary nid (tcp)"
319 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
321 run_test 4 "Add peer with nidrange (tcp)"
324 reinit_dlc || return $?
325 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
327 - primary nid: 5.5.5.5@o2ib
337 echo "Add peer with nidrange (o2ib)"
338 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
340 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
341 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
343 run_test 5 "Add peer with nidrange (o2ib)"
346 reinit_dlc || return $?
347 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
349 - primary nid: 6.6.6.6@tcp
369 compare_peer_add "6.6.6.6@tcp" \
370 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
372 run_test 6 "Add peer with multiple nidranges"
375 local prim_nid="${1:+--prim_nid $1}"
376 local nid="${2:+--nid $2}"
378 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
380 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
381 $LNETCTL export --backup > $actual || error "export failed $?"
387 reinit_dlc || return $?
388 create_base_yaml_file
390 echo "Delete peer with single nid (tcp)"
391 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
392 compare_peer_del "7.7.7.7@tcp"
394 echo "Delete peer with single nid (o2ib)"
395 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
396 compare_peer_del "7.7.7.7@o2ib"
398 echo "Delete peer that has multiple nids (tcp)"
399 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
400 error "Peer add failed $?"
401 compare_peer_del "7.7.7.7@tcp"
403 echo "Delete peer that has multiple nids (o2ib)"
404 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
405 error "Peer add failed $?"
406 compare_peer_del "7.7.7.7@o2ib"
408 echo "Delete peer that has both tcp and o2ib nids"
409 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
410 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
411 error "Peer add failed $?"
412 compare_peer_del "7.7.7.7@tcp"
414 echo "Delete peer with single nid (gni)"
415 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
416 compare_peer_del "7@gni"
418 echo "Delete peer that has multiple nids (gni)"
419 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
420 error "Peer add failed $?"
421 compare_peer_del "7@gni"
423 echo "Delete peer that has tcp, o2ib and gni nids"
424 do_lnetctl peer add --prim_nid 7@gni \
425 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
426 error "Peer add failed $?"
427 compare_peer_del "7@gni"
429 run_test 7 "Various peer delete tests"
432 reinit_dlc || return $?
434 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
436 - primary nid: 8.8.8.8@tcp
448 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
449 error "Peer add failed $?"
450 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
452 run_test 8 "Delete single secondary nid from peer (tcp)"
455 reinit_dlc || return $?
457 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
459 - primary nid: 9.9.9.9@tcp
466 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
467 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
468 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
470 run_test 9 "Delete all secondary nids from peer (tcp)"
473 reinit_dlc || return $?
475 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
477 - primary nid: 10.10.10.10@tcp
480 - nid: 10.10.10.10@tcp
481 - nid: 10.10.10.12@tcp
482 - nid: 10.10.10.13@tcp
483 - nid: 10.10.10.15@tcp
484 - nid: 10.10.10.16@tcp
487 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
488 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
489 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
491 run_test 10 "Delete single secondary nid from peer (o2ib)"
494 reinit_dlc || return $?
496 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
498 - primary nid: 11.11.11.11@tcp
501 - nid: 11.11.11.11@tcp
504 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
505 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
506 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
508 run_test 11 "Delete all secondary nids from peer (o2ib)"
511 reinit_dlc || return $?
513 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
515 - primary nid: 12.12.12.12@o2ib
518 - nid: 12.12.12.12@o2ib
519 - nid: 13.13.13.13@o2ib
520 - nid: 14.13.13.13@o2ib
521 - nid: 14.15.13.13@o2ib
523 - nid: 15.17.1.10@tcp
524 - nid: 15.17.1.20@tcp
527 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
528 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
529 error "Peer add failed $?"
530 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
532 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
535 reinit_dlc || return $?
537 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
539 - primary nid: 13.13.13.13@o2ib
542 - nid: 13.13.13.13@o2ib
545 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
546 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
547 error "Peer add failed $?"
548 compare_peer_del "13.13.13.13@o2ib" \
549 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
551 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
557 if [[ $net =~ gni* ]]; then
560 echo "${num}.${num}.${num}.${num}@${net}"
564 create_mr_peer_yaml() {
566 local secondary_nids="$2"
569 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
570 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
572 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
575 while [[ $created -lt $num_peers ]]; do
576 local primary=$(create_nid ${nidnum} ${net})
577 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
578 - primary nid: $primary
584 local start=$((nidnum + 1))
585 local end=$((nidnum + $secondary_nids))
586 for j in $(seq ${start} ${end}); do
587 local nid=$(create_nid $j ${net})
588 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
596 reinit_dlc || return $?
598 echo "Create single peer, single nid, using import"
599 create_mr_peer_yaml 1 0 tcp
600 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
601 error "Import failed $?"
603 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
606 echo "Delete single peer using import --del"
607 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
608 error "Import failed $?"
609 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
610 create_base_yaml_file
611 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
614 run_test 14 "import peer create/delete with single nid"
617 reinit_dlc || return $?
619 echo "Create multiple peers, single nid per peer, using import"
620 create_mr_peer_yaml 5 0 o2ib
621 # The ordering of nids for this use-case is non-deterministic, so we
622 # we can't just diff the expected/actual output.
623 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
624 error "Import failed $?"
625 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
626 validate_peer_nids 5 0
628 echo "Delete multiple peers, single nid per peer, using import --del"
629 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
630 error "Import failed $?"
631 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
632 create_base_yaml_file
633 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
636 run_test 15 "import multi peer create/delete with single nid per peer"
639 reinit_dlc || return $?
641 echo "Create single peer, multiple nids, using import"
642 create_mr_peer_yaml 1 5 tcp
643 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
644 error "Import failed $?"
645 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
646 validate_peer_nids 1 5
648 echo "Delete single peer, multiple nids, using import --del"
649 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
650 error "Import failed $?"
651 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
652 create_base_yaml_file
653 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
656 run_test 16 "import peer create/delete with multiple nids"
659 reinit_dlc || return $?
661 echo "Create multiple peers, multiple nids per peer, using import"
662 create_mr_peer_yaml 5 7 o2ib
663 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
664 error "Import failed $?"
665 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
666 validate_peer_nids 5 7
668 echo "Delete multiple peers, multiple nids per peer, using import --del"
669 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
670 error "Import failed $?"
671 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
672 create_base_yaml_file
673 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
676 run_test 17 "import multi peer create/delete with multiple nids"
679 reinit_dlc || return $?
681 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
683 - primary nid: 1.1.1.1@tcp
692 echo "Import peer with 5 nids"
693 cat $TMP/sanity-lnet-$testnum-expected.yaml
694 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
695 error "Import failed $?"
696 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
698 - primary nid: 1.1.1.1@tcp
705 echo "Delete three of the nids"
706 cat $TMP/sanity-lnet-$testnum-expected.yaml
707 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
708 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
710 - primary nid: 1.1.1.1@tcp
716 echo "Check peer has expected nids remaining"
717 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
721 run_test 18a "Delete a subset of nids from a single peer using import --del"
724 reinit_dlc || return $?
726 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
728 - primary nid: 1.1.1.1@tcp
736 - primary nid: 6.6.6.6@o2ib
745 echo "Import two peers with 5 nids each"
746 cat $TMP/sanity-lnet-$testnum-expected.yaml
747 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
748 error "Import failed $?"
749 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
751 - primary nid: 1.1.1.1@tcp
757 - primary nid: 6.6.6.6@o2ib
764 echo "Delete three of the nids from each peer"
765 cat $TMP/sanity-lnet-$testnum-expected.yaml
766 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
767 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
769 - primary nid: 6.6.6.6@o2ib
774 - primary nid: 1.1.1.1@tcp
781 echo "Check peers have expected nids remaining"
782 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
784 validate_peer_nids 2 1
786 run_test 18b "Delete multiple nids from multiple peers using import --del"
789 reinit_dlc || return $?
790 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
792 - primary nid: 19@gni
798 compare_peer_add "19@gni"
800 run_test 19 "Add peer with single nid (gni)"
803 reinit_dlc || return $?
804 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
806 - primary nid: 20@gni
810 - nid: 20.20.20.20@tcp
811 - nid: 20.20.20.20@o2ib
814 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
816 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
819 reinit_dlc || return $?
820 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
822 - primary nid: 21@gni
832 echo "Add peer with nidrange (gni)"
833 compare_peer_add "21@gni" "[22-25]@gni" || error
834 echo "Add peer with nidrange that overlaps primary nid (gni)"
835 compare_peer_add "21@gni" "[21-25]@gni"
837 run_test 21 "Add peer with nidrange (gni)"
840 reinit_dlc || return $?
841 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
843 - primary nid: 22@gni
854 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
855 error "Peer add failed $?"
856 compare_peer_del "22@gni" "26@gni"
858 run_test 22 "Delete single secondary nid from peer (gni)"
861 reinit_dlc || return $?
862 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
864 - primary nid: 23@gni
871 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
872 error "Peer add failed $?"
873 compare_peer_del "23@gni" "[25-29]@gni"
875 run_test 23 "Delete all secondary nids from peer (gni)"
878 reinit_dlc || return $?
879 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
881 - primary nid: 24@gni
886 - nid: 13.13.13.13@o2ib
887 - nid: 14.13.13.13@o2ib
888 - nid: 14.15.13.13@o2ib
890 - nid: 15.17.1.10@tcp
891 - nid: 15.17.1.20@tcp
894 do_lnetctl peer add --prim_nid 24@gni \
895 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp,[5-12/6]@gni ||
896 error "Peer add failed $?"
897 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
899 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
902 reinit_dlc || return $?
903 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
905 - primary nid: 25@gni
911 do_lnetctl peer add --prim_nid 25@gni \
912 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
913 error "Peer add failed $?"
914 compare_peer_del "25@gni" \
915 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
917 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
920 reinit_dlc || return $?
922 echo "Invalid prim_nid - peer add"
923 do_lnetctl peer add --prim_nid foobar &&
924 error "Command should have failed"
926 echo "Invalid prim_nid - peer del"
927 do_lnetctl peer del --prim_nid foobar &&
928 error "Command should have failed"
930 echo "Delete non-existing peer"
931 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
932 error "Command should have failed"
934 echo "Don't provide mandatory argument for peer del"
935 do_lnetctl peer del --nid 1.1.1.1@tcp &&
936 error "Command should have failed"
938 echo "Don't provide mandatory argument for peer add"
939 do_lnetctl peer add --nid 1.1.1.1@tcp &&
940 error "Command should have failed"
942 echo "Don't provide mandatory arguments peer add"
943 do_lnetctl peer add &&
944 error "Command should have failed"
946 echo "Invalid secondary nids"
947 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
948 error "Command should have failed"
950 echo "Exceed max nids per peer"
951 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
952 error "Command should have failed"
954 echo "Invalid net type"
955 do_lnetctl peer add --prim_nid 1@foo &&
956 error "Command should have failed"
958 echo "Invalid nid format"
959 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
962 for nid in ${invalid_nids}; do
963 echo "Check invalid primary nid - '$nid'"
964 do_lnetctl peer add --prim_nid $nid &&
965 error "Command should have failed"
968 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
969 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
970 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
973 for nidstr in ${invalid_strs}; do
974 echo "Check invalid nidstring - '$nidstr'"
975 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
976 error "Command should have failed"
979 echo "Add non-local gateway"
980 do_lnetctl route add --net tcp --gateway 1@gni &&
981 error "Command should have failed"
985 run_test 99a "Check various invalid inputs to lnetctl peer"
988 reinit_dlc || return $?
990 create_base_yaml_file
992 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
994 - primary nid: 99.99.99.99@tcp
997 - nid: 99.99.99.99@tcp
999 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1000 error "import should have failed"
1001 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1004 run_test 99b "Invalid value for Multi-Rail in yaml import"
1008 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1016 if ! lsmod | grep -q ksocklnd ; then
1017 load_module ../lnet/klnds/socklnd/ksocklnd ||
1018 error "Can't load ksocklnd.ko"
1021 do_lnetctl net add --net ${net} --if ${if} ||
1022 error "Failed to add net ${net} on if ${if}"
1025 compare_route_add() {
1029 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1031 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1032 error "route add failed $?"
1033 # CPT configuration is pruned from the exported yaml, since the default
1034 # can vary across test systems (unlike default values for things like
1035 # peer_credits, peer_timeout, etc.)
1036 $LNETCTL export --backup | grep -v CPT > $actual ||
1037 error "export failed $?"
1038 validate_gateway_nids
1043 reinit_dlc || return $?
1044 add_net "tcp" "${INTERFACES[0]}"
1045 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1054 peer_buffer_credits: 0
1060 gateway: 7.7.7.7@tcp
1063 health_sensitivity: 1
1065 - primary nid: 7.7.7.7@tcp
1071 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1074 run_test 100 "Add route with single gw (tcp)"
1077 reinit_dlc || return $?
1078 add_net "tcp" "${INTERFACES[0]}"
1079 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1088 peer_buffer_credits: 0
1094 gateway: 8.8.8.10@tcp
1097 health_sensitivity: 1
1099 gateway: 8.8.8.9@tcp
1102 health_sensitivity: 1
1104 gateway: 8.8.8.8@tcp
1107 health_sensitivity: 1
1109 - primary nid: 8.8.8.9@tcp
1113 - primary nid: 8.8.8.10@tcp
1117 - primary nid: 8.8.8.8@tcp
1123 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1125 run_test 101 "Add route with multiple gw (tcp)"
1127 compare_route_del() {
1131 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1133 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1134 error "route del failed $?"
1135 $LNETCTL export --backup > $actual ||
1136 error "export failed $?"
1137 validate_gateway_nids
1141 reinit_dlc || return $?
1142 add_net "tcp" "${INTERFACES[0]}"
1143 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1144 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1145 error "route add failed $?"
1146 compare_route_del "tcp102" "102.102.102.102@tcp"
1148 run_test 102 "Delete route with single gw (tcp)"
1151 reinit_dlc || return $?
1152 add_net "tcp" "${INTERFACES[0]}"
1153 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1154 do_lnetctl route add --net tcp103 \
1155 --gateway 103.103.103.[103-120/4]@tcp ||
1156 error "route add failed $?"
1157 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1159 run_test 103 "Delete route with multiple gw (tcp)"
1162 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1164 reinit_dlc || return $?
1166 # Default value is '3'
1167 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1169 error "Expect 3 found $val"
1171 echo "Set < 0; Should fail"
1172 do_lnetctl set response_tracking -1 &&
1173 error "should have failed $?"
1175 reinit_dlc || return $?
1178 response_tracking: -10
1180 do_lnetctl import < $tyaml &&
1181 error "should have failed $?"
1183 echo "Check valid values; Should succeed"
1185 for ((i = 0; i < 4; i++)); do
1186 reinit_dlc || return $?
1187 do_lnetctl set response_tracking $i ||
1188 error "should have succeeded $?"
1189 $LNETCTL global show | grep -q "response_tracking: $i" ||
1190 error "Failed to set response_tracking to $i"
1191 reinit_dlc || return $?
1194 response_tracking: $i
1196 do_lnetctl import < $tyaml ||
1197 error "should have succeeded $?"
1198 $LNETCTL global show | grep -q "response_tracking: $i" ||
1199 error "Failed to set response_tracking to $i"
1202 reinit_dlc || return $?
1203 echo "Set > 3; Should fail"
1204 do_lnetctl set response_tracking 4 &&
1205 error "should have failed $?"
1207 reinit_dlc || return $?
1210 response_tracking: 10
1212 do_lnetctl import < $tyaml &&
1213 error "should have failed $?"
1216 run_test 104 "Set/check response_tracking param"
1219 reinit_dlc || return $?
1220 add_net "tcp" "${INTERFACES[0]}"
1221 do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1222 error "route add failed $?"
1223 do_lnetctl peer add --prim 105.105.105.105@tcp &&
1224 error "peer add should fail"
1228 run_test 105 "Adding duplicate GW peer should fail"
1231 reinit_dlc || return $?
1232 add_net "tcp" "${INTERFACES[0]}"
1233 do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1234 error "route add failed $?"
1235 do_lnetctl peer del --prim 106.106.106.106@tcp &&
1236 error "peer del should fail"
1240 run_test 106 "Deleting GW peer should fail"
1243 cleanup_lnet || exit 1
1244 load_lnet "networks=\"\""
1245 do_ns $LNETCTL lnet configure --all || exit 1
1246 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1248 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1251 cleanup_lnet || exit 1
1252 load_lnet "networks=tcp($FAKE_IF)"
1253 do_ns $LNETCTL lnet configure --all || exit 1
1254 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1256 run_test 201 "load lnet using networks module options in a non-default namespace"
1259 cleanup_lnet || exit 1
1260 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1261 do_ns $LNETCTL lnet configure --all || exit 1
1262 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1264 run_test 202 "load lnet using ip2nets in a non-default namespace"
1267 ### Add the interfaces in the target namespace
1270 cleanup_lnet || exit 1
1272 do_lnetctl lnet configure || exit 1
1273 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1275 run_test 203 "add a network using an interface in the non-default namespace"
1277 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1278 function save_lnet_params() {
1279 $LNETCTL global show | egrep -v '^global:$' |
1280 sed 's/://' > $LNET_PARAMS_FILE
1283 function restore_lnet_params() {
1285 while read param value; do
1286 [[ $param == max_intf ]] && continue
1287 [[ $param == lnd_timeout ]] && continue
1288 $LNETCTL set ${param} ${value} ||
1289 error "Failed to restore ${param} to ${value}"
1290 done < $LNET_PARAMS_FILE
1293 function lnet_health_pre() {
1296 # Lower transaction timeout to speed up test execution
1297 $LNETCTL set transaction_timeout 10 ||
1298 error "Failed to set transaction_timeout $?"
1300 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1301 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1302 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1303 xargs echo | sed 's/ /+/g' | bc -l)
1305 RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1306 awk '/health value/{print $NF}' | xargs echo |
1307 sed 's/ /+/g' | bc -l)
1309 # Might not have any peers so initialize to zero.
1310 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1315 function lnet_health_post() {
1316 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1317 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1318 awk '/health value/{print $NF}' |
1319 xargs echo | sed 's/ /+/g' | bc -l)
1321 RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1322 awk '/health value/{print $NF}' | xargs echo |
1323 sed 's/ /+/g' | bc -l)
1325 # Might not have any peers so initialize to zero.
1326 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1329 echo "Pre resends: $RSND_PRE" &&
1330 echo "Post resends: $RSND_POST" &&
1331 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1332 echo "Pre local health: $LO_HVAL_PRE" &&
1333 echo "Post local health: $LO_HVAL_POST" &&
1334 echo "Pre remote health: $RMT_HVAL_PRE" &&
1335 echo "Post remote health: $RMT_HVAL_POST"
1339 do_lnetctl peer set --health 1000 --all
1340 do_lnetctl net set --health 1000 --all
1345 function check_no_resends() {
1346 echo "Check that no resends took place"
1347 [[ $RSND_POST -ne $RSND_PRE ]] &&
1348 error "Found resends: $RSND_POST != $RSND_PRE"
1353 function check_resends() {
1354 local delta=$((RSND_POST - RSND_PRE))
1356 echo "Check that $RETRY_PARAM resends took place"
1357 [[ $delta -ne $RETRY_PARAM ]] &&
1358 error "Expected $RETRY_PARAM resends found $delta"
1363 function check_no_local_health() {
1364 echo "Check that local NI health is unchanged"
1365 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1366 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1371 function check_local_health() {
1372 echo "Check that local NI health has been changed"
1373 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1374 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1379 function check_no_remote_health() {
1380 echo "Check that remote NI health is unchanged"
1381 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1382 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1387 function check_remote_health() {
1388 echo "Check that remote NI health has been changed"
1389 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1390 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1400 setup_health_test() {
1404 local rnodes=$(remote_nodes_list)
1405 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1407 cleanup_lnet || error "Failed to cleanup before test execution"
1409 # Loading modules should configure LNet with the appropriate
1410 # test-framework configuration
1411 load_lnet "config_on_load=1" || error "Failed to load modules"
1413 LNIDS=( $($LCTL list_nids | xargs echo) )
1415 RNODE=$(awk '{print $1}' <<<$rnodes)
1416 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1418 if [[ -z ${RNIDS[@]} ]]; then
1419 do_rpc_nodes $RNODE load_lnet "config_on_load=1"
1421 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1424 [[ ${#LNIDS[@]} -lt 1 ]] &&
1425 error "No NIDs configured for local host $HOSTNAME"
1426 [[ ${#RNIDS[@]} -lt 1 ]] &&
1427 error "No NIDs configured for remote host $RNODE"
1429 do_lnetctl discover ${RNIDS[0]} ||
1430 error "Unable to discover ${RNIDS[0]}"
1432 local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1433 awk '/Multi-Rail/{print $NF}')
1435 if ${need_mr} && [[ $mr == False ]]; then
1436 cleanup_health_test || return $?
1440 if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1441 ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1442 cleanup_health_test || return $?
1446 if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1447 # Add a second, reachable NID to rnode.
1448 local net=${RNIDS[0]}
1452 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1454 error "Failed to determine interface for $RNODE"
1456 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1457 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1459 if [[ $rc -ne 0 ]]; then
1460 error "Failed to add interface to $RNODE rc=$?"
1462 RNIDS[1]="${RNIDS[0]}1"
1463 NET_DEL_ARGS="--net $net --if $if"
1467 if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1468 local net=${LNIDS[0]}
1471 do_lnetctl lnet configure &&
1472 do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1474 if [[ $rc -ne 0 ]]; then
1475 error "Failed to add interface rc=$?"
1477 LNIDS[1]="${LNIDS[0]}1"
1483 $LNETCTL peer show -v 2 | egrep -e nid -e health
1485 $LCTL set_param debug=+net
1491 cleanup_health_test() {
1494 if [[ -n $NET_DEL_ARGS ]]; then
1495 do_rpc_nodes $RNODE \
1496 "$LNETCTL net del $NET_DEL_ARGS" ||
1501 unload_modules || rc=$?
1504 do_rpc_nodes $RNODE unload_modules_local ||
1510 error "Failed cleanup"
1515 add_health_test_drop_rules() {
1519 for lnid in "${LNIDS[@]}"; do
1520 for rnid in "${RNIDS[@]}"; do
1521 $LCTL net_drop_add -s $lnid -d $rnid -m GET -r 1 -e ${hstatus}
1526 # See lnet/lnet/lib-msg.c:lnet_health_check()
1527 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1528 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1529 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1531 setup_health_test false || return $?
1534 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1535 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1536 echo "Simulate $hstatus"
1537 lnet_health_pre || return $?
1539 add_health_test_drop_rules ${hstatus}
1540 do_lnetctl discover ${RNIDS[0]} &&
1541 error "Should have failed"
1542 $LCTL net_drop_del -a
1546 check_no_resends || return $?
1547 check_no_local_health || return $?
1550 cleanup_health_test || return $?
1554 run_test 204 "Check no health or resends for single-rail local failures"
1557 setup_health_test true || return $?
1560 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1561 echo "Simulate $hstatus"
1562 lnet_health_pre || return $?
1564 add_health_test_drop_rules ${hstatus}
1565 do_lnetctl discover ${RNIDS[0]} &&
1566 error "Should have failed"
1567 $LCTL net_drop_del -a
1571 check_resends || return $?
1572 check_local_health || return $?
1575 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1576 echo "Simulate $hstatus"
1577 lnet_health_pre || return $?
1579 add_health_test_drop_rules ${hstatus}
1580 do_lnetctl discover ${RNIDS[0]} &&
1581 error "Should have failed"
1582 $LCTL net_drop_del -a
1586 check_no_resends || return $?
1587 check_local_health || return $?
1590 cleanup_health_test || return $?
1594 run_test 205 "Check health and resends for multi-rail local failures"
1596 # See lnet/lnet/lib-msg.c:lnet_health_check()
1597 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1598 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1600 setup_health_test false || return $?
1603 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1604 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1605 echo "Simulate $hstatus"
1606 lnet_health_pre || return $?
1608 add_health_test_drop_rules ${hstatus}
1609 do_lnetctl discover ${RNIDS[0]} &&
1610 error "Should have failed"
1611 $LCTL net_drop_del -a
1615 check_no_resends || return $?
1616 check_no_local_health || return $?
1617 check_no_remote_health || return $?
1620 cleanup_health_test || return $?
1624 run_test 206 "Check no health or resends for single-rail remote failures"
1627 setup_health_test true || return $?
1630 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1631 echo "Simulate $hstatus"
1632 lnet_health_pre || return $?
1634 add_health_test_drop_rules ${hstatus}
1636 do_lnetctl discover ${RNIDS[0]} &&
1637 error "Should have failed"
1641 $LCTL net_drop_del -a
1643 check_resends || return $?
1644 check_no_local_health || return $?
1645 check_remote_health || return $?
1646 do_lnetctl peer set --health 1000 --all ||
1647 error "Unable to reset health rc=$?"
1649 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1650 echo "Simulate $hstatus"
1651 lnet_health_pre || return $?
1653 add_health_test_drop_rules ${hstatus}
1655 do_lnetctl discover ${RNIDS[0]} &&
1656 error "Should have failed"
1660 $LCTL net_drop_del -a
1662 check_no_resends || return $?
1663 check_no_local_health || return $?
1664 check_remote_health || return $?
1665 do_lnetctl peer set --health 1000 --all ||
1666 error "Unable to reset health rc=$?"
1669 cleanup_health_test || return $?
1673 run_test 207 "Check health and resends for multi-rail remote errors"
1675 test_208_load_and_check_lnet() {
1679 local num_expected=1
1681 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1684 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1690 nids=( $($LCTL list_nids) )
1692 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1693 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1695 [[ ${nids[0]} == ${p_nid} ]] ||
1696 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1698 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1699 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1701 $LCTL net down &>/dev/null
1706 cleanup_netns || error "Failed to cleanup netns before test execution"
1707 cleanup_lnet || error "Failed to unload modules before test execution"
1708 setup_fakeif || error "Failed to add fake IF"
1710 have_interface "$FAKE_IF" ||
1711 error "Expect $FAKE_IF configured but not found"
1713 local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1714 awk '/inet /{print $4}' |
1716 if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1717 local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1719 echo "Configure single NID \"$ip2nets_str\""
1720 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1722 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1723 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1724 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1727 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1728 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1729 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1731 local addr1=( ${if0_ip//./ } )
1732 local addr2=( ${FAKE_IP//./ } )
1733 local range="[${addr1[0]},${addr2[0]}]"
1736 for i in $(seq 1 3); do
1737 range+=".[${addr1[$i]},${addr2[$i]}]"
1739 ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1741 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1742 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1747 echo "alt syntax with missing IF \"$ip2nets_str\""
1748 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1750 echo "$LCTL net up should fail"
1752 error "LNet bringup should have failed"
1756 run_test 208 "Test various kernel ip2nets configurations"
1759 setup_health_test false || return $?
1761 echo "Simulate network_timeout w/SR config"
1764 add_health_test_drop_rules network_timeout
1766 do_lnetctl discover ${RNIDS[0]} &&
1767 error "Should have failed"
1768 $LCTL net_drop_del -a
1772 check_no_resends || return $?
1773 check_no_local_health || return $?
1774 check_no_remote_health || return $?
1776 cleanup_health_test || return $?
1778 setup_health_test true || return $?
1780 echo "Simulate network_timeout w/MR config"
1784 add_health_test_drop_rules network_timeout
1786 do_lnetctl discover ${RNIDS[0]} &&
1787 error "Should have failed"
1788 $LCTL net_drop_del -a
1792 check_no_resends || return $?
1793 check_local_health || return $?
1794 check_remote_health || return $?
1796 cleanup_health_test || return $?
1800 run_test 209 "Check health, but not resends, for network timeout"
1802 check_nid_in_recovq() {
1803 local recovq=$($LNETCTL debug recovery $1)
1805 local nids=$($LCTL list_nids | xargs echo)
1809 echo "Check \"$1\" recovery queue"
1811 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1812 error "Expect $expect NIDs found: \"$recovq\""
1815 [[ $expect -eq 0 ]] && return 0
1817 for nid in ${nids}; do
1818 grep -q "nid-0: $nid"<<<$recovq &&
1823 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1829 # First enqueue happens at time 0.
1830 # 2nd at 0 + 2^0 = 1
1831 # 3rd at 1 + 2^1 = 3
1832 # 4th at 3 + 2^2 = 7
1833 # 5th at 7 + 2^3 = 15
1834 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1835 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1837 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1838 # we expect the peer NI to have aged out, so it will not actually be
1840 check_ping_count() {
1844 echo "Check ping counts:"
1846 if [[ $queue == "ni" ]]; then
1847 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1848 ping_count=( $($LNETCTL net show -v 2 |
1849 awk '/ping_count/{print $NF}') )
1850 elif [[ $queue == "peer_ni" ]]; then
1851 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1852 ping_count=( $($LNETCTL peer show -v 2 |
1853 awk '/ping_count/{print $NF}') )
1855 error "Unrecognized queue \"$queue\""
1861 for count in "${ping_count[@]}"; do
1862 if [[ $count -eq $expect ]]; then
1863 if [[ $expect -ne 0 ]] && $found ; then
1864 error "Found more than one interface matching \"$expect\" ping count"
1867 echo "Expect ping count \"$expect\" found \"$count\""
1870 elif [[ $count -ne 0 ]]; then
1871 error "Found interface with ping count \"$count\" but expect \"$expect\""
1880 reinit_dlc || return $?
1881 add_net "tcp" "${INTERFACES[0]}" || return $?
1882 add_net "tcp1" "${INTERFACES[0]}" || return $?
1884 local prim_nid=$($LCTL list_nids | head -n 1)
1886 do_lnetctl discover $prim_nid ||
1887 error "failed to discover myself"
1889 # Set recovery limit to 10 seconds.
1890 do_lnetctl set recovery_limit 10 ||
1891 error "failed to set recovery_limit"
1893 $LCTL set_param debug=+net
1894 # Use local_error so LNet doesn't attempt to resend the discovery ping
1895 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1896 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1897 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1898 error "Expected discovery to fail"
1901 check_nid_in_recovq "-l" 1
1902 check_ping_count "ni" "2"
1906 check_nid_in_recovq "-l" 1
1907 check_ping_count "ni" "3"
1909 $LCTL net_drop_del -a
1913 run_test 210 "Local NI recovery checks"
1916 reinit_dlc || return $?
1917 add_net "tcp" "${INTERFACES[0]}" || return $?
1918 add_net "tcp1" "${INTERFACES[0]}" || return $?
1920 local prim_nid=$($LCTL list_nids | head -n 1)
1922 do_lnetctl discover $prim_nid ||
1923 error "failed to discover myself"
1925 # Set recovery limit to 10 seconds.
1926 do_lnetctl set recovery_limit 10 ||
1927 error "failed to set recovery_limit"
1929 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1930 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1932 # Set health to 0 on one interface. This forces it onto the recovery
1934 $LNETCTL peer set --nid $prim_nid --health 0
1936 # After 5 seconds, we expect the peer NI to still be in recovery
1938 check_nid_in_recovq "-p" 1
1939 check_ping_count "peer_ni" "2"
1941 # After 15 seconds, the peer NI should have been fully processed out of
1942 # the recovery queue. We'll allow a total of 17 seconds to account for
1943 # differences in sleeping for whole seconds vs. the more accurate time
1944 # keeping that is done in the recovery code.
1946 check_nid_in_recovq "-p" 0
1947 check_ping_count "peer_ni" "4"
1949 $LCTL net_drop_del -a
1951 # Set health to force it back onto the recovery queue. Set to 500 means
1952 # in 5 seconds it should be back at maximum value. We'll wait a couple
1953 # more seconds than that to be safe.
1954 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1956 do_lnetctl set recovery_limit 0 ||
1957 error "failed to set recovery_limit"
1959 $LNETCTL peer set --nid $prim_nid --health 500
1961 check_nid_in_recovq "-p" 1
1962 check_ping_count "peer_ni" "2"
1966 check_nid_in_recovq "-p" 0
1967 check_ping_count "peer_ni" "0"
1971 run_test 211 "Remote NI recovery checks"
1974 local rnodes=$(remote_nodes_list)
1975 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1977 cleanup_lnet || error "Failed to cleanup before test execution"
1979 # Loading modules should configure LNet with the appropriate
1980 # test-framework configuration
1981 load_lnet "config_on_load=1" || error "Failed to load modules"
1983 local my_nid=$($LCTL list_nids | head -n 1)
1985 error "Failed to get primary NID for local host $HOSTNAME"
1987 local rnode=$(awk '{print $1}' <<<$rnodes)
1988 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1991 if [[ -z $rnodenids ]]; then
1992 do_rpc_nodes $rnode load_lnet "config_on_load=1"
1994 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
1997 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
1999 [[ -z $rnodepnid ]] &&
2000 error "Failed to get primary NID for remote host $rnode"
2002 log "Initial discovery"
2003 do_lnetctl discover --force $rnodepnid ||
2004 error "Failed to discover $rnodepnid"
2006 do_node $rnode "$LNETCTL discover --force $my_nid" ||
2007 error "$rnode failed to discover $my_nid"
2009 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2010 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2011 do_lnetctl discover --force $rnodepnid &&
2012 error "Discovery should have failed"
2013 $LCTL net_drop_del -a
2016 for nid in $rnodenids; do
2017 # We need GET (PING) delay just long enough so we can trigger
2018 # discovery on the remote peer
2019 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2020 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2021 # We need PUT (PUSH) delay just long enough so we can process
2023 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2026 log "Force $HOSTNAME to discover $rnodepnid (in background)"
2027 # We want to get a PING sent that we know will eventually fail.
2028 # The delay rules we added will ensure the ping is not sent until
2029 # the PUSH is also in flight (see below), and the drop rule ensures that
2030 # when the PING is eventually sent it will error out
2031 do_lnetctl discover --force $rnodepnid &
2034 # We want a discovery PUSH from rnode to put rnode back on our
2035 # discovery queue. This should cause us to try and send a PUSH to rnode
2036 # while the PING is still outstanding.
2037 log "Force $rnode to discover $my_nid"
2038 do_node $rnode $LNETCTL discover --force $my_nid
2040 # At this point we'll have both PING_SENT and PUSH_SENT set for the
2041 # rnode peer. Wait for the PING to error out which should terminate the
2042 # discovery process that we backgrounded.
2043 log "Wait for $pid1"
2045 log "Finished wait on $pid1"
2047 # The PING send failure clears the PING_SENT flag and puts the peer back
2048 # on the discovery queue. When discovery thread processes the peer it
2049 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2050 # Discovery will then complete for this peer even though we have an
2052 # When PUSH is actually unlinked it will be forced back onto the
2053 # discovery queue, but we no longer have a ref on the peer. When
2054 # discovery completes again, we'll trip the ASSERT in
2055 # lnet_destroy_peer_locked()
2057 # Delete the delay rules to send the PUSH
2058 $LCTL net_delay_del -a
2059 # Delete the drop rules
2060 $LCTL net_drop_del -a
2063 error "Failed to unload modules"
2065 do_rpc_nodes $rnode unload_modules_local ||
2066 error "Failed to unload modules on $rnode"
2071 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2074 cleanup_netns || error "Failed to cleanup netns before test execution"
2075 cleanup_lnet || error "Failed to unload modules before test execution"
2077 setup_fakeif || error "Failed to add fake IF"
2078 have_interface "$FAKE_IF" ||
2079 error "Expect $FAKE_IF configured but not found"
2081 reinit_dlc || return $?
2083 add_net "tcp" "${INTERFACES[0]}" || return $?
2084 add_net "tcp" "$FAKE_IF" || return $?
2086 local nid1=$(lctl list_nids | head -n 1)
2087 local nid2=$(lctl list_nids | tail --lines 1)
2089 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2090 error "Expect nid1 \"$nid1\" to be preferred"
2092 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2093 error "Expect nid2 \"$nid2\" to be preferred"
2097 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2099 function check_ni_status() {
2103 local status=$($LNETCTL net show |
2105 awk '/status/{print $NF}')
2107 echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2108 if [[ $status != $expect ]]; then
2109 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2116 cleanup_netns || error "Failed to cleanup netns before test execution"
2117 cleanup_lnet || error "Failed to unload modules before test execution"
2119 setup_fakeif || error "Failed to add fake IF"
2120 have_interface "$FAKE_IF" ||
2121 error "Expect $FAKE_IF configured but not found"
2123 reinit_dlc || return $?
2125 add_net "tcp" "${INTERFACES[0]}" || return $?
2126 add_net "tcp" "$FAKE_IF" || return $?
2128 local nid1=$(lctl list_nids | head -n 1)
2129 local nid2=$(lctl list_nids | tail --lines 1)
2131 check_ni_status "0@lo" up
2132 check_ni_status "$nid1" up
2133 check_ni_status "$nid2" up
2135 echo "Set $FAKE_IF down"
2136 echo "ip link set dev $FAKE_IF down"
2137 ip link set dev $FAKE_IF down
2138 check_ni_status "0@lo" up
2139 check_ni_status "$nid1" up
2140 check_ni_status "$nid2" down
2142 run_test 214 "Check local NI status when link is downed"
2148 $LNETCTL net show -v 2 |
2149 egrep -e nid -e $stat |
2151 awk '/'$stat':/{print $NF}'
2156 for nidvar in nid1 nid2; do
2157 for stat in send_count recv_count; do
2158 s=$(get_ni_stat ${!nidvar} $stat)
2159 eval ${nidvar}_pre_${stat}=$s
2166 for nidvar in nid1 nid2; do
2167 for stat in send_count recv_count; do
2168 s=$(get_ni_stat ${!nidvar} $stat)
2169 eval ${nidvar}_post_${stat}=$s
2179 eval pre=\${${nidvar}_pre_${stat}}
2180 eval post=\${${nidvar}_post_${stat}}
2182 echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2184 [[ $pre -ne $post ]]
2188 cleanup_netns || error "Failed to cleanup netns before test execution"
2189 cleanup_lnet || error "Failed to unload modules before test execution"
2191 reinit_dlc || return $?
2193 add_net "tcp1" "${INTERFACES[0]}" || return $?
2194 add_net "tcp2" "${INTERFACES[0]}" || return $?
2196 local nid1=$($LCTL list_nids | head -n 1)
2197 local nid2=$($LCTL list_nids | tail --lines 1)
2199 do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2200 error "Failed to add peer"
2204 for nidvarA in nid1 nid2; do
2207 for nidvarB in nid1 nid2; do
2208 [[ $nidvarA == $nidvarB ]] && continue
2212 echo "$LNETCTL ping $dst x $npings"
2213 for i in $(seq 1 $npings); do
2214 $LNETCTL ping $dst &>/dev/null ||
2215 error "$LNETCTL ping $dst failed"
2220 # No source specified, sends to either NID should cause
2221 # counts to increase across both NIs
2222 for nidvar in nid1 nid2; do
2223 for stat in send_count recv_count; do
2224 ni_stat_changed $nidvar $stat ||
2225 error "$stat unchanged for ${!nidvar}"
2231 echo "$LNETCTL ping --source $src $dst x $npings"
2232 for i in $(seq 1 $npings); do
2233 $LNETCTL ping --source $src $dst &>/dev/null ||
2234 error "$LNETCTL ping --source $src $dst failed"
2239 # src nid == dest nid means stats for the _other_ NI
2240 # should be unchanged
2241 for nidvar in nid1 nid2; do
2242 for stat in send_count recv_count; do
2243 if [[ ${!nidvar} == $src ]]; then
2244 ni_stat_changed $nidvar $stat ||
2245 error "$stat unchanged for ${!nidvar}"
2247 ni_stat_changed $nidvar $stat &&
2248 error "$stat changed for ${!nidvar}"
2253 # Double number of pings for next iteration because the net
2254 # sequence numbers will have diverged
2255 npings=$(($npings * 2))
2258 # Ping from nid1 to nid2 should fail
2259 do_lnetctl ping --source $nid1 $nid2 &&
2260 error "ping from $nid1 to $nid2 should fail"
2262 # Ping from nid2 to nid1 should fail
2263 do_lnetctl ping --source $nid2 $nid1 &&
2264 error "ping from $nid2 to $nid1 should fail"
2268 run_test 215 "Test lnetctl ping --source option"
2273 reinit_dlc || return $?
2275 add_net "tcp" "${INTERFACES[0]}" || return $?
2276 add_net "tcp1" "${INTERFACES[0]}" || return $?
2278 local nids=( $($LCTL list_nids | xargs echo) )
2280 do_lnetctl discover ${nids[0]} ||
2281 error "Initial discovery failed"
2283 do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2284 error "Initial ping failed $?"
2286 do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2287 error "Initial ping failed $?"
2290 for src in "${nids[@]}"; do
2291 for dst in "${nids[@]}"; do
2292 $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2296 do_lnetctl ping ${nids[0]} || rc=$?
2298 $LCTL net_drop_del -a
2301 error "expected ping to fail"
2303 check_nid_in_recovq "-p" 0
2304 check_nid_in_recovq "-l" 1
2308 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2311 reinit_dlc || return $?
2313 [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2314 error "Unexpected number of NIs after initalizing DLC"
2316 do_lnetctl discover 0@lo ||
2317 error "Failed to discover 0@lo"
2321 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2324 reinit_dlc || return $?
2326 [[ ${#INTERFACES[@]} -lt 2 ]] &&
2327 skip "Need two LNet interfaces"
2329 add_net "tcp" "${INTERFACES[0]}" || return $?
2331 local nid1=$($LCTL list_nids | head -n 1)
2333 do_lnetctl ping $nid1 ||
2336 add_net "tcp" "${INTERFACES[1]}" || return $?
2338 local nid2=$($LCTL list_nids | tail --lines 1)
2340 do_lnetctl ping $nid2 ||
2343 $LCTL net_drop_add -s $nid1 -d $nid1 -e local_error -r 1
2345 do_lnetctl ping $nid1 &&
2346 error "ping should have failed"
2348 local health_recovered
2351 for i in $(seq 1 5); do
2352 health_recovered=$($LNETCTL net show -v 2 |
2353 grep -c 'health value: 1000')
2355 if [[ $health_recovered -ne 2 ]]; then
2356 echo "Wait 1 second for health to recover"
2363 health_recovered=$($LNETCTL net show -v 2 |
2364 grep -c 'health value: 1000')
2366 $LCTL net_drop_del -a
2368 [[ $health_recovered -ne 2 ]] &&
2369 do_lnetctl net show -v 2 | egrep -e nid -e health &&
2370 error "Health hasn't recovered"
2374 run_test 218 "Local recovery pings should exercise all available paths"
2377 reinit_dlc || return $?
2378 add_net "tcp" "${INTERFACES[0]}" || return $?
2379 add_net "tcp1" "${INTERFACES[0]}" || return $?
2381 local nid1=$(lctl list_nids | head -n 1)
2382 local nid2=$(lctl list_nids | tail --lines 1)
2384 do_lnetctl ping $nid1 ||
2385 error "Ping failed $?"
2386 do_lnetctl ping $nid2 ||
2387 error "Ping failed $?"
2389 do_lnetctl discover $nid2 ||
2390 error "Discovery failed"
2392 $LNETCTL peer show --nid $nid1 | grep -q $nid2 ||
2393 error "$nid2 is not listed under $nid1"
2395 run_test 219 "Consolidate peer entries"
2399 echo "Check valid values; Should succeed"
2403 for ((i = 4; i < 16; i+=1)); do
2404 reinit_dlc || return $?
2405 add_net "tcp" "${INTERFACES[0]}" || return $?
2406 do_lnetctl net set --all --conns-per-peer $i ||
2407 error "should have succeeded $?"
2408 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2409 error "failed to set conns-per-peer to $i"
2410 lnid="$(lctl list_nids | head -n 1)"
2411 do_lnetctl ping "$lnid" ||
2412 error "failed to ping myself"
2414 # "lctl --net tcp conn_list" prints the list of active
2415 # connections. Since we're pinging ourselves, there should be
2416 # 2 Control connections plus 2*conns_per_peer connections
2417 # created (one Bulk Input, one Bulk Output in each pair).
2418 # Here's the sample output for conns_per_peer set to 1:
2419 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2420 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2421 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2422 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2423 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2425 # Expect 2+conns_per_peer*2 connections. Wait no longer
2427 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2428 error "expected number of tcp connections $((2+i*2))"
2431 reinit_dlc || return $?
2432 add_net "tcp" "${INTERFACES[0]}" || return $?
2433 echo "Set > 127; Should fail"
2434 do_lnetctl net set --all --conns-per-peer 128 &&
2435 error "should have failed $?"
2437 reinit_dlc || return $?
2438 add_net "tcp" "${INTERFACES[0]}" || return $?
2439 echo "Set < 0; Should be ignored"
2440 do_lnetctl net set --all --conns-per-peer -1 ||
2441 error "should have succeeded $?"
2442 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2443 error "Did not stay at default"
2445 run_test 230 "Test setting conns-per-peer"
2447 ### Test that linux route is added for each ni
2449 reinit_dlc || return $?
2450 add_net "tcp" "${INTERFACES[0]}" || return $?
2451 ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
2453 run_test 250 "test that linux routes are added"
2458 local out=$TMP/$tfile
2459 local prefix=/usr/include/linux/lnet
2461 # We use a hard coded prefix so that this test will not fail
2464 if ! which $CC > /dev/null 2>&1; then
2465 skip_env "$CC is not installed"
2468 cleanup_lnet || exit 1
2471 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2472 if ! [[ -d $prefix ]]; then
2473 # Assume we're running in tree and fixup the include path.
2474 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2475 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2478 for header in $prefix/*.h; do
2479 if ! [[ -f "$header" ]]; then
2483 echo "$CC $cc_args -include $header"
2484 $CC $cc_args -include $header ||
2485 error "cannot compile '$header'"
2489 run_test 300 "packaged LNet UAPI headers can be compiled"