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 test ARM testing until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17 # bug number for skipped test: LU-13704 LU-13701 LU-13701 LU-13701
18 ALWAYS_EXCEPT+=" 204 205 206 207 "
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 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
35 [ ! -f "$LNETCTL" ] &&
36 export LNETCTL=$(which lnetctl 2> /dev/null)
37 [[ -z $LNETCTL ]] && skip "Need lnetctl"
41 if is_mounted $MOUNT || is_mounted $MOUNT2; then
42 cleanupall || error "Failed cleanup prior to test execution"
47 echo "Cleaning up LNet"
48 lsmod | grep -q lnet &&
49 $LNETCTL lnet unconfigure 2>/dev/null
54 if module_loaded lnet ; then
55 cleanup_lnet || error "Failed to unload modules before test execution"
61 rm -f $TMP/sanity-dlc*
64 if $restore_mounts; then
65 setupall || error "Failed to setup Lustre after test execution"
66 elif $restore_modules; then
68 error "Couldn't load modules after test execution"
74 load_module ../libcfs/libcfs/libcfs
75 # Prevent local MODOPTS_LIBCFS being passed as part of environment
76 # variable to remote nodes
79 set_default_debug "neterror net nettrace malloc"
80 load_module ../lnet/lnet/lnet "$@"
82 LNDPATH=${LNDPATH:-"../lnet/klnds"}
83 if [ -z "$LNETLND" ]; then
85 o2ib*) LNETLND="o2iblnd/ko2iblnd" ;;
86 tcp*) LNETLND="socklnd/ksocklnd" ;;
87 *) local lnd="${NETTYPE%%[0-9]}lnd"
88 [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
89 LNETLND="$lnd/k$lnd" ||
90 LNETLND="socklnd/ksocklnd"
93 load_module ../lnet/klnds/$LNETLND
105 echo "ip netns exec $TESTNS $@"
106 ip netns exec $TESTNS "$@"
114 netns_arg="netns $netns"
116 ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
117 ip link set 'test1pl' up
118 if [[ -n $netns ]]; then
119 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
120 do_ns ip link set $FAKE_IF up
122 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
123 ip link set $FAKE_IF up
128 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
139 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
144 echo "Loading LNet and configuring DLC"
146 do_lnetctl lnet configure
149 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
150 define_global_yaml() {
151 $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
152 error "Failed to export global yaml $?"
156 if lsmod | grep -q lnet; then
157 do_lnetctl lnet unconfigure ||
158 error "lnetctl lnet unconfigure failed $?"
159 do_lnetctl lnet configure ||
160 error "lnetctl lnet configure failed $?"
162 configure_dlc || error "configure_dlc failed $?"
167 append_global_yaml() {
168 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
169 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
171 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
174 create_base_yaml_file() {
178 compare_yaml_files() {
179 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
180 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
182 ! [[ -e $expected ]] && echo "$expected not found" && return 1
183 ! [[ -e $actual ]] && echo "$actual not found" && return 1
184 diff -upN ${actual} ${expected} || rc=$?
194 local net="${nid//*@/}"
195 local addr="${nid//@*/}"
197 local num_re='[0-9]\+'
198 local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
200 if [[ $net =~ gni[0-9]* ]]; then
201 [[ $addr =~ ${num_re} ]] && return 0
203 [[ $addr =~ ${ip_re} ]] && return 0
208 local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
209 local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
210 local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
211 local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
214 for nid in $primary_nids $secondary_nids; do
215 validate_nid "$nid" || error "Bad NID \"${nid}\""
220 validate_peer_nids() {
222 local nids_per_peer="$2"
224 local expect_p="$num_peers"
225 # The primary nid also shows up in the list of secondary nids
226 local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
228 local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
229 local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
230 if [[ $expect_p -ne $actual_p ]]; then
232 error "Expected $expect_p but found $actual_p primary nids"
233 elif [[ $expect_s -ne $actual_s ]]; then
235 error "Expected $expect_s but found $actual_s secondary nids"
240 validate_gateway_nids() {
241 local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
242 local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
243 if [[ $expect_gw -ne $actual_gw ]]; then
245 error "Expected $expect_gw gateways but found $actual_gw gateways"
251 setup_netns || error "setup_netns failed with $?"
253 stack_trap 'cleanup_testsuite' EXIT
256 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
257 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
259 reinit_dlc || return $?
260 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
261 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
262 create_base_yaml_file
263 compare_yaml_files || error "Configuration changed after import"
265 run_test 0 "Export empty config, import the config, compare"
268 local prim_nid="${1:+--prim_nid $1}"
269 local nid="${2:+--nid $2}"
271 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
273 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
274 $LNETCTL export --backup > $actual || error "export failed $?"
280 reinit_dlc || return $?
281 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
283 - primary nid: 1.1.1.1@tcp
289 compare_peer_add "1.1.1.1@tcp"
291 run_test 1 "Add peer with single nid (tcp)"
294 reinit_dlc || return $?
295 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
297 - primary nid: 2.2.2.2@o2ib
303 compare_peer_add "2.2.2.2@o2ib"
305 run_test 2 "Add peer with single nid (o2ib)"
308 reinit_dlc || return $?
309 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
311 - primary nid: 3.3.3.3@tcp
318 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
320 run_test 3 "Add peer with tcp primary o2ib secondary"
323 reinit_dlc || return $?
324 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
326 - primary nid: 4.4.4.4@tcp
335 echo "Add peer with nidrange (tcp)"
336 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
338 echo "Add peer with nidrange that overlaps primary nid (tcp)"
339 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
341 run_test 4 "Add peer with nidrange (tcp)"
344 reinit_dlc || return $?
345 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
347 - primary nid: 5.5.5.5@o2ib
357 echo "Add peer with nidrange (o2ib)"
358 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
360 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
361 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
363 run_test 5 "Add peer with nidrange (o2ib)"
366 reinit_dlc || return $?
367 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
369 - primary nid: 6.6.6.6@tcp
389 compare_peer_add "6.6.6.6@tcp" \
390 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
392 run_test 6 "Add peer with multiple nidranges"
395 local prim_nid="${1:+--prim_nid $1}"
396 local nid="${2:+--nid $2}"
398 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
400 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
401 $LNETCTL export --backup > $actual || error "export failed $?"
407 reinit_dlc || return $?
408 create_base_yaml_file
410 echo "Delete peer with single nid (tcp)"
411 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
412 compare_peer_del "7.7.7.7@tcp"
414 echo "Delete peer with single nid (o2ib)"
415 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
416 compare_peer_del "7.7.7.7@o2ib"
418 echo "Delete peer that has multiple nids (tcp)"
419 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
420 error "Peer add failed $?"
421 compare_peer_del "7.7.7.7@tcp"
423 echo "Delete peer that has multiple nids (o2ib)"
424 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
425 error "Peer add failed $?"
426 compare_peer_del "7.7.7.7@o2ib"
428 echo "Delete peer that has both tcp and o2ib nids"
429 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
430 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
431 error "Peer add failed $?"
432 compare_peer_del "7.7.7.7@tcp"
434 echo "Delete peer with single nid (gni)"
435 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
436 compare_peer_del "7@gni"
438 echo "Delete peer that has multiple nids (gni)"
439 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
440 error "Peer add failed $?"
441 compare_peer_del "7@gni"
443 echo "Delete peer that has tcp, o2ib and gni nids"
444 do_lnetctl peer add --prim_nid 7@gni \
445 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
446 error "Peer add failed $?"
447 compare_peer_del "7@gni"
449 run_test 7 "Various peer delete tests"
452 reinit_dlc || return $?
454 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
456 - primary nid: 8.8.8.8@tcp
468 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
469 error "Peer add failed $?"
470 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
472 run_test 8 "Delete single secondary nid from peer (tcp)"
475 reinit_dlc || return $?
477 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
479 - primary nid: 9.9.9.9@tcp
486 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
487 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
488 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
490 run_test 9 "Delete all secondary nids from peer (tcp)"
493 reinit_dlc || return $?
495 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
497 - primary nid: 10.10.10.10@tcp
500 - nid: 10.10.10.10@tcp
501 - nid: 10.10.10.12@tcp
502 - nid: 10.10.10.13@tcp
503 - nid: 10.10.10.15@tcp
504 - nid: 10.10.10.16@tcp
507 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
508 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
509 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
511 run_test 10 "Delete single secondary nid from peer (o2ib)"
514 reinit_dlc || return $?
516 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
518 - primary nid: 11.11.11.11@tcp
521 - nid: 11.11.11.11@tcp
524 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
525 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
526 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
528 run_test 11 "Delete all secondary nids from peer (o2ib)"
531 reinit_dlc || return $?
533 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
535 - primary nid: 12.12.12.12@o2ib
538 - nid: 12.12.12.12@o2ib
539 - nid: 13.13.13.13@o2ib
540 - nid: 14.13.13.13@o2ib
541 - nid: 14.15.13.13@o2ib
543 - nid: 15.17.1.10@tcp
544 - nid: 15.17.1.20@tcp
547 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
548 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
549 error "Peer add failed $?"
550 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
552 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
555 reinit_dlc || return $?
557 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
559 - primary nid: 13.13.13.13@o2ib
562 - nid: 13.13.13.13@o2ib
565 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
566 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
567 error "Peer add failed $?"
568 compare_peer_del "13.13.13.13@o2ib" \
569 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
571 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
577 if [[ $net =~ gni* ]]; then
580 echo "${num}.${num}.${num}.${num}@${net}"
584 create_mr_peer_yaml() {
586 local secondary_nids="$2"
589 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
590 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
592 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
595 while [[ $created -lt $num_peers ]]; do
596 local primary=$(create_nid ${nidnum} ${net})
597 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
598 - primary nid: $primary
604 local start=$((nidnum + 1))
605 local end=$((nidnum + $secondary_nids))
606 for j in $(seq ${start} ${end}); do
607 local nid=$(create_nid $j ${net})
608 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
616 reinit_dlc || return $?
618 echo "Create single peer, single nid, using import"
619 create_mr_peer_yaml 1 0 tcp
620 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
621 error "Import failed $?"
623 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
626 echo "Delete single peer using import --del"
627 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
628 error "Import failed $?"
629 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
630 create_base_yaml_file
631 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
634 run_test 14 "import peer create/delete with single nid"
637 reinit_dlc || return $?
639 echo "Create multiple peers, single nid per peer, using import"
640 create_mr_peer_yaml 5 0 o2ib
641 # The ordering of nids for this use-case is non-deterministic, so we
642 # we can't just diff the expected/actual output.
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 5 0
648 echo "Delete multiple peers, single nid per peer, 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 15 "import multi peer create/delete with single nid per peer"
659 reinit_dlc || return $?
661 echo "Create single peer, multiple nids, using import"
662 create_mr_peer_yaml 1 5 tcp
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 1 5
668 echo "Delete single peer, multiple nids, 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 16 "import peer create/delete with multiple nids"
679 reinit_dlc || return $?
681 echo "Create multiple peers, multiple nids per peer, using import"
682 create_mr_peer_yaml 5 7 o2ib
683 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
684 error "Import failed $?"
685 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
686 validate_peer_nids 5 7
688 echo "Delete multiple peers, multiple nids per peer, using import --del"
689 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
690 error "Import failed $?"
691 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
692 create_base_yaml_file
693 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
696 run_test 17 "import multi peer create/delete with multiple nids"
699 reinit_dlc || return $?
701 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
703 - primary nid: 1.1.1.1@tcp
712 echo "Import peer with 5 nids"
713 cat $TMP/sanity-lnet-$testnum-expected.yaml
714 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
715 error "Import failed $?"
716 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
718 - primary nid: 1.1.1.1@tcp
725 echo "Delete three of the nids"
726 cat $TMP/sanity-lnet-$testnum-expected.yaml
727 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
728 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
730 - primary nid: 1.1.1.1@tcp
736 echo "Check peer has expected nids remaining"
737 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
741 run_test 18a "Delete a subset of nids from a single peer using import --del"
744 reinit_dlc || return $?
746 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
748 - primary nid: 1.1.1.1@tcp
756 - primary nid: 6.6.6.6@o2ib
765 echo "Import two peers with 5 nids each"
766 cat $TMP/sanity-lnet-$testnum-expected.yaml
767 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
768 error "Import failed $?"
769 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
771 - primary nid: 1.1.1.1@tcp
777 - primary nid: 6.6.6.6@o2ib
784 echo "Delete three of the nids from each peer"
785 cat $TMP/sanity-lnet-$testnum-expected.yaml
786 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
787 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
789 - primary nid: 6.6.6.6@o2ib
794 - primary nid: 1.1.1.1@tcp
801 echo "Check peers have expected nids remaining"
802 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
804 validate_peer_nids 2 1
806 run_test 18b "Delete multiple nids from multiple peers using import --del"
809 reinit_dlc || return $?
810 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
812 - primary nid: 19@gni
818 compare_peer_add "19@gni"
820 run_test 19 "Add peer with single nid (gni)"
823 reinit_dlc || return $?
824 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
826 - primary nid: 20@gni
830 - nid: 20.20.20.20@tcp
831 - nid: 20.20.20.20@o2ib
834 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
836 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
839 reinit_dlc || return $?
840 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
842 - primary nid: 21@gni
852 echo"Add peer with nidrange (gni)"
853 compare_peer_add "21@gni" "[22-25]@gni" || error
854 echo "Add peer with nidrange that overlaps primary nid (gni)"
855 compare_peer_add "21@gni" "[21-25]@gni"
857 run_test 21 "Add peer with nidrange (gni)"
860 reinit_dlc || return $?
861 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
863 - primary nid: 22@gni
874 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
875 error "Peer add failed $?"
876 compare_peer_del "22@gni" "26@gni"
878 run_test 22 "Delete single secondary nid from peer (gni)"
881 reinit_dlc || return $?
882 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
884 - primary nid: 23@gni
891 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
892 error "Peer add failed $?"
893 compare_peer_del "23@gni" "[25-29]@gni"
895 run_test 23 "Delete all secondary nids from peer (gni)"
898 reinit_dlc || return $?
899 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
901 - primary nid: 24@gni
906 - nid: 13.13.13.13@o2ib
907 - nid: 14.13.13.13@o2ib
908 - nid: 14.15.13.13@o2ib
910 - nid: 15.17.1.10@tcp
911 - nid: 15.17.1.20@tcp
914 do_lnetctl peer add --prim_nid 24@gni \
915 --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 ||
916 error "Peer add failed $?"
917 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
919 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
922 reinit_dlc || return $?
923 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
925 - primary nid: 25@gni
931 do_lnetctl peer add --prim_nid 25@gni \
932 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
933 error "Peer add failed $?"
934 compare_peer_del "25@gni" \
935 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
937 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
940 reinit_dlc || return $?
942 echo "Invalid prim_nid - peer add"
943 do_lnetctl peer add --prim_nid foobar &&
944 error "Command should have failed"
946 echo "Invalid prim_nid - peer del"
947 do_lnetctl peer del --prim_nid foobar &&
948 error "Command should have failed"
950 echo "Delete non-existing peer"
951 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
952 error "Command should have failed"
954 echo "Don't provide mandatory arguments peer del"
955 do_lnetctl peer del --nid 1.1.1.1@tcp &&
956 error "Command should have failed"
958 echo "Don't provide mandatory arguments peer add"
959 do_lnetctl peer add &&
960 error "Command should have failed"
962 echo "Invalid secondary nids"
963 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
964 error "Command should have failed"
966 echo "Exceed max nids per peer"
967 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
968 error "Command should have failed"
970 echo "Invalid net type"
971 do_lnetctl peer add --prim_nid 1@foo &&
972 error "Command should have failed"
974 echo "Invalid nid format"
975 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
978 for nid in ${invalid_nids}; do
979 echo "Check invalid primary nid - '$nid'"
980 do_lnetctl peer add --prim_nid $nid &&
981 error "Command should have failed"
984 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
985 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
986 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
989 for nidstr in ${invalid_strs}; do
990 echo "Check invalid nidstring - '$nidstr'"
991 do_lnetctl peer add --nid $nidstr &&
992 error "Command should have failed"
995 echo "Add non-local gateway"
996 do_lnetctl route add --net tcp --gateway 1@gni &&
997 error "Command should have failed"
1001 run_test 99a "Check various invalid inputs to lnetctl peer"
1004 reinit_dlc || return $?
1006 create_base_yaml_file
1008 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1010 - primary nid: 99.99.99.99@tcp
1013 - nid: 99.99.99.99@tcp
1015 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1016 error "import should have failed"
1017 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1020 run_test 99b "Invalid value for Multi-Rail in yaml import"
1024 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1032 if ! lsmod | grep -q ksocklnd ; then
1033 load_module ../lnet/klnds/socklnd/ksocklnd ||
1034 error "Can't load ksocklnd.ko"
1037 do_lnetctl net add --net ${net} --if ${if} ||
1038 error "Failed to add net ${net} on if ${if}"
1041 compare_route_add() {
1045 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1047 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1048 error "route add failed $?"
1049 # CPT configuration is pruned from the exported yaml, since the default
1050 # can vary across test systems (unlike default values for things like
1051 # peer_credits, peer_timeout, etc.)
1052 $LNETCTL export --backup | grep -v CPT > $actual ||
1053 error "export failed $?"
1054 validate_gateway_nids
1059 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1060 reinit_dlc || return $?
1061 add_net "tcp" "eth0"
1062 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1071 peer_buffer_credits: 0
1075 gateway: 7.7.7.7@tcp
1078 health_sensitivity: 1
1080 - primary nid: 7.7.7.7@tcp
1086 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1089 run_test 100 "Add route with single gw (tcp)"
1092 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1093 reinit_dlc || return $?
1094 add_net "tcp" "eth0"
1095 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1104 peer_buffer_credits: 0
1108 gateway: 8.8.8.10@tcp
1111 health_sensitivity: 1
1113 gateway: 8.8.8.9@tcp
1116 health_sensitivity: 1
1118 gateway: 8.8.8.8@tcp
1121 health_sensitivity: 1
1123 - primary nid: 8.8.8.9@tcp
1127 - primary nid: 8.8.8.10@tcp
1131 - primary nid: 8.8.8.8@tcp
1137 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1139 run_test 101 "Add route with multiple gw (tcp)"
1141 compare_route_del() {
1145 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1147 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1148 error "route del failed $?"
1149 $LNETCTL export --backup > $actual ||
1150 error "export failed $?"
1151 validate_gateway_nids
1155 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1156 reinit_dlc || return $?
1157 add_net "tcp" "eth0"
1158 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1159 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1160 error "route add failed $?"
1161 compare_route_del "tcp102" "102.102.102.102@tcp"
1163 run_test 102 "Delete route with single gw (tcp)"
1166 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1167 reinit_dlc || return $?
1168 add_net "tcp" "eth0"
1169 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1170 do_lnetctl route add --net tcp103 \
1171 --gateway 103.103.103.[103-120/4]@tcp ||
1172 error "route add failed $?"
1173 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1175 run_test 103 "Delete route with multiple gw (tcp)"
1177 ### load lnet in default namespace, configure in target namespace
1180 cleanup_lnet || exit 1
1181 load_lnet "networks=\"\""
1182 do_ns $LNETCTL lnet configure --all || exit 1
1183 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1185 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1188 cleanup_lnet || exit 1
1189 load_lnet "networks=tcp($FAKE_IF)"
1190 do_ns $LNETCTL lnet configure --all || exit 1
1191 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1193 run_test 201 "load lnet using networks module options in a non-default namespace"
1196 cleanup_lnet || exit 1
1197 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1198 do_ns $LNETCTL lnet configure --all || exit 1
1199 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1201 run_test 202 "load lnet using ip2nets in a non-default namespace"
1204 ### Add the interfaces in the target namespace
1207 cleanup_lnet || exit 1
1209 do_lnetctl lnet configure || exit 1
1210 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1212 run_test 203 "add a network using an interface in the non-default namespace"
1214 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1215 function save_lnet_params() {
1216 $LNETCTL global show | egrep -v '^global:$' |
1217 sed 's/://' > $LNET_PARAMS_FILE
1220 function restore_lnet_params() {
1222 while read param value; do
1223 [[ $param == max_intf ]] && continue
1224 [[ $param == lnd_timeout ]] && continue
1225 $LNETCTL set ${param} ${value} ||
1226 error "Failed to restore ${param} to ${value}"
1227 done < $LNET_PARAMS_FILE
1230 function lnet_health_pre() {
1233 # Lower transaction timeout to speed up test execution
1234 $LNETCTL set transaction_timeout 10 ||
1235 error "Failed to set transaction_timeout $?"
1237 # Increase recovery interval so we have time to capture health values
1238 $LNETCTL set recovery_interval 20 ||
1239 error "Failed to set recovery_interval $?"
1241 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1242 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1243 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1244 xargs echo | sed 's/ /+/g' | bc -l)
1246 local my_nid=$($LCTL list_nids | head -n 1)
1248 RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1249 awk '/health value/{print $NF}' | xargs echo |
1250 sed 's/ /+/g' | bc -l)
1252 # Might not have any peers so initialize to zero.
1253 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1258 function lnet_health_post() {
1259 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1260 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1261 awk '/health value/{print $NF}' |
1262 xargs echo | sed 's/ /+/g' | bc -l)
1264 local my_nid=$($LCTL list_nids | head -n 1)
1266 RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1267 awk '/health value/{print $NF}' | xargs echo |
1268 sed 's/ /+/g' | bc -l)
1270 # Might not have any peers so initialize to zero.
1271 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1274 echo "Pre resends: $RSND_PRE" &&
1275 echo "Post resends: $RSND_POST" &&
1276 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1277 echo "Pre local health: $LO_HVAL_PRE" &&
1278 echo "Post local health: $LO_HVAL_POST" &&
1279 echo "Pre remote health: $RMT_HVAL_PRE" &&
1280 echo "Post remote health: $RMT_HVAL_POST"
1287 function check_no_resends() {
1288 echo "Check that no resends took place"
1289 [[ $RSND_POST -ne $RSND_PRE ]] &&
1290 error "Found resends: $RSND_POST != $RSND_PRE"
1295 function check_resends() {
1296 local delta=$((RSND_POST - RSND_PRE))
1298 echo "Check that $RETRY_PARAM resends took place"
1299 [[ $delta -ne $RETRY_PARAM ]] &&
1300 error "Expected $RETRY_PARAM resends found $delta"
1305 function check_no_local_health() {
1306 echo "Check that local NI health is unchanged"
1307 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1308 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1313 function check_local_health() {
1314 echo "Check that local NI health has been changed"
1315 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1316 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1321 function check_no_remote_health() {
1322 echo "Check that remote NI health is unchanged"
1323 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1324 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1329 function check_remote_health() {
1330 echo "Check that remote NI health has been changed"
1331 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1332 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1337 # See lnet/lnet/lib-msg.c:lnet_health_check()
1338 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1339 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1340 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1342 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1343 reinit_dlc || return $?
1344 add_net "tcp" "eth0" || return $?
1346 lnet_health_pre || return $?
1349 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1350 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1351 echo "Simulate $hstatus"
1352 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1353 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1354 error "Should have failed"
1355 $LCTL net_drop_del *
1360 check_no_resends || return $?
1361 check_no_local_health || return $?
1365 run_test 204 "Check no health or resends for single-rail local failures"
1368 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1371 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1372 reinit_dlc || return $?
1373 add_net "tcp" "eth0" || return $?
1374 add_net "tcp1" "eth0" || return $?
1376 echo "Simulate $hstatus"
1379 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1380 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1381 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1382 error "Should have failed"
1383 $LCTL net_drop_del *
1387 check_resends || return $?
1388 check_local_health || return $?
1391 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1392 reinit_dlc || return $?
1393 add_net "tcp" "eth0" || return $?
1394 add_net "tcp1" "eth0" || return $?
1396 echo "Simulate $hstatus"
1397 lnet_health_pre || return $?
1399 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1400 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1401 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1402 error "Should have failed"
1403 $LCTL net_drop_del *
1407 check_no_resends || return $?
1408 check_local_health || return $?
1413 run_test 205 "Check health and resends for multi-rail local failures"
1415 # See lnet/lnet/lib-msg.c:lnet_health_check()
1416 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1417 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout network_timeout"
1419 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1420 reinit_dlc || return $?
1421 add_net "tcp" "eth0" || return $?
1423 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1424 error "failed to discover myself"
1426 lnet_health_pre || return $?
1429 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1430 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1431 echo "Simulate $hstatus"
1432 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1433 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1434 error "Should have failed"
1435 $LCTL net_drop_del *
1440 check_no_resends || return $?
1441 check_no_local_health || return $?
1442 check_no_remote_health || return $?
1446 run_test 206 "Check no health or resends for single-rail remote failures"
1449 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1452 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1453 reinit_dlc || return $?
1454 add_net "tcp" "eth0" || return $?
1455 add_net "tcp1" "eth0" || return $?
1457 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1458 error "failed to discover myself"
1460 echo "Simulate $hstatus"
1461 lnet_health_pre || return $?
1462 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1463 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1464 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1465 error "Should have failed"
1466 $LCTL net_drop_del *
1470 check_resends || return $?
1471 check_no_local_health || return $?
1472 check_remote_health || return $?
1474 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1475 reinit_dlc || return $?
1476 add_net "tcp" "eth0" || return $?
1477 add_net "tcp1" "eth0" || return $?
1479 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1480 error "failed to discover myself"
1482 echo "Simulate $hstatus"
1483 lnet_health_pre || return $?
1484 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1485 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1486 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1487 error "Should have failed"
1488 $LCTL net_drop_del *
1492 check_no_resends || return $?
1493 check_no_local_health || return $?
1494 check_remote_health || return $?
1499 run_test 207 "Check health and resends for multi-rail remote errors"
1501 test_208_load_and_check_lnet() {
1505 local num_expected=1
1507 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1510 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1516 nids=( $($LCTL list_nids) )
1518 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1519 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1521 [[ ${nids[0]} == ${p_nid} ]] ||
1522 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1524 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1525 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1527 $LCTL net down &>/dev/null
1532 have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1534 cleanup_netns || error "Failed to cleanup netns before test execution"
1535 cleanup_lnet || error "Failed to unload modules before test execution"
1536 setup_fakeif || error "Failed to add fake IF"
1538 have_interface "$FAKE_IF" ||
1539 error "Expect $FAKE_IF configured but not found"
1541 local eth0_ip=$(ip --oneline addr show dev eth0 |
1542 awk '/inet /{print $4}' |
1544 local ip2nets_str="tcp(eth0) $eth0_ip"
1546 echo "Configure single NID \"$ip2nets_str\""
1547 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp"
1549 ip2nets_str="tcp(eth0) $eth0_ip; tcp1($FAKE_IF) $FAKE_IP"
1550 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1551 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1554 ip2nets_str="tcp(eth0) $eth0_ip; tcp($FAKE_IF) $FAKE_IP"
1555 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1556 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1558 local addr1=( ${eth0_ip//./ } )
1559 local addr2=( ${FAKE_IP//./ } )
1560 local range="[${addr1[0]},${addr2[0]}]"
1563 for i in $(seq 1 3); do
1564 range+=".[${addr1[$i]},${addr2[$i]}]"
1566 ip2nets_str="tcp(eth0,${FAKE_IF}) ${range}"
1568 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1569 test_208_load_and_check_lnet "${ip2nets_str}" "${eth0_ip}@tcp" \
1574 echo "alt syntax with missing IF \"$ip2nets_str\""
1575 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1577 echo "$LCTL net up should fail"
1579 error "LNet bringup should have failed"
1583 run_test 208 "Test various kernel ip2nets configurations"
1588 local out=$TMP/$tfile
1589 local prefix=/usr/include/linux/lnet
1591 # We use a hard coded prefix so that this test will not fail
1594 if ! which $CC > /dev/null 2>&1; then
1595 skip_env "$CC is not installed"
1598 cleanup_lnet || exit 1
1601 if ! [[ -d $prefix ]]; then
1602 # Assume we're running in tree and fixup the include path.
1603 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
1606 for header in $prefix/*.h; do
1607 if ! [[ -f "$header" ]]; then
1611 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
1612 error "cannot compile '$header'"
1616 run_test 300 "packaged LNet UAPI headers can be compiled"