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"
72 load_module ../libcfs/libcfs/libcfs
73 # Prevent local MODOPTS_LIBCFS being passed as part of environment
74 # variable to remote nodes
77 set_default_debug "neterror net nettrace malloc"
78 load_module ../lnet/lnet/lnet "$@"
80 LNDPATH=${LNDPATH:-"../lnet/klnds"}
81 if [ -z "$LNETLND" ]; then
83 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
84 tcp*) LNETLND="socklnd/ksocklnd" ;;
85 *) local lnd="${NETTYPE%%[0-9]}lnd"
86 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
87 LNETLND="$lnd/k$lnd" ||
88 LNETLND="socklnd/ksocklnd"
91 load_module ../lnet/klnds/$LNETLND
103 echo "ip netns exec $TESTNS $@"
104 ip netns exec $TESTNS "$@"
112 netns_arg="netns $netns"
114 ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
115 ip link set 'test1pl' up
116 if [[ -n $netns ]]; then
117 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
118 do_ns ip link set $FAKE_IF up
120 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
121 ip link set $FAKE_IF up
126 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
137 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
142 echo "Loading LNet and configuring DLC"
144 do_lnetctl lnet configure
147 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
148 define_global_yaml() {
149 $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
150 error "Failed to export global yaml $?"
154 if lsmod | grep -q lnet; then
155 do_lnetctl lnet unconfigure ||
156 error "lnetctl lnet unconfigure failed $?"
157 do_lnetctl lnet configure ||
158 error "lnetctl lnet configure failed $?"
160 configure_dlc || error "configure_dlc failed $?"
165 append_global_yaml() {
166 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
167 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
169 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
172 create_base_yaml_file() {
176 compare_yaml_files() {
177 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
178 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
180 ! [[ -e $expected ]] && echo "$expected not found" && return 1
181 ! [[ -e $actual ]] && echo "$actual not found" && return 1
182 diff -upN ${actual} ${expected} || rc=$?
192 local net="${nid//*@/}"
193 local addr="${nid//@*/}"
195 local num_re='[0-9]\+'
196 local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
198 if [[ $net =~ gni[0-9]* ]]; then
199 [[ $addr =~ ${num_re} ]] && return 0
201 [[ $addr =~ ${ip_re} ]] && return 0
206 local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
207 local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
208 local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
209 local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
212 for nid in $primary_nids $secondary_nids; do
213 validate_nid "$nid" || error "Bad NID \"${nid}\""
218 validate_peer_nids() {
220 local nids_per_peer="$2"
222 local expect_p="$num_peers"
223 # The primary nid also shows up in the list of secondary nids
224 local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
226 local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
227 local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
228 if [[ $expect_p -ne $actual_p ]]; then
230 error "Expected $expect_p but found $actual_p primary nids"
231 elif [[ $expect_s -ne $actual_s ]]; then
233 error "Expected $expect_s but found $actual_s secondary nids"
238 validate_gateway_nids() {
239 local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
240 local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
241 if [[ $expect_gw -ne $actual_gw ]]; then
243 error "Expected $expect_gw gateways but found $actual_gw gateways"
249 setup_netns || error "setup_netns failed with $?"
251 # Determine the local interface(s) used for LNet
252 load_modules || error "Failed to load modules"
257 INTERFACES=( $(lnet_if_list) )
259 cleanup_lnet || error "Failed to cleanup LNet"
261 stack_trap 'cleanup_testsuite' EXIT
264 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
265 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
267 reinit_dlc || return $?
268 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
269 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
270 create_base_yaml_file
271 compare_yaml_files || error "Configuration changed after import"
273 run_test 0 "Export empty config, import the config, compare"
276 local prim_nid="${1:+--prim_nid $1}"
277 local nid="${2:+--nid $2}"
279 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
281 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
282 $LNETCTL export --backup > $actual || error "export failed $?"
288 reinit_dlc || return $?
289 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
291 - primary nid: 1.1.1.1@tcp
297 compare_peer_add "1.1.1.1@tcp"
299 run_test 1 "Add peer with single nid (tcp)"
302 reinit_dlc || return $?
303 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
305 - primary nid: 2.2.2.2@o2ib
311 compare_peer_add "2.2.2.2@o2ib"
313 run_test 2 "Add peer with single nid (o2ib)"
316 reinit_dlc || return $?
317 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
319 - primary nid: 3.3.3.3@tcp
326 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
328 run_test 3 "Add peer with tcp primary o2ib secondary"
331 reinit_dlc || return $?
332 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
334 - primary nid: 4.4.4.4@tcp
343 echo "Add peer with nidrange (tcp)"
344 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
346 echo "Add peer with nidrange that overlaps primary nid (tcp)"
347 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
349 run_test 4 "Add peer with nidrange (tcp)"
352 reinit_dlc || return $?
353 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
355 - primary nid: 5.5.5.5@o2ib
365 echo "Add peer with nidrange (o2ib)"
366 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
368 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
369 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
371 run_test 5 "Add peer with nidrange (o2ib)"
374 reinit_dlc || return $?
375 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
377 - primary nid: 6.6.6.6@tcp
397 compare_peer_add "6.6.6.6@tcp" \
398 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
400 run_test 6 "Add peer with multiple nidranges"
403 local prim_nid="${1:+--prim_nid $1}"
404 local nid="${2:+--nid $2}"
406 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
408 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
409 $LNETCTL export --backup > $actual || error "export failed $?"
415 reinit_dlc || return $?
416 create_base_yaml_file
418 echo "Delete peer with single nid (tcp)"
419 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
420 compare_peer_del "7.7.7.7@tcp"
422 echo "Delete peer with single nid (o2ib)"
423 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
424 compare_peer_del "7.7.7.7@o2ib"
426 echo "Delete peer that has multiple nids (tcp)"
427 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
428 error "Peer add failed $?"
429 compare_peer_del "7.7.7.7@tcp"
431 echo "Delete peer that has multiple nids (o2ib)"
432 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
433 error "Peer add failed $?"
434 compare_peer_del "7.7.7.7@o2ib"
436 echo "Delete peer that has both tcp and o2ib nids"
437 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
438 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
439 error "Peer add failed $?"
440 compare_peer_del "7.7.7.7@tcp"
442 echo "Delete peer with single nid (gni)"
443 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
444 compare_peer_del "7@gni"
446 echo "Delete peer that has multiple nids (gni)"
447 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
448 error "Peer add failed $?"
449 compare_peer_del "7@gni"
451 echo "Delete peer that has tcp, o2ib and gni nids"
452 do_lnetctl peer add --prim_nid 7@gni \
453 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
454 error "Peer add failed $?"
455 compare_peer_del "7@gni"
457 run_test 7 "Various peer delete tests"
460 reinit_dlc || return $?
462 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
464 - primary nid: 8.8.8.8@tcp
476 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
477 error "Peer add failed $?"
478 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
480 run_test 8 "Delete single secondary nid from peer (tcp)"
483 reinit_dlc || return $?
485 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
487 - primary nid: 9.9.9.9@tcp
494 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
495 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
496 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
498 run_test 9 "Delete all secondary nids from peer (tcp)"
501 reinit_dlc || return $?
503 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
505 - primary nid: 10.10.10.10@tcp
508 - nid: 10.10.10.10@tcp
509 - nid: 10.10.10.12@tcp
510 - nid: 10.10.10.13@tcp
511 - nid: 10.10.10.15@tcp
512 - nid: 10.10.10.16@tcp
515 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
516 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
517 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
519 run_test 10 "Delete single secondary nid from peer (o2ib)"
522 reinit_dlc || return $?
524 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
526 - primary nid: 11.11.11.11@tcp
529 - nid: 11.11.11.11@tcp
532 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
533 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
534 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
536 run_test 11 "Delete all secondary nids from peer (o2ib)"
539 reinit_dlc || return $?
541 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
543 - primary nid: 12.12.12.12@o2ib
546 - nid: 12.12.12.12@o2ib
547 - nid: 13.13.13.13@o2ib
548 - nid: 14.13.13.13@o2ib
549 - nid: 14.15.13.13@o2ib
551 - nid: 15.17.1.10@tcp
552 - nid: 15.17.1.20@tcp
555 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
556 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
557 error "Peer add failed $?"
558 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
560 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
563 reinit_dlc || return $?
565 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
567 - primary nid: 13.13.13.13@o2ib
570 - nid: 13.13.13.13@o2ib
573 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
574 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
575 error "Peer add failed $?"
576 compare_peer_del "13.13.13.13@o2ib" \
577 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
579 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
585 if [[ $net =~ gni* ]]; then
588 echo "${num}.${num}.${num}.${num}@${net}"
592 create_mr_peer_yaml() {
594 local secondary_nids="$2"
597 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
598 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
600 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
603 while [[ $created -lt $num_peers ]]; do
604 local primary=$(create_nid ${nidnum} ${net})
605 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
606 - primary nid: $primary
612 local start=$((nidnum + 1))
613 local end=$((nidnum + $secondary_nids))
614 for j in $(seq ${start} ${end}); do
615 local nid=$(create_nid $j ${net})
616 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
624 reinit_dlc || return $?
626 echo "Create single peer, single nid, using import"
627 create_mr_peer_yaml 1 0 tcp
628 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
629 error "Import failed $?"
631 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
634 echo "Delete single peer using import --del"
635 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
636 error "Import failed $?"
637 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
638 create_base_yaml_file
639 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
642 run_test 14 "import peer create/delete with single nid"
645 reinit_dlc || return $?
647 echo "Create multiple peers, single nid per peer, using import"
648 create_mr_peer_yaml 5 0 o2ib
649 # The ordering of nids for this use-case is non-deterministic, so we
650 # we can't just diff the expected/actual output.
651 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
652 error "Import failed $?"
653 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
654 validate_peer_nids 5 0
656 echo "Delete multiple peers, single nid per peer, using import --del"
657 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
658 error "Import failed $?"
659 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
660 create_base_yaml_file
661 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
664 run_test 15 "import multi peer create/delete with single nid per peer"
667 reinit_dlc || return $?
669 echo "Create single peer, multiple nids, using import"
670 create_mr_peer_yaml 1 5 tcp
671 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
672 error "Import failed $?"
673 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
674 validate_peer_nids 1 5
676 echo "Delete single peer, multiple nids, using import --del"
677 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
678 error "Import failed $?"
679 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
680 create_base_yaml_file
681 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
684 run_test 16 "import peer create/delete with multiple nids"
687 reinit_dlc || return $?
689 echo "Create multiple peers, multiple nids per peer, using import"
690 create_mr_peer_yaml 5 7 o2ib
691 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
692 error "Import failed $?"
693 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
694 validate_peer_nids 5 7
696 echo "Delete multiple peers, multiple nids per peer, using import --del"
697 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
698 error "Import failed $?"
699 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
700 create_base_yaml_file
701 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
704 run_test 17 "import multi peer create/delete with multiple nids"
707 reinit_dlc || return $?
709 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
711 - primary nid: 1.1.1.1@tcp
720 echo "Import peer with 5 nids"
721 cat $TMP/sanity-lnet-$testnum-expected.yaml
722 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
723 error "Import failed $?"
724 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
726 - primary nid: 1.1.1.1@tcp
733 echo "Delete three of the nids"
734 cat $TMP/sanity-lnet-$testnum-expected.yaml
735 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
736 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
738 - primary nid: 1.1.1.1@tcp
744 echo "Check peer has expected nids remaining"
745 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
749 run_test 18a "Delete a subset of nids from a single peer using import --del"
752 reinit_dlc || return $?
754 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
756 - primary nid: 1.1.1.1@tcp
764 - primary nid: 6.6.6.6@o2ib
773 echo "Import two peers with 5 nids each"
774 cat $TMP/sanity-lnet-$testnum-expected.yaml
775 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
776 error "Import failed $?"
777 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
779 - primary nid: 1.1.1.1@tcp
785 - primary nid: 6.6.6.6@o2ib
792 echo "Delete three of the nids from each peer"
793 cat $TMP/sanity-lnet-$testnum-expected.yaml
794 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
795 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
797 - primary nid: 6.6.6.6@o2ib
802 - primary nid: 1.1.1.1@tcp
809 echo "Check peers have expected nids remaining"
810 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
812 validate_peer_nids 2 1
814 run_test 18b "Delete multiple nids from multiple peers using import --del"
817 reinit_dlc || return $?
818 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
820 - primary nid: 19@gni
826 compare_peer_add "19@gni"
828 run_test 19 "Add peer with single nid (gni)"
831 reinit_dlc || return $?
832 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
834 - primary nid: 20@gni
838 - nid: 20.20.20.20@tcp
839 - nid: 20.20.20.20@o2ib
842 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
844 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
847 reinit_dlc || return $?
848 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
850 - primary nid: 21@gni
860 echo "Add peer with nidrange (gni)"
861 compare_peer_add "21@gni" "[22-25]@gni" || error
862 echo "Add peer with nidrange that overlaps primary nid (gni)"
863 compare_peer_add "21@gni" "[21-25]@gni"
865 run_test 21 "Add peer with nidrange (gni)"
868 reinit_dlc || return $?
869 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
871 - primary nid: 22@gni
882 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
883 error "Peer add failed $?"
884 compare_peer_del "22@gni" "26@gni"
886 run_test 22 "Delete single secondary nid from peer (gni)"
889 reinit_dlc || return $?
890 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
892 - primary nid: 23@gni
899 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
900 error "Peer add failed $?"
901 compare_peer_del "23@gni" "[25-29]@gni"
903 run_test 23 "Delete all secondary nids from peer (gni)"
906 reinit_dlc || return $?
907 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
909 - primary nid: 24@gni
914 - nid: 13.13.13.13@o2ib
915 - nid: 14.13.13.13@o2ib
916 - nid: 14.15.13.13@o2ib
918 - nid: 15.17.1.10@tcp
919 - nid: 15.17.1.20@tcp
922 do_lnetctl peer add --prim_nid 24@gni \
923 --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 ||
924 error "Peer add failed $?"
925 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
927 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
930 reinit_dlc || return $?
931 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
933 - primary nid: 25@gni
939 do_lnetctl peer add --prim_nid 25@gni \
940 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
941 error "Peer add failed $?"
942 compare_peer_del "25@gni" \
943 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
945 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
948 reinit_dlc || return $?
950 echo "Invalid prim_nid - peer add"
951 do_lnetctl peer add --prim_nid foobar &&
952 error "Command should have failed"
954 echo "Invalid prim_nid - peer del"
955 do_lnetctl peer del --prim_nid foobar &&
956 error "Command should have failed"
958 echo "Delete non-existing peer"
959 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
960 error "Command should have failed"
962 echo "Don't provide mandatory argument for peer del"
963 do_lnetctl peer del --nid 1.1.1.1@tcp &&
964 error "Command should have failed"
966 echo "Don't provide mandatory argument for peer add"
967 do_lnetctl peer add --nid 1.1.1.1@tcp &&
968 error "Command should have failed"
970 echo "Don't provide mandatory arguments peer add"
971 do_lnetctl peer add &&
972 error "Command should have failed"
974 echo "Invalid secondary nids"
975 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
976 error "Command should have failed"
978 echo "Exceed max nids per peer"
979 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
980 error "Command should have failed"
982 echo "Invalid net type"
983 do_lnetctl peer add --prim_nid 1@foo &&
984 error "Command should have failed"
986 echo "Invalid nid format"
987 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
990 for nid in ${invalid_nids}; do
991 echo "Check invalid primary nid - '$nid'"
992 do_lnetctl peer add --prim_nid $nid &&
993 error "Command should have failed"
996 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
997 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
998 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
1001 for nidstr in ${invalid_strs}; do
1002 echo "Check invalid nidstring - '$nidstr'"
1003 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
1004 error "Command should have failed"
1007 echo "Add non-local gateway"
1008 do_lnetctl route add --net tcp --gateway 1@gni &&
1009 error "Command should have failed"
1013 run_test 99a "Check various invalid inputs to lnetctl peer"
1016 reinit_dlc || return $?
1018 create_base_yaml_file
1020 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1022 - primary nid: 99.99.99.99@tcp
1025 - nid: 99.99.99.99@tcp
1027 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1028 error "import should have failed"
1029 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1032 run_test 99b "Invalid value for Multi-Rail in yaml import"
1036 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1044 if ! lsmod | grep -q ksocklnd ; then
1045 load_module ../lnet/klnds/socklnd/ksocklnd ||
1046 error "Can't load ksocklnd.ko"
1049 do_lnetctl net add --net ${net} --if ${if} ||
1050 error "Failed to add net ${net} on if ${if}"
1053 compare_route_add() {
1057 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1059 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1060 error "route add failed $?"
1061 # CPT configuration is pruned from the exported yaml, since the default
1062 # can vary across test systems (unlike default values for things like
1063 # peer_credits, peer_timeout, etc.)
1064 $LNETCTL export --backup | grep -v CPT > $actual ||
1065 error "export failed $?"
1066 validate_gateway_nids
1071 reinit_dlc || return $?
1072 add_net "tcp" "${INTERFACES[0]}"
1073 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1082 peer_buffer_credits: 0
1088 gateway: 7.7.7.7@tcp
1091 health_sensitivity: 1
1093 - primary nid: 7.7.7.7@tcp
1099 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1102 run_test 100 "Add route with single gw (tcp)"
1105 reinit_dlc || return $?
1106 add_net "tcp" "${INTERFACES[0]}"
1107 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1116 peer_buffer_credits: 0
1122 gateway: 8.8.8.10@tcp
1125 health_sensitivity: 1
1127 gateway: 8.8.8.9@tcp
1130 health_sensitivity: 1
1132 gateway: 8.8.8.8@tcp
1135 health_sensitivity: 1
1137 - primary nid: 8.8.8.9@tcp
1141 - primary nid: 8.8.8.10@tcp
1145 - primary nid: 8.8.8.8@tcp
1151 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1153 run_test 101 "Add route with multiple gw (tcp)"
1155 compare_route_del() {
1159 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1161 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1162 error "route del failed $?"
1163 $LNETCTL export --backup > $actual ||
1164 error "export failed $?"
1165 validate_gateway_nids
1169 reinit_dlc || return $?
1170 add_net "tcp" "${INTERFACES[0]}"
1171 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1172 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1173 error "route add failed $?"
1174 compare_route_del "tcp102" "102.102.102.102@tcp"
1176 run_test 102 "Delete route with single gw (tcp)"
1179 reinit_dlc || return $?
1180 add_net "tcp" "${INTERFACES[0]}"
1181 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1182 do_lnetctl route add --net tcp103 \
1183 --gateway 103.103.103.[103-120/4]@tcp ||
1184 error "route add failed $?"
1185 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1187 run_test 103 "Delete route with multiple gw (tcp)"
1190 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1192 reinit_dlc || return $?
1194 # Default value is '3'
1195 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1197 error "Expect 3 found $val"
1199 echo "Set < 0; Should fail"
1200 do_lnetctl set response_tracking -1 &&
1201 error "should have failed $?"
1203 reinit_dlc || return $?
1206 response_tracking: -10
1208 do_lnetctl import < $tyaml &&
1209 error "should have failed $?"
1211 echo "Check valid values; Should succeed"
1213 for ((i = 0; i < 4; i++)); do
1214 reinit_dlc || return $?
1215 do_lnetctl set response_tracking $i ||
1216 error "should have succeeded $?"
1217 $LNETCTL global show | grep -q "response_tracking: $i" ||
1218 error "Failed to set response_tracking to $i"
1219 reinit_dlc || return $?
1222 response_tracking: $i
1224 do_lnetctl import < $tyaml ||
1225 error "should have succeeded $?"
1226 $LNETCTL global show | grep -q "response_tracking: $i" ||
1227 error "Failed to set response_tracking to $i"
1230 reinit_dlc || return $?
1231 echo "Set > 3; Should fail"
1232 do_lnetctl set response_tracking 4 &&
1233 error "should have failed $?"
1235 reinit_dlc || return $?
1238 response_tracking: 10
1240 do_lnetctl import < $tyaml &&
1241 error "should have failed $?"
1244 run_test 104 "Set/check response_tracking param"
1247 reinit_dlc || return $?
1248 add_net "tcp" "${INTERFACES[0]}"
1249 do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1250 error "route add failed $?"
1251 do_lnetctl peer add --prim 105.105.105.105@tcp &&
1252 error "peer add should fail"
1256 run_test 105 "Adding duplicate GW peer should fail"
1259 reinit_dlc || return $?
1260 add_net "tcp" "${INTERFACES[0]}"
1261 do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1262 error "route add failed $?"
1263 do_lnetctl peer del --prim 106.106.106.106@tcp &&
1264 error "peer del should fail"
1268 run_test 106 "Deleting GW peer should fail"
1271 cleanup_lnet || exit 1
1272 load_lnet "networks=\"\""
1273 do_ns $LNETCTL lnet configure --all || exit 1
1274 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1276 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1279 cleanup_lnet || exit 1
1280 load_lnet "networks=tcp($FAKE_IF)"
1281 do_ns $LNETCTL lnet configure --all || exit 1
1282 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1284 run_test 201 "load lnet using networks module options in a non-default namespace"
1287 cleanup_lnet || exit 1
1288 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1289 do_ns $LNETCTL lnet configure --all || exit 1
1290 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1292 run_test 202 "load lnet using ip2nets in a non-default namespace"
1295 ### Add the interfaces in the target namespace
1298 cleanup_lnet || exit 1
1300 do_lnetctl lnet configure || exit 1
1301 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1303 run_test 203 "add a network using an interface in the non-default namespace"
1305 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1306 function save_lnet_params() {
1307 $LNETCTL global show | egrep -v '^global:$' |
1308 sed 's/://' > $LNET_PARAMS_FILE
1311 function restore_lnet_params() {
1313 while read param value; do
1314 [[ $param == max_intf ]] && continue
1315 [[ $param == lnd_timeout ]] && continue
1316 $LNETCTL set ${param} ${value} ||
1317 error "Failed to restore ${param} to ${value}"
1318 done < $LNET_PARAMS_FILE
1321 function lnet_health_pre() {
1324 # Lower transaction timeout to speed up test execution
1325 $LNETCTL set transaction_timeout 10 ||
1326 error "Failed to set transaction_timeout $?"
1328 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1329 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1330 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1331 xargs echo | sed 's/ /+/g' | bc -l)
1333 RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1334 awk '/health value/{print $NF}' | xargs echo |
1335 sed 's/ /+/g' | bc -l)
1337 # Might not have any peers so initialize to zero.
1338 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1343 function lnet_health_post() {
1344 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1345 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1346 awk '/health value/{print $NF}' |
1347 xargs echo | sed 's/ /+/g' | bc -l)
1349 RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1350 awk '/health value/{print $NF}' | xargs echo |
1351 sed 's/ /+/g' | bc -l)
1353 # Might not have any peers so initialize to zero.
1354 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1357 echo "Pre resends: $RSND_PRE" &&
1358 echo "Post resends: $RSND_POST" &&
1359 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1360 echo "Pre local health: $LO_HVAL_PRE" &&
1361 echo "Post local health: $LO_HVAL_POST" &&
1362 echo "Pre remote health: $RMT_HVAL_PRE" &&
1363 echo "Post remote health: $RMT_HVAL_POST"
1367 do_lnetctl peer set --health 1000 --all
1368 do_lnetctl net set --health 1000 --all
1373 function check_no_resends() {
1374 echo "Check that no resends took place"
1375 [[ $RSND_POST -ne $RSND_PRE ]] &&
1376 error "Found resends: $RSND_POST != $RSND_PRE"
1381 function check_resends() {
1382 local delta=$((RSND_POST - RSND_PRE))
1384 echo "Check that $RETRY_PARAM resends took place"
1385 [[ $delta -ne $RETRY_PARAM ]] &&
1386 error "Expected $RETRY_PARAM resends found $delta"
1391 function check_no_local_health() {
1392 echo "Check that local NI health is unchanged"
1393 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1394 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1399 function check_local_health() {
1400 echo "Check that local NI health has been changed"
1401 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1402 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1407 function check_no_remote_health() {
1408 echo "Check that remote NI health is unchanged"
1409 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1410 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1415 function check_remote_health() {
1416 echo "Check that remote NI health has been changed"
1417 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1418 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1428 setup_health_test() {
1432 local rnodes=$(remote_nodes_list)
1433 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1435 cleanup_lnet || error "Failed to cleanup before test execution"
1437 # Loading modules should configure LNet with the appropriate
1438 # test-framework configuration
1439 load_modules || error "Failed to load modules"
1441 LNIDS=( $($LCTL list_nids | xargs echo) )
1443 RNODE=$(awk '{print $1}' <<<$rnodes)
1444 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1446 if [[ -z ${RNIDS[@]} ]]; then
1447 do_rpc_nodes $RNODE load_modules_local
1449 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1452 [[ ${#LNIDS[@]} -lt 1 ]] &&
1453 error "No NIDs configured for local host $HOSTNAME"
1454 [[ ${#RNIDS[@]} -lt 1 ]] &&
1455 error "No NIDs configured for remote host $RNODE"
1457 do_lnetctl discover ${RNIDS[0]} ||
1458 error "Unable to discover ${RNIDS[0]}"
1460 local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1461 awk '/Multi-Rail/{print $NF}')
1463 if ${need_mr} && [[ $mr == False ]]; then
1464 cleanup_health_test || return $?
1468 if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1469 ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1470 cleanup_health_test || return $?
1474 if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1475 # Add a second, reachable NID to rnode.
1476 local net=${RNIDS[0]}
1480 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1482 error "Failed to determine interface for $RNODE"
1484 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1485 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1487 if [[ $rc -ne 0 ]]; then
1488 error "Failed to add interface to $RNODE rc=$?"
1490 RNIDS[1]="${RNIDS[0]}1"
1491 NET_DEL_ARGS="--net $net --if $if"
1495 if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1496 local net=${LNIDS[0]}
1499 do_lnetctl lnet configure &&
1500 do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1502 if [[ $rc -ne 0 ]]; then
1503 error "Failed to add interface rc=$?"
1505 LNIDS[1]="${LNIDS[0]}1"
1511 $LNETCTL peer show -v 2 | egrep -e nid -e health
1513 $LCTL set_param debug=+net
1519 cleanup_health_test() {
1522 if [[ -n $NET_DEL_ARGS ]]; then
1523 do_rpc_nodes $RNODE \
1524 "$LNETCTL net del $NET_DEL_ARGS" ||
1529 unload_modules || rc=$?
1532 do_rpc_nodes $RNODE unload_modules_local ||
1538 error "Failed cleanup"
1543 add_health_test_drop_rules() {
1547 for lnid in ${LNIDS[@]}; do
1548 for rnid in ${RNIDS[@]}; do
1549 $LCTL net_drop_add -s $lnid -d $rnid -m GET -r 1 -e ${hstatus}
1554 # See lnet/lnet/lib-msg.c:lnet_health_check()
1555 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1556 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1557 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1559 setup_health_test false || return $?
1562 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1563 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1564 echo "Simulate $hstatus"
1565 lnet_health_pre || return $?
1567 add_health_test_drop_rules ${hstatus}
1568 do_lnetctl discover ${RNIDS[0]} &&
1569 error "Should have failed"
1570 $LCTL net_drop_del -a
1574 check_no_resends || return $?
1575 check_no_local_health || return $?
1578 cleanup_health_test || return $?
1582 run_test 204 "Check no health or resends for single-rail local failures"
1585 setup_health_test true || return $?
1588 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1589 echo "Simulate $hstatus"
1590 lnet_health_pre || return $?
1592 add_health_test_drop_rules ${hstatus}
1593 do_lnetctl discover ${RNIDS[0]} &&
1594 error "Should have failed"
1595 $LCTL net_drop_del -a
1599 check_resends || return $?
1600 check_local_health || return $?
1603 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1604 echo "Simulate $hstatus"
1605 lnet_health_pre || return $?
1607 add_health_test_drop_rules ${hstatus}
1608 do_lnetctl discover ${RNIDS[0]} &&
1609 error "Should have failed"
1610 $LCTL net_drop_del -a
1614 check_no_resends || return $?
1615 check_local_health || return $?
1618 cleanup_health_test || return $?
1622 run_test 205 "Check health and resends for multi-rail local failures"
1624 # See lnet/lnet/lib-msg.c:lnet_health_check()
1625 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1626 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1628 setup_health_test false || return $?
1631 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1632 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1633 echo "Simulate $hstatus"
1634 lnet_health_pre || return $?
1636 add_health_test_drop_rules ${hstatus}
1637 do_lnetctl discover ${RNIDS[0]} &&
1638 error "Should have failed"
1639 $LCTL net_drop_del -a
1643 check_no_resends || return $?
1644 check_no_local_health || return $?
1645 check_no_remote_health || return $?
1648 cleanup_health_test || return $?
1652 run_test 206 "Check no health or resends for single-rail remote failures"
1655 setup_health_test true || return $?
1658 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1659 echo "Simulate $hstatus"
1660 lnet_health_pre || return $?
1662 add_health_test_drop_rules ${hstatus}
1664 do_lnetctl discover ${RNIDS[0]} &&
1665 error "Should have failed"
1669 $LCTL net_drop_del -a
1671 check_resends || return $?
1672 check_no_local_health || return $?
1673 check_remote_health || return $?
1674 do_lnetctl peer set --health 1000 --all ||
1675 error "Unable to reset health rc=$?"
1677 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1678 echo "Simulate $hstatus"
1679 lnet_health_pre || return $?
1681 add_health_test_drop_rules ${hstatus}
1683 do_lnetctl discover ${RNIDS[0]} &&
1684 error "Should have failed"
1688 $LCTL net_drop_del -a
1690 check_no_resends || return $?
1691 check_no_local_health || return $?
1692 check_remote_health || return $?
1693 do_lnetctl peer set --health 1000 --all ||
1694 error "Unable to reset health rc=$?"
1697 cleanup_health_test || return $?
1701 run_test 207 "Check health and resends for multi-rail remote errors"
1703 test_208_load_and_check_lnet() {
1707 local num_expected=1
1709 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1712 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1718 nids=( $($LCTL list_nids) )
1720 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1721 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1723 [[ ${nids[0]} == ${p_nid} ]] ||
1724 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1726 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1727 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1729 $LCTL net down &>/dev/null
1734 cleanup_netns || error "Failed to cleanup netns before test execution"
1735 cleanup_lnet || error "Failed to unload modules before test execution"
1736 setup_fakeif || error "Failed to add fake IF"
1738 have_interface "$FAKE_IF" ||
1739 error "Expect $FAKE_IF configured but not found"
1741 local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1742 awk '/inet /{print $4}' |
1744 if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1745 local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1747 echo "Configure single NID \"$ip2nets_str\""
1748 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1750 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1751 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1752 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1755 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1756 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1757 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1759 local addr1=( ${if0_ip//./ } )
1760 local addr2=( ${FAKE_IP//./ } )
1761 local range="[${addr1[0]},${addr2[0]}]"
1764 for i in $(seq 1 3); do
1765 range+=".[${addr1[$i]},${addr2[$i]}]"
1767 ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1769 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1770 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1775 echo "alt syntax with missing IF \"$ip2nets_str\""
1776 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1778 echo "$LCTL net up should fail"
1780 error "LNet bringup should have failed"
1784 run_test 208 "Test various kernel ip2nets configurations"
1787 setup_health_test false || return $?
1789 echo "Simulate network_timeout w/SR config"
1792 add_health_test_drop_rules network_timeout
1794 do_lnetctl discover ${RNIDS[0]} &&
1795 error "Should have failed"
1796 $LCTL net_drop_del -a
1800 check_no_resends || return $?
1801 check_no_local_health || return $?
1802 check_no_remote_health || return $?
1804 cleanup_health_test || return $?
1806 setup_health_test true || return $?
1808 echo "Simulate network_timeout w/MR config"
1812 add_health_test_drop_rules network_timeout
1814 do_lnetctl discover ${RNIDS[0]} &&
1815 error "Should have failed"
1816 $LCTL net_drop_del -a
1820 check_no_resends || return $?
1821 check_local_health || return $?
1822 check_remote_health || return $?
1824 cleanup_health_test || return $?
1828 run_test 209 "Check health, but not resends, for network timeout"
1830 check_nid_in_recovq() {
1831 local recovq=$($LNETCTL debug recovery $1)
1833 local nids=$($LCTL list_nids | xargs echo)
1837 echo "Check \"$1\" recovery queue"
1839 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1840 error "Expect $expect NIDs found: \"$recovq\""
1843 [[ $expect -eq 0 ]] && return 0
1845 for nid in ${nids}; do
1846 grep -q "nid-0: $nid"<<<$recovq &&
1851 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1857 # First enqueue happens at time 0.
1858 # 2nd at 0 + 2^0 = 1
1859 # 3rd at 1 + 2^1 = 3
1860 # 4th at 3 + 2^2 = 7
1861 # 5th at 7 + 2^3 = 15
1862 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1863 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1865 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1866 # we expect the peer NI to have aged out, so it will not actually be
1868 check_ping_count() {
1872 echo "Check ping counts:"
1874 if [[ $queue == "ni" ]]; then
1875 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1876 ping_count=( $($LNETCTL net show -v 2 |
1877 awk '/ping_count/{print $NF}') )
1878 elif [[ $queue == "peer_ni" ]]; then
1879 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1880 ping_count=( $($LNETCTL peer show -v 2 |
1881 awk '/ping_count/{print $NF}') )
1883 error "Unrecognized queue \"$queue\""
1889 for count in ${ping_count[@]}; do
1890 if [[ $count -eq $expect ]]; then
1891 if [[ $expect -ne 0 ]] && $found ; then
1892 error "Found more than one interface matching \"$expect\" ping count"
1895 echo "Expect ping count \"$expect\" found \"$count\""
1898 elif [[ $count -ne 0 ]]; then
1899 error "Found interface with ping count \"$count\" but expect \"$expect\""
1908 reinit_dlc || return $?
1909 add_net "tcp" "${INTERFACES[0]}" || return $?
1910 add_net "tcp1" "${INTERFACES[0]}" || return $?
1912 local prim_nid=$($LCTL list_nids | head -n 1)
1914 do_lnetctl discover $prim_nid ||
1915 error "failed to discover myself"
1917 # Set recovery limit to 10 seconds.
1918 do_lnetctl set recovery_limit 10 ||
1919 error "failed to set recovery_limit"
1921 $LCTL set_param debug=+net
1922 # Use local_error so LNet doesn't attempt to resend the discovery ping
1923 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1924 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1925 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1926 error "Expected discovery to fail"
1929 check_nid_in_recovq "-l" 1
1930 check_ping_count "ni" "2"
1934 check_nid_in_recovq "-l" 1
1935 check_ping_count "ni" "3"
1937 $LCTL net_drop_del -a
1941 run_test 210 "Local NI recovery checks"
1944 reinit_dlc || return $?
1945 add_net "tcp" "${INTERFACES[0]}" || return $?
1946 add_net "tcp1" "${INTERFACES[0]}" || return $?
1948 local prim_nid=$($LCTL list_nids | head -n 1)
1950 do_lnetctl discover $prim_nid ||
1951 error "failed to discover myself"
1953 # Set recovery limit to 10 seconds.
1954 do_lnetctl set recovery_limit 10 ||
1955 error "failed to set recovery_limit"
1957 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1958 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1960 # Set health to 0 on one interface. This forces it onto the recovery
1962 $LNETCTL peer set --nid $prim_nid --health 0
1964 # After 5 seconds, we expect the peer NI to still be in recovery
1966 check_nid_in_recovq "-p" 1
1967 check_ping_count "peer_ni" "2"
1969 # After 15 seconds, the peer NI should have been fully processed out of
1970 # the recovery queue. We'll allow a total of 17 seconds to account for
1971 # differences in sleeping for whole seconds vs. the more accurate time
1972 # keeping that is done in the recovery code.
1974 check_nid_in_recovq "-p" 0
1975 check_ping_count "peer_ni" "4"
1977 $LCTL net_drop_del -a
1979 # Set health to force it back onto the recovery queue. Set to 500 means
1980 # in 5 seconds it should be back at maximum value. We'll wait a couple
1981 # more seconds than that to be safe.
1982 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1984 do_lnetctl set recovery_limit 0 ||
1985 error "failed to set recovery_limit"
1987 $LNETCTL peer set --nid $prim_nid --health 500
1989 check_nid_in_recovq "-p" 1
1990 check_ping_count "peer_ni" "2"
1994 check_nid_in_recovq "-p" 0
1995 check_ping_count "peer_ni" "0"
1999 run_test 211 "Remote NI recovery checks"
2002 local rnodes=$(remote_nodes_list)
2003 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
2005 cleanup_lnet || error "Failed to cleanup before test execution"
2007 # Loading modules should configure LNet with the appropriate
2008 # test-framework configuration
2009 load_modules || error "Failed to load modules"
2011 local my_nid=$($LCTL list_nids | head -n 1)
2013 error "Failed to get primary NID for local host $HOSTNAME"
2015 local rnode=$(awk '{print $1}' <<<$rnodes)
2016 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2019 if [[ -z $rnodenids ]]; then
2020 do_rpc_nodes $rnode load_modules_local
2022 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2025 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
2027 [[ -z $rnodepnid ]] &&
2028 error "Failed to get primary NID for remote host $rnode"
2030 log "Initial discovery"
2031 do_lnetctl discover --force $rnodepnid ||
2032 error "Failed to discover $rnodepnid"
2034 do_node $rnode "$LNETCTL discover --force $my_nid" ||
2035 error "$rnode failed to discover $my_nid"
2037 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2038 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2039 do_lnetctl discover --force $rnodepnid &&
2040 error "Discovery should have failed"
2041 $LCTL net_drop_del -a
2044 for nid in $rnodenids; do
2045 # We need GET (PING) delay just long enough so we can trigger
2046 # discovery on the remote peer
2047 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2048 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2049 # We need PUT (PUSH) delay just long enough so we can process
2051 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2054 log "Force $HOSTNAME to discover $rnodepnid (in background)"
2055 # We want to get a PING sent that we know will eventually fail.
2056 # The delay rules we added will ensure the ping is not sent until
2057 # the PUSH is also in flight (see below), and the drop rule ensures that
2058 # when the PING is eventually sent it will error out
2059 do_lnetctl discover --force $rnodepnid &
2062 # We want a discovery PUSH from rnode to put rnode back on our
2063 # discovery queue. This should cause us to try and send a PUSH to rnode
2064 # while the PING is still outstanding.
2065 log "Force $rnode to discover $my_nid"
2066 do_node $rnode $LNETCTL discover --force $my_nid
2068 # At this point we'll have both PING_SENT and PUSH_SENT set for the
2069 # rnode peer. Wait for the PING to error out which should terminate the
2070 # discovery process that we backgrounded.
2071 log "Wait for $pid1"
2073 log "Finished wait on $pid1"
2075 # The PING send failure clears the PING_SENT flag and puts the peer back
2076 # on the discovery queue. When discovery thread processes the peer it
2077 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2078 # Discovery will then complete for this peer even though we have an
2080 # When PUSH is actually unlinked it will be forced back onto the
2081 # discovery queue, but we no longer have a ref on the peer. When
2082 # discovery completes again, we'll trip the ASSERT in
2083 # lnet_destroy_peer_locked()
2085 # Delete the delay rules to send the PUSH
2086 $LCTL net_delay_del -a
2087 # Delete the drop rules
2088 $LCTL net_drop_del -a
2091 error "Failed to unload modules"
2093 do_rpc_nodes $rnode unload_modules_local ||
2094 error "Failed to unload modules on $rnode"
2099 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2102 cleanup_netns || error "Failed to cleanup netns before test execution"
2103 cleanup_lnet || error "Failed to unload modules before test execution"
2105 setup_fakeif || error "Failed to add fake IF"
2106 have_interface "$FAKE_IF" ||
2107 error "Expect $FAKE_IF configured but not found"
2109 reinit_dlc || return $?
2111 add_net "tcp" "${INTERFACES[0]}" || return $?
2112 add_net "tcp" "$FAKE_IF" || return $?
2114 local nid1=$(lctl list_nids | head -n 1)
2115 local nid2=$(lctl list_nids | tail --lines 1)
2117 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2118 error "Expect nid1 \"$nid1\" to be preferred"
2120 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2121 error "Expect nid2 \"$nid2\" to be preferred"
2125 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2127 function check_ni_status() {
2131 local status=$($LNETCTL net show |
2133 awk '/status/{print $NF}')
2135 echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2136 if [[ $status != $expect ]]; then
2137 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2144 cleanup_netns || error "Failed to cleanup netns before test execution"
2145 cleanup_lnet || error "Failed to unload modules before test execution"
2147 setup_fakeif || error "Failed to add fake IF"
2148 have_interface "$FAKE_IF" ||
2149 error "Expect $FAKE_IF configured but not found"
2151 reinit_dlc || return $?
2153 add_net "tcp" "${INTERFACES[0]}" || return $?
2154 add_net "tcp" "$FAKE_IF" || return $?
2156 local nid1=$(lctl list_nids | head -n 1)
2157 local nid2=$(lctl list_nids | tail --lines 1)
2159 check_ni_status "0@lo" up
2160 check_ni_status "$nid1" up
2161 check_ni_status "$nid2" up
2163 echo "Set $FAKE_IF down"
2164 echo "ip link set dev $FAKE_IF down"
2165 ip link set dev $FAKE_IF down
2166 check_ni_status "0@lo" up
2167 check_ni_status "$nid1" up
2168 check_ni_status "$nid2" down
2170 run_test 214 "Check local NI status when link is downed"
2176 $LNETCTL net show -v 2 |
2177 egrep -e nid -e $stat |
2179 awk '/'$stat':/{print $NF}'
2184 for nidvar in nid1 nid2; do
2185 for stat in send_count recv_count; do
2186 s=$(get_ni_stat ${!nidvar} $stat)
2187 eval ${nidvar}_pre_${stat}=$s
2194 for nidvar in nid1 nid2; do
2195 for stat in send_count recv_count; do
2196 s=$(get_ni_stat ${!nidvar} $stat)
2197 eval ${nidvar}_post_${stat}=$s
2207 eval pre=\${${nidvar}_pre_${stat}}
2208 eval post=\${${nidvar}_post_${stat}}
2210 echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2212 [[ $pre -ne $post ]]
2216 cleanup_netns || error "Failed to cleanup netns before test execution"
2217 cleanup_lnet || error "Failed to unload modules before test execution"
2219 reinit_dlc || return $?
2221 add_net "tcp1" "${INTERFACES[0]}" || return $?
2222 add_net "tcp2" "${INTERFACES[0]}" || return $?
2224 local nid1=$($LCTL list_nids | head -n 1)
2225 local nid2=$($LCTL list_nids | tail --lines 1)
2227 do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2228 error "Failed to add peer"
2232 for nidvarA in nid1 nid2; do
2235 for nidvarB in nid1 nid2; do
2236 [[ $nidvarA == $nidvarB ]] && continue
2240 echo "$LNETCTL ping $dst x $npings"
2241 for i in $(seq 1 $npings); do
2242 $LNETCTL ping $dst &>/dev/null ||
2243 error "$LNETCTL ping $dst failed"
2248 # No source specified, sends to either NID should cause
2249 # counts to increase across both NIs
2250 for nidvar in nid1 nid2; do
2251 for stat in send_count recv_count; do
2252 ni_stat_changed $nidvar $stat ||
2253 error "$stat unchanged for ${!nidvar}"
2259 echo "$LNETCTL ping --source $src $dst x $npings"
2260 for i in $(seq 1 $npings); do
2261 $LNETCTL ping --source $src $dst &>/dev/null ||
2262 error "$LNETCTL ping --source $src $dst failed"
2267 # src nid == dest nid means stats for the _other_ NI
2268 # should be unchanged
2269 for nidvar in nid1 nid2; do
2270 for stat in send_count recv_count; do
2271 if [[ ${!nidvar} == $src ]]; then
2272 ni_stat_changed $nidvar $stat ||
2273 error "$stat unchanged for ${!nidvar}"
2275 ni_stat_changed $nidvar $stat &&
2276 error "$stat changed for ${!nidvar}"
2281 # Double number of pings for next iteration because the net
2282 # sequence numbers will have diverged
2283 npings=$(($npings * 2))
2286 # Ping from nid1 to nid2 should fail
2287 do_lnetctl ping --source $nid1 $nid2 &&
2288 error "ping from $nid1 to $nid2 should fail"
2290 # Ping from nid2 to nid1 should fail
2291 do_lnetctl ping --source $nid2 $nid1 &&
2292 error "ping from $nid2 to $nid1 should fail"
2296 run_test 215 "Test lnetctl ping --source option"
2301 reinit_dlc || return $?
2303 add_net "tcp" "${INTERFACES[0]}" || return $?
2304 add_net "tcp1" "${INTERFACES[0]}" || return $?
2306 local nids=( $($LCTL list_nids | xargs echo) )
2308 do_lnetctl discover ${nids[0]} ||
2309 error "Initial discovery failed"
2311 do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2312 error "Initial ping failed $?"
2314 do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2315 error "Initial ping failed $?"
2318 for src in ${nids[@]}; do
2319 for dst in ${nids[@]}; do
2320 $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2324 do_lnetctl ping ${nids[0]} || rc=$?
2326 $LCTL net_drop_del -a
2329 error "expected ping to fail"
2331 check_nid_in_recovq "-p" 0
2332 check_nid_in_recovq "-l" 1
2336 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2339 reinit_dlc || return $?
2341 [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2342 error "Unexpected number of NIs after initalizing DLC"
2344 do_lnetctl discover 0@lo ||
2345 error "Failed to discover 0@lo"
2349 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2353 echo "Check valid values; Should succeed"
2357 for ((i = 4; i < 16; i+=1)); do
2358 reinit_dlc || return $?
2359 add_net "tcp" "${INTERFACES[0]}" || return $?
2360 do_lnetctl net set --all --conns-per-peer $i ||
2361 error "should have succeeded $?"
2362 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2363 error "failed to set conns-per-peer to $i"
2364 lnid="$(lctl list_nids | head -n 1)"
2365 do_lnetctl ping "$lnid" ||
2366 error "failed to ping myself"
2368 # "lctl --net tcp conn_list" prints the list of active
2369 # connections. Since we're pinging ourselves, there should be
2370 # 2 Control connections plus 2*conns_per_peer connections
2371 # created (one Bulk Input, one Bulk Output in each pair).
2372 # Here's the sample output for conns_per_peer set to 1:
2373 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2374 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2375 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2376 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2377 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2379 # Expect 2+conns_per_peer*2 connections. Wait no longer
2381 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2382 error "expected number of tcp connections $((2+i*2))"
2385 reinit_dlc || return $?
2386 add_net "tcp" "${INTERFACES[0]}" || return $?
2387 echo "Set > 127; Should fail"
2388 do_lnetctl net set --all --conns-per-peer 128 &&
2389 error "should have failed $?"
2391 reinit_dlc || return $?
2392 add_net "tcp" "${INTERFACES[0]}" || return $?
2393 echo "Set < 0; Should be ignored"
2394 do_lnetctl net set --all --conns-per-peer -1 ||
2395 error "should have succeeded $?"
2396 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2397 error "Did not stay at default"
2399 run_test 230 "Test setting conns-per-peer"
2401 ### Test that linux route is added for each ni
2403 reinit_dlc || return $?
2404 add_net "tcp" "${INTERFACES[0]}" || return $?
2405 ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
2407 run_test 250 "test that linux routes are added"
2412 local out=$TMP/$tfile
2413 local prefix=/usr/include/linux/lnet
2415 # We use a hard coded prefix so that this test will not fail
2418 if ! which $CC > /dev/null 2>&1; then
2419 skip_env "$CC is not installed"
2422 cleanup_lnet || exit 1
2425 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2426 if ! [[ -d $prefix ]]; then
2427 # Assume we're running in tree and fixup the include path.
2428 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2429 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2432 for header in $prefix/*.h; do
2433 if ! [[ -f "$header" ]]; then
2437 echo "$CC $cc_args -include $header"
2438 $CC $cc_args -include $header ||
2439 error "cannot compile '$header'"
2443 run_test 300 "packaged LNet UAPI headers can be compiled"