Whamcloud - gitweb
4f56596e693048e06be493a0e81dec3eba548d21
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test:
11 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
12 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
16
17 . $LUSTRE/tests/test-framework.sh
18 CLEANUP=${CLEANUP:-:}
19 SETUP=${SETUP:-:}
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 build_test_filter
25
26 export LNETCTL=${LNETCTL:-"$LUSTRE/../lnet/utils/lnetctl"}
27 [ ! -f "$LNETCTL" ] &&
28         export LNETCTL=$(which lnetctl 2> /dev/null)
29 [[ -z $LNETCTL ]] && skip "Need lnetctl"
30
31 restore_mounts=false
32
33 if is_mounted $MOUNT || is_mounted $MOUNT2; then
34         cleanupall || error "Failed cleanup prior to test execution"
35         restore_mounts=true
36 fi
37
38 cleanup_lnet() {
39         echo "Cleaning up LNet"
40         $LNETCTL lnet unconfigure 2>/dev/null
41         unload_modules
42 }
43
44 restore_modules=false
45 if module_loaded lnet ; then
46         cleanup_lnet || error "Failed to unload modules before test execution"
47         restore_modules=true
48 fi
49
50 cleanup_testsuite() {
51         trap "" EXIT
52         rm -f $TMP/sanity-dlc*
53         cleanup_netns
54         cleanup_lnet
55         if $restore_mounts; then
56                 setupall || error "Failed to setup Lustre after test execution"
57         elif $restore_modules; then
58                 load_modules ||
59                         error "Couldn't load modules after test execution"
60         fi
61         return 0
62 }
63
64 load_lnet() {
65         load_module ../libcfs/libcfs/libcfs
66         # Prevent local MODOPTS_LIBCFS being passed as part of environment
67         # variable to remote nodes
68         unset MODOPTS_LIBCFS
69
70         set_default_debug "neterror net nettrace malloc"
71         load_module ../lnet/lnet/lnet "$@"
72
73         LNDPATH=${LNDPATH:-"../lnet/klnds"}
74         if [ -z "$LNETLND" ]; then
75                 case $NETTYPE in
76                 o2ib*)  LNETLND="o2iblnd/ko2iblnd" ;;
77                 tcp*)   LNETLND="socklnd/ksocklnd" ;;
78                 *)      local lnd="${NETTYPE%%[0-9]}lnd"
79                         [ -f "$LNDPATH/$lnd/k$lnd.ko" ] &&
80                                 LNETLND="$lnd/k$lnd" ||
81                                 LNETLND="socklnd/ksocklnd"
82                 esac
83         fi
84         load_module ../lnet/klnds/$LNETLND
85 }
86
87 do_lnetctl() {
88         echo "$LNETCTL $@"
89         $LNETCTL "$@"
90 }
91
92 TESTNS='test_ns'
93 FAKE_IF="test1pg"
94 FAKE_IP="10.1.2.3"
95 do_ns() {
96         echo "ip netns exec $TESTNS $@"
97         ip netns exec $TESTNS "$@"
98 }
99
100 setup_netns() {
101         cleanup_netns
102
103         ip netns add $TESTNS
104         ip link add 'test1pl' type veth peer name $FAKE_IF netns $TESTNS
105         ip link set 'test1pl' up
106         do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
107         do_ns ip link set $FAKE_IF up
108 }
109
110 cleanup_netns() {
111         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
112         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
113 }
114
115 configure_dlc() {
116         echo "Loading LNet and configuring DLC"
117         load_lnet
118         do_lnetctl lnet configure
119 }
120
121 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
122 define_global_yaml() {
123         $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
124                 error "Failed to export global yaml $?"
125 }
126
127 reinit_dlc() {
128         if lsmod | grep -q lnet; then
129                 do_lnetctl lnet unconfigure ||
130                         error "lnetctl lnet unconfigure failed $?"
131                 do_lnetctl lnet configure ||
132                         error "lnetctl lnet configure failed $?"
133         else
134                 configure_dlc || error "configure_dlc failed $?"
135         fi
136         define_global_yaml
137 }
138
139 append_global_yaml() {
140         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
141                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
142
143         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
144 }
145
146 create_base_yaml_file() {
147         append_global_yaml
148 }
149
150 compare_yaml_files() {
151         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
152         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
153         local rc=0
154         ! [[ -e $expected ]] && echo "$expected not found" && return 1
155         ! [[ -e $actual ]] && echo "$actual not found" && return 1
156         diff -upN ${actual} ${expected} || rc=$?
157         echo "Expected:"
158         cat $expected
159         echo "Actual:"
160         cat $actual
161         return $rc
162 }
163
164 validate_nid() {
165         local nid="$1"
166         local net="${nid//*@/}"
167         local addr="${nid//@*/}"
168
169         local num_re='[0-9]\+'
170         local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
171
172         if [[ $net =~ gni[0-9]* ]]; then
173                 [[ $addr =~ ${num_re} ]] && return 0
174         else
175                 [[ $addr =~ ${ip_re} ]] && return 0
176         fi
177 }
178
179 validate_nids() {
180         local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
181         local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
182         local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
183         local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
184
185         local nid
186         for nid in $primary_nids $secondary_nids; do
187                 validate_nid "$nid" || error "Bad NID \"${nid}\""
188         done
189         return 0
190 }
191
192 validate_peer_nids() {
193         local num_peers="$1"
194         local nids_per_peer="$2"
195
196         local expect_p="$num_peers"
197         # The primary nid also shows up in the list of secondary nids
198         local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
199
200         local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
201         local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
202         if [[ $expect_p -ne $actual_p ]]; then
203                 compare_yaml_files
204                 error "Expected $expect_p but found $actual_p primary nids"
205         elif [[ $expect_s -ne $actual_s ]]; then
206                 compare_yaml_files
207                 error "Expected $expect_s but found $actual_s secondary nids"
208         fi
209         validate_nids
210 }
211
212 validate_gateway_nids() {
213         local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
214         local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
215         if [[ $expect_gw -ne $actual_gw ]]; then
216                 compare_yaml_files
217                 error "Expected $expect_gw gateways but found $actual_gw gateways"
218         fi
219         validate_nids
220 }
221
222 cleanupall -f
223 setup_netns || error "setup_netns failed with $?"
224
225 stack_trap 'cleanup_testsuite' EXIT
226
227 test_0() {
228         load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
229         do_lnetctl lnet configure || error "lnet configure failed rc = $?"
230         define_global_yaml
231         reinit_dlc || return $?
232         do_lnetctl import <  ${GLOBAL_YAML_FILE} || error "Import failed $?"
233         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
234         create_base_yaml_file
235         compare_yaml_files || error "Configuration changed after import"
236 }
237 run_test 0 "Export empty config, import the config, compare"
238
239 compare_peer_add() {
240         local prim_nid="${1:+--prim_nid $1}"
241         local nid="${2:+--nid $2}"
242
243         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
244
245         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
246         $LNETCTL export --backup > $actual || error "export failed $?"
247         compare_yaml_files
248         return $?
249 }
250
251 test_1() {
252         reinit_dlc || return $?
253         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
254 peer:
255     - primary nid: 1.1.1.1@tcp
256       Multi-Rail: True
257       peer ni:
258         - nid: 1.1.1.1@tcp
259 EOF
260         append_global_yaml
261         compare_peer_add "1.1.1.1@tcp"
262 }
263 run_test 1 "Add peer with single nid (tcp)"
264
265 test_2() {
266         reinit_dlc || return $?
267         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
268 peer:
269     - primary nid: 2.2.2.2@o2ib
270       Multi-Rail: True
271       peer ni:
272         - nid: 2.2.2.2@o2ib
273 EOF
274         append_global_yaml
275         compare_peer_add "2.2.2.2@o2ib"
276 }
277 run_test 2 "Add peer with single nid (o2ib)"
278
279 test_3() {
280         reinit_dlc || return $?
281         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
282 peer:
283     - primary nid: 3.3.3.3@tcp
284       Multi-Rail: True
285       peer ni:
286         - nid: 3.3.3.3@tcp
287         - nid: 3.3.3.3@o2ib
288 EOF
289         append_global_yaml
290         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
291 }
292 run_test 3 "Add peer with tcp primary o2ib secondary"
293
294 test_4() {
295         reinit_dlc || return $?
296         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
297 peer:
298     - primary nid: 4.4.4.4@tcp
299       Multi-Rail: True
300       peer ni:
301         - nid: 4.4.4.4@tcp
302         - nid: 4.4.4.1@tcp
303         - nid: 4.4.4.2@tcp
304         - nid: 4.4.4.3@tcp
305 EOF
306         append_global_yaml
307         echo "Add peer with nidrange (tcp)"
308         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
309
310         echo "Add peer with nidrange that overlaps primary nid (tcp)"
311         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
312 }
313 run_test 4 "Add peer with nidrange (tcp)"
314
315 test_5() {
316         reinit_dlc || return $?
317         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
318 peer:
319     - primary nid: 5.5.5.5@o2ib
320       Multi-Rail: True
321       peer ni:
322         - nid: 5.5.5.5@o2ib
323         - nid: 5.5.5.1@o2ib
324         - nid: 5.5.5.2@o2ib
325         - nid: 5.5.5.3@o2ib
326         - nid: 5.5.5.4@o2ib
327 EOF
328         append_global_yaml
329         echo "Add peer with nidrange (o2ib)"
330         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
331
332         echo "Add peer with nidranage that overlaps primary nid (o2ib)"
333         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
334 }
335 run_test 5 "Add peer with nidrange (o2ib)"
336
337 test_6() {
338         reinit_dlc || return $?
339         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
340 peer:
341     - primary nid: 6.6.6.6@tcp
342       Multi-Rail: True
343       peer ni:
344         - nid: 6.6.6.6@tcp
345         - nid: 6.6.6.0@tcp
346         - nid: 6.6.6.2@tcp
347         - nid: 6.6.6.4@tcp
348         - nid: 6.6.7.0@tcp
349         - nid: 6.6.7.2@tcp
350         - nid: 6.6.7.4@tcp
351         - nid: 6.6.1.0@o2ib
352         - nid: 6.6.1.3@o2ib
353         - nid: 6.6.1.6@o2ib
354         - nid: 6.6.3.0@o2ib
355         - nid: 6.6.3.3@o2ib
356         - nid: 6.6.3.6@o2ib
357         - nid: 6@gni
358         - nid: 10@gni
359 EOF
360         append_global_yaml
361         compare_peer_add "6.6.6.6@tcp" \
362                 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
363 }
364 run_test 6 "Add peer with multiple nidranges"
365
366 compare_peer_del() {
367         local prim_nid="${1:+--prim_nid $1}"
368         local nid="${2:+--nid $2}"
369
370         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
371
372         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
373         $LNETCTL export --backup > $actual || error "export failed $?"
374         compare_yaml_files
375         return $?
376 }
377
378 test_7() {
379         reinit_dlc || return $?
380         create_base_yaml_file
381
382         echo "Delete peer with single nid (tcp)"
383         do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
384         compare_peer_del "7.7.7.7@tcp"
385
386         echo "Delete peer with single nid (o2ib)"
387         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
388         compare_peer_del "7.7.7.7@o2ib"
389
390         echo "Delete peer that has multiple nids (tcp)"
391         do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
392                 error "Peer add failed $?"
393         compare_peer_del "7.7.7.7@tcp"
394
395         echo "Delete peer that has multiple nids (o2ib)"
396         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
397                 error "Peer add failed $?"
398         compare_peer_del "7.7.7.7@o2ib"
399
400         echo "Delete peer that has both tcp and o2ib nids"
401         do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
402                 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
403                 error "Peer add failed $?"
404         compare_peer_del "7.7.7.7@tcp"
405
406         echo "Delete peer with single nid (gni)"
407         do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
408         compare_peer_del "7@gni"
409
410         echo "Delete peer that has multiple nids (gni)"
411         do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
412                 error "Peer add failed $?"
413         compare_peer_del "7@gni"
414
415         echo "Delete peer that has tcp, o2ib and gni nids"
416         do_lnetctl peer add --prim_nid 7@gni \
417                 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
418                 error "Peer add failed $?"
419         compare_peer_del "7@gni"
420 }
421 run_test 7 "Various peer delete tests"
422
423 test_8() {
424         reinit_dlc || return $?
425
426         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
427 peer:
428     - primary nid: 8.8.8.8@tcp
429       Multi-Rail: True
430       peer ni:
431         - nid: 8.8.8.8@tcp
432         - nid: 8.8.8.10@tcp
433         - nid: 8.8.8.11@tcp
434         - nid: 8.8.8.12@tcp
435         - nid: 8.8.8.14@tcp
436         - nid: 8.8.8.15@tcp
437 EOF
438         append_global_yaml
439
440         do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
441                 error "Peer add failed $?"
442         compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
443 }
444 run_test 8 "Delete single secondary nid from peer (tcp)"
445
446 test_9() {
447         reinit_dlc || return $?
448
449         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
450 peer:
451     - primary nid: 9.9.9.9@tcp
452       Multi-Rail: True
453       peer ni:
454         - nid: 9.9.9.9@tcp
455 EOF
456         append_global_yaml
457
458         do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
459                 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
460         compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
461 }
462 run_test 9 "Delete all secondary nids from peer (tcp)"
463
464 test_10() {
465         reinit_dlc || return $?
466
467         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
468 peer:
469     - primary nid: 10.10.10.10@tcp
470       Multi-Rail: True
471       peer ni:
472         - nid: 10.10.10.10@tcp
473         - nid: 10.10.10.12@tcp
474         - nid: 10.10.10.13@tcp
475         - nid: 10.10.10.15@tcp
476         - nid: 10.10.10.16@tcp
477 EOF
478         append_global_yaml
479         do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
480                 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
481         compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
482 }
483 run_test 10 "Delete single secondary nid from peer (o2ib)"
484
485 test_11() {
486         reinit_dlc || return $?
487
488         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
489 peer:
490     - primary nid: 11.11.11.11@tcp
491       Multi-Rail: True
492       peer ni:
493         - nid: 11.11.11.11@tcp
494 EOF
495         append_global_yaml
496         do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
497                 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
498         compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
499 }
500 run_test 11 "Delete all secondary nids from peer (o2ib)"
501
502 test_12() {
503         reinit_dlc || return $?
504
505         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
506 peer:
507     - primary nid: 12.12.12.12@o2ib
508       Multi-Rail: True
509       peer ni:
510         - nid: 12.12.12.12@o2ib
511         - nid: 13.13.13.13@o2ib
512         - nid: 14.13.13.13@o2ib
513         - nid: 14.15.13.13@o2ib
514         - nid: 15.17.1.5@tcp
515         - nid: 15.17.1.10@tcp
516         - nid: 15.17.1.20@tcp
517 EOF
518         append_global_yaml
519         do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
520                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
521                 error "Peer add failed $?"
522         compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
523 }
524 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
525
526 test_13() {
527         reinit_dlc || return $?
528
529         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
530 peer:
531     - primary nid: 13.13.13.13@o2ib
532       Multi-Rail: True
533       peer ni:
534         - nid: 13.13.13.13@o2ib
535 EOF
536         append_global_yaml
537         do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
538                 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
539                 error "Peer add failed $?"
540         compare_peer_del "13.13.13.13@o2ib" \
541                 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
542 }
543 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
544
545 create_nid() {
546         local num="$1"
547         local net="$2"
548
549         if [[ $net =~ gni* ]]; then
550                 echo "${num}@${net}"
551         else
552                 echo "${num}.${num}.${num}.${num}@${net}"
553         fi
554 }
555
556 create_mr_peer_yaml() {
557         local num_peers="$1"
558         local secondary_nids="$2"
559         local net="$3"
560
561         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
562         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
563         local i
564         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
565         local created=0
566         local nidnum=1
567         while [[ $created -lt $num_peers ]]; do
568                 local primary=$(create_nid ${nidnum} ${net})
569         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
570     - primary nid: $primary
571       Multi-Rail: True
572       peer ni:
573         - nid: $primary
574 EOF
575                 local j
576                 local start=$((nidnum + 1))
577                 local end=$((nidnum + $secondary_nids))
578                 for j in $(seq ${start} ${end}); do
579                         local nid=$(create_nid $j ${net})
580                         echo "        - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
581                 done
582                 nidnum=$((end + 1))
583                 ((created++))
584         done
585 }
586
587 test_14() {
588         reinit_dlc || return $?
589
590         echo "Create single peer, single nid, using import"
591         create_mr_peer_yaml 1 0 tcp
592         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
593                 error "Import failed $?"
594         append_global_yaml
595         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
596         compare_yaml_files
597
598         echo "Delete single peer using import --del"
599         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
600                 error "Import failed $?"
601         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
602         create_base_yaml_file
603         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
604         compare_yaml_files
605 }
606 run_test 14 "import peer create/delete with single nid"
607
608 test_15() {
609         reinit_dlc || return $?
610
611         echo "Create multiple peers, single nid per peer, using import"
612         create_mr_peer_yaml 5 0 o2ib
613         # The ordering of nids for this use-case is non-deterministic, so we
614         # we can't just diff the expected/actual output.
615         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
616                 error "Import failed $?"
617         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
618         validate_peer_nids 5 0
619
620         echo "Delete multiple peers, single nid per peer, using import --del"
621         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
622                 error "Import failed $?"
623         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
624         create_base_yaml_file
625         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
626         compare_yaml_files
627 }
628 run_test 15 "import multi peer create/delete with single nid per peer"
629
630 test_16() {
631         reinit_dlc || return $?
632
633         echo "Create single peer, multiple nids, using import"
634         create_mr_peer_yaml 1 5 tcp
635         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
636                 error "Import failed $?"
637         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
638         validate_peer_nids 1 5
639
640         echo "Delete single peer, multiple nids, using import --del"
641         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
642                 error "Import failed $?"
643         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
644         create_base_yaml_file
645         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
646         compare_yaml_files
647 }
648 run_test 16 "import peer create/delete with multiple nids"
649
650 test_17() {
651         reinit_dlc || return $?
652
653         echo "Create multiple peers, multiple nids per peer, using import"
654         create_mr_peer_yaml 5 7 o2ib
655         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
656                 error "Import failed $?"
657         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
658         validate_peer_nids 5 7
659
660         echo "Delete multiple peers, multiple nids per peer, using import --del"
661         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
662                 error "Import failed $?"
663         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
664         create_base_yaml_file
665         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
666         compare_yaml_files
667 }
668 run_test 17 "import multi peer create/delete with multiple nids"
669
670 test_18a() {
671         reinit_dlc || return $?
672
673         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
674 peer:
675     - primary nid: 1.1.1.1@tcp
676       Multi-Rail: True
677       peer ni:
678         - nid: 1.1.1.1@tcp
679         - nid: 2.2.2.2@tcp
680         - nid: 4.4.4.4@tcp
681         - nid: 3.3.3.3@o2ib
682         - nid: 5@gni
683 EOF
684         echo "Import peer with 5 nids"
685         cat $TMP/sanity-lnet-$testnum-expected.yaml
686         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
687                 error "Import failed $?"
688         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
689 peer:
690     - primary nid: 1.1.1.1@tcp
691       Multi-Rail: True
692       peer ni:
693         - nid: 2.2.2.2@tcp
694         - nid: 3.3.3.3@o2ib
695         - nid: 5@gni
696 EOF
697         echo "Delete three of the nids"
698         cat $TMP/sanity-lnet-$testnum-expected.yaml
699         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
700         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
701 peer:
702     - primary nid: 1.1.1.1@tcp
703       Multi-Rail: True
704       peer ni:
705         - nid: 1.1.1.1@tcp
706         - nid: 4.4.4.4@tcp
707 EOF
708         echo "Check peer has expected nids remaining"
709         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
710         append_global_yaml
711         compare_yaml_files
712 }
713 run_test 18a "Delete a subset of nids from a single peer using import --del"
714
715 test_18b() {
716         reinit_dlc || return $?
717
718         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
719 peer:
720     - primary nid: 1.1.1.1@tcp
721       Multi-Rail: True
722       peer ni:
723         - nid: 1.1.1.1@tcp
724         - nid: 2.2.2.2@tcp
725         - nid: 4.4.4.4@tcp
726         - nid: 3.3.3.3@o2ib
727         - nid: 5@gni
728     - primary nid: 6.6.6.6@o2ib
729       Multi-Rail: True
730       peer ni:
731         - nid: 6.6.6.6@o2ib
732         - nid: 7.7.7.7@tcp
733         - nid: 8.8.8.8@tcp
734         - nid: 9.9.9.9@tcp
735         - nid: 10@gni
736 EOF
737         echo "Import two peers with 5 nids each"
738         cat $TMP/sanity-lnet-$testnum-expected.yaml
739         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
740                 error "Import failed $?"
741         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
742 peer:
743     - primary nid: 1.1.1.1@tcp
744       Multi-Rail: True
745       peer ni:
746         - nid: 2.2.2.2@tcp
747         - nid: 3.3.3.3@o2ib
748         - nid: 5@gni
749     - primary nid: 6.6.6.6@o2ib
750       Multi-Rail: True
751       peer ni:
752         - nid: 7.7.7.7@tcp
753         - nid: 8.8.8.8@tcp
754         - nid: 10@gni
755 EOF
756         echo "Delete three of the nids from each peer"
757         cat $TMP/sanity-lnet-$testnum-expected.yaml
758         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
759         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
760 peer:
761     - primary nid: 6.6.6.6@o2ib
762       Multi-Rail: True
763       peer ni:
764         - nid: 6.6.6.6@o2ib
765         - nid: 7.7.7.7@tcp
766     - primary nid: 1.1.1.1@tcp
767       Multi-Rail: True
768       peer ni:
769         - nid: 1.1.1.1@tcp
770         - nid: 4.4.4.4@tcp
771 EOF
772         append_global_yaml
773         echo "Check peers have expected nids remaining"
774         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
775         compare_yaml_files
776         validate_peer_nids 2 1
777 }
778 run_test 18b "Delete multiple nids from multiple peers using import --del"
779
780 test_19() {
781         reinit_dlc || return $?
782         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
783 peer:
784     - primary nid: 19@gni
785       Multi-Rail: True
786       peer ni:
787         - nid: 19@gni
788 EOF
789         append_global_yaml
790         compare_peer_add "19@gni"
791 }
792 run_test 19 "Add peer with single nid (gni)"
793
794 test_20() {
795         reinit_dlc || return $?
796         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
797 peer:
798     - primary nid: 20@gni
799       Multi-Rail: True
800       peer ni:
801         - nid: 20@gni
802         - nid: 20.20.20.20@tcp
803         - nid: 20.20.20.20@o2ib
804 EOF
805         append_global_yaml
806         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
807 }
808 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
809
810 test_21() {
811         reinit_dlc || return $?
812         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
813 peer:
814     - primary nid: 21@gni
815       Multi-Rail: True
816       peer ni:
817         - nid: 21@gni
818         - nid: 22@gni
819         - nid: 23@gni
820         - nid: 24@gni
821         - nid: 25@gni
822 EOF
823         append_global_yaml
824         echo"Add peer with nidrange (gni)"
825         compare_peer_add "21@gni" "[22-25]@gni" || error
826         echo "Add peer with nidrange that overlaps primary nid (gni)"
827         compare_peer_add "21@gni" "[21-25]@gni"
828 }
829 run_test 21 "Add peer with nidrange (gni)"
830
831 test_22() {
832         reinit_dlc || return $?
833         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
834 peer:
835     - primary nid: 22@gni
836       Multi-Rail: True
837       peer ni:
838         - nid: 22@gni
839         - nid: 24@gni
840         - nid: 25@gni
841         - nid: 27@gni
842         - nid: 28@gni
843         - nid: 29@gni
844 EOF
845         append_global_yaml
846         do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
847                 error "Peer add failed $?"
848         compare_peer_del "22@gni" "26@gni"
849 }
850 run_test 22 "Delete single secondary nid from peer (gni)"
851
852 test_23() {
853         reinit_dlc || return $?
854         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
855 peer:
856     - primary nid: 23@gni
857       Multi-Rail: True
858       peer ni:
859         - nid: 23@gni
860 EOF
861         append_global_yaml
862
863         do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
864                 error "Peer add failed $?"
865         compare_peer_del "23@gni" "[25-29]@gni"
866 }
867 run_test 23 "Delete all secondary nids from peer (gni)"
868
869 test_24() {
870         reinit_dlc || return $?
871         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
872 peer:
873     - primary nid: 24@gni
874       Multi-Rail: True
875       peer ni:
876         - nid: 24@gni
877         - nid: 11@gni
878         - nid: 13.13.13.13@o2ib
879         - nid: 14.13.13.13@o2ib
880         - nid: 14.15.13.13@o2ib
881         - nid: 15.17.1.5@tcp
882         - nid: 15.17.1.10@tcp
883         - nid: 15.17.1.20@tcp
884 EOF
885         append_global_yaml
886         do_lnetctl peer add --prim_nid 24@gni \
887                 --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 ||
888                 error "Peer add failed $?"
889         compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
890 }
891 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
892
893 test_25() {
894         reinit_dlc || return $?
895         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
896 peer:
897     - primary nid: 25@gni
898       Multi-Rail: True
899       peer ni:
900         - nid: 25@gni
901 EOF
902         append_global_yaml
903         do_lnetctl peer add --prim_nid 25@gni \
904                 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
905                 error "Peer add failed $?"
906         compare_peer_del "25@gni" \
907                 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
908 }
909 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
910
911 test_99a() {
912         reinit_dlc || return $?
913
914         echo "Invalid prim_nid - peer add"
915         do_lnetctl peer add --prim_nid foobar &&
916                 error "Command should have failed"
917
918         echo "Invalid prim_nid - peer del"
919         do_lnetctl peer del --prim_nid foobar &&
920                 error "Command should have failed"
921
922         echo "Delete non-existing peer"
923         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
924                 error "Command should have failed"
925
926         echo "Don't provide mandatory arguments peer del"
927         do_lnetctl peer del --nid 1.1.1.1@tcp &&
928                 error "Command should have failed"
929
930         echo "Don't provide mandatory arguments peer add"
931         do_lnetctl peer add &&
932                 error "Command should have failed"
933
934         echo "Invalid secondary nids"
935         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
936                 error "Command should have failed"
937
938         echo "Exceed max nids per peer"
939         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
940                 error "Command should have failed"
941
942         echo "Invalid net type"
943         do_lnetctl peer add --prim_nid 1@foo &&
944                 error "Command should have failed"
945
946         echo "Invalid nid format"
947         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
948
949         local nid
950         for nid in ${invalid_nids}; do
951                 echo "Check invalid primary nid - '$nid'"
952                 do_lnetctl peer add --prim_nid $nid &&
953                         error "Command should have failed"
954         done
955
956         local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
957         invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
958         invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
959
960         local nidstr
961         for nidstr in ${invalid_strs}; do
962                 echo "Check invalid nidstring - '$nidstr'"
963                 do_lnetctl peer add --nid $nidstr &&
964                         error "Command should have failed"
965         done
966
967         echo "Add non-local gateway"
968         do_lnetctl route add --net tcp --gateway 1@gni &&
969                 error "Command should have failed"
970
971         return 0
972 }
973 run_test 99a "Check various invalid inputs to lnetctl peer"
974
975 test_99b() {
976         reinit_dlc || return $?
977
978         create_base_yaml_file
979
980         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
981 peer:
982     - primary nid: 99.99.99.99@tcp
983       Multi-Rail: Foobar
984       peer ni:
985         - nid: 99.99.99.99@tcp
986 EOF
987         do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
988                 error "import should have failed"
989         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
990         compare_yaml_files
991 }
992 run_test 99b "Invalid value for Multi-Rail in yaml import"
993
994 have_interface() {
995         local if="$1"
996         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
997         [[ -n $ip ]]
998 }
999
1000 add_net() {
1001         local net="$1"
1002         local if="$2"
1003
1004         if ! lsmod | grep -q ksocklnd ; then
1005                 load_module ../lnet/klnds/socklnd/ksocklnd ||
1006                         error "Can't load ksocklnd.ko"
1007         fi
1008
1009         do_lnetctl net add --net ${net} --if ${if} ||
1010                 error "Failed to add net ${net} on if ${if}"
1011 }
1012
1013 compare_route_add() {
1014         local rnet="$1"
1015         local gw="$2"
1016
1017         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1018
1019         do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1020                 error "route add failed $?"
1021         # CPT configuration is pruned from the exported yaml, since the default
1022         # can vary across test systems (unlike default values for things like
1023         # peer_credits, peer_timeout, etc.)
1024         $LNETCTL export --backup | grep -v CPT > $actual ||
1025                 error "export failed $?"
1026         validate_gateway_nids
1027         return $?
1028 }
1029
1030 test_100() {
1031         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1032         reinit_dlc || return $?
1033         add_net "tcp" "eth0"
1034         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1035 net:
1036     - net type: tcp
1037       local NI(s):
1038         - interfaces:
1039               0: eth0
1040           tunables:
1041               peer_timeout: 180
1042               peer_credits: 8
1043               peer_buffer_credits: 0
1044               credits: 256
1045 route:
1046     - net: tcp7
1047       gateway: 7.7.7.7@tcp
1048       hop: -1
1049       priority: 0
1050       health_sensitivity: 1
1051 peer:
1052     - primary nid: 7.7.7.7@tcp
1053       Multi-Rail: False
1054       peer ni:
1055         - nid: 7.7.7.7@tcp
1056 EOF
1057         append_global_yaml
1058         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1059         compare_yaml_files
1060 }
1061 run_test 100 "Add route with single gw (tcp)"
1062
1063 test_101() {
1064         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1065         reinit_dlc || return $?
1066         add_net "tcp" "eth0"
1067         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1068 net:
1069     - net type: tcp
1070       local NI(s):
1071         - interfaces:
1072               0: eth0
1073           tunables:
1074               peer_timeout: 180
1075               peer_credits: 8
1076               peer_buffer_credits: 0
1077               credits: 256
1078 route:
1079     - net: tcp8
1080       gateway: 8.8.8.10@tcp
1081       hop: -1
1082       priority: 0
1083       health_sensitivity: 1
1084     - net: tcp8
1085       gateway: 8.8.8.9@tcp
1086       hop: -1
1087       priority: 0
1088       health_sensitivity: 1
1089     - net: tcp8
1090       gateway: 8.8.8.8@tcp
1091       hop: -1
1092       priority: 0
1093       health_sensitivity: 1
1094 peer:
1095     - primary nid: 8.8.8.9@tcp
1096       Multi-Rail: False
1097       peer ni:
1098         - nid: 8.8.8.9@tcp
1099     - primary nid: 8.8.8.10@tcp
1100       Multi-Rail: False
1101       peer ni:
1102         - nid: 8.8.8.10@tcp
1103     - primary nid: 8.8.8.8@tcp
1104       Multi-Rail: False
1105       peer ni:
1106         - nid: 8.8.8.8@tcp
1107 EOF
1108         append_global_yaml
1109         compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1110 }
1111 run_test 101 "Add route with multiple gw (tcp)"
1112
1113 compare_route_del() {
1114         local rnet="$1"
1115         local gw="$2"
1116
1117         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1118
1119         do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1120                 error "route del failed $?"
1121         $LNETCTL export --backup > $actual ||
1122                 error "export failed $?"
1123         validate_gateway_nids
1124 }
1125
1126 test_102() {
1127         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1128         reinit_dlc || return $?
1129         add_net "tcp" "eth0"
1130         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1131         do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1132                 error "route add failed $?"
1133         compare_route_del "tcp102" "102.102.102.102@tcp"
1134 }
1135 run_test 102 "Delete route with single gw (tcp)"
1136
1137 test_103() {
1138         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1139         reinit_dlc || return $?
1140         add_net "tcp" "eth0"
1141         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1142         do_lnetctl route add --net tcp103 \
1143                 --gateway 103.103.103.[103-120/4]@tcp ||
1144                 error "route add failed $?"
1145         compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1146 }
1147 run_test 103 "Delete route with multiple gw (tcp)"
1148
1149 ### load lnet in default namespace, configure in target namespace
1150
1151 test_200() {
1152         cleanup_lnet || exit 1
1153         load_lnet "networks=\"\""
1154         do_ns $LNETCTL lnet configure --all || exit 1
1155         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1156 }
1157 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1158
1159 test_201() {
1160         cleanup_lnet || exit 1
1161         load_lnet "networks=tcp($FAKE_IF)"
1162         do_ns $LNETCTL lnet configure --all || exit 1
1163         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1164 }
1165 run_test 201 "load lnet using networks module options in a non-default namespace"
1166
1167 test_202() {
1168         cleanup_lnet || exit 1
1169         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1170         do_ns $LNETCTL lnet configure --all || exit 1
1171         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1172 }
1173 run_test 202 "load lnet using ip2nets in a non-default namespace"
1174
1175
1176 ### Add the interfaces in the target namespace
1177
1178 test_203() {
1179         cleanup_lnet || exit 1
1180         load_lnet
1181         do_lnetctl lnet configure || exit 1
1182         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1183 }
1184 run_test 203 "add a network using an interface in the non-default namespace"
1185
1186 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1187 function save_lnet_params() {
1188         $LNETCTL global show | egrep -v '^global:$' |
1189                                sed 's/://' > $LNET_PARAMS_FILE
1190 }
1191
1192 function restore_lnet_params() {
1193         local param value
1194         while read param value; do
1195                 [[ $param == max_intf ]] && continue
1196                 [[ $param == lnd_timeout ]] && continue
1197                 $LNETCTL set ${param} ${value} ||
1198                         error "Failed to restore ${param} to ${value}"
1199         done < $LNET_PARAMS_FILE
1200 }
1201
1202 function lnet_health_pre() {
1203         save_lnet_params
1204
1205         # Lower transaction timeout to speed up test execution
1206         $LNETCTL set transaction_timeout 10 ||
1207                 error "Failed to set transaction_timeout $?"
1208
1209         # Increase recovery interval so we have time to capture health values
1210         $LNETCTL set recovery_interval 20 ||
1211                 error "Failed to set recovery_interval $?"
1212
1213         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1214         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1215         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1216                       xargs echo | sed 's/ /+/g' | bc -l)
1217
1218         local my_nid=$($LCTL list_nids | head -n 1)
1219
1220         RMT_HVAL_PRE=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1221                        awk '/health value/{print $NF}' | xargs echo |
1222                        sed 's/ /+/g' | bc -l)
1223
1224         # Might not have any peers so initialize to zero.
1225         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1226
1227         return 0
1228 }
1229
1230 function lnet_health_post() {
1231         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1232         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1233                        awk '/health value/{print $NF}' |
1234                        xargs echo | sed 's/ /+/g' | bc -l)
1235
1236         local my_nid=$($LCTL list_nids | head -n 1)
1237
1238         RMT_HVAL_POST=$($LNETCTL peer show --nid $my_nid -v 2 2>/dev/null |
1239                         awk '/health value/{print $NF}' | xargs echo |
1240                         sed 's/ /+/g' | bc -l)
1241
1242         # Might not have any peers so initialize to zero.
1243         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1244
1245         ${VERBOSE} &&
1246         echo "Pre resends: $RSND_PRE" &&
1247         echo "Post resends: $RSND_POST" &&
1248         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1249         echo "Pre local health: $LO_HVAL_PRE" &&
1250         echo "Post local health: $LO_HVAL_POST" &&
1251         echo "Pre remote health: $RMT_HVAL_PRE" &&
1252         echo "Post remote health: $RMT_HVAL_POST"
1253
1254         restore_lnet_params
1255
1256         return 0
1257 }
1258
1259 function check_no_resends() {
1260         echo "Check that no resends took place"
1261         [[ $RSND_POST -ne $RSND_PRE ]] &&
1262                 error "Found resends: $RSND_POST != $RSND_PRE"
1263
1264         return 0
1265 }
1266
1267 function check_resends() {
1268         local delta=$((RSND_POST - RSND_PRE))
1269
1270         echo "Check that $RETRY_PARAM resends took place"
1271         [[ $delta -ne $RETRY_PARAM ]] &&
1272                 error "Expected $RETRY_PARAM resends found $delta"
1273
1274         return 0
1275 }
1276
1277 function check_no_local_health() {
1278         echo "Check that local NI health is unchanged"
1279         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1280                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1281
1282         return 0
1283 }
1284
1285 function check_local_health() {
1286         echo "Check that local NI health has been changed"
1287         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1288                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1289
1290         return 0
1291 }
1292
1293 function check_no_remote_health() {
1294         echo "Check that remote NI health is unchanged"
1295         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1296                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1297
1298         return 0
1299 }
1300
1301 function check_remote_health() {
1302         echo "Check that remote NI health has been changed"
1303         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1304                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1305
1306         return 0
1307 }
1308
1309 # See lnet/lnet/lib-msg.c:lnet_health_check()
1310 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1311 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1312 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1313 test_204() {
1314         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1315         reinit_dlc || return $?
1316         add_net "tcp" "eth0" || return $?
1317
1318         lnet_health_pre || return $?
1319
1320         local hstatus
1321         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1322                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1323                 echo "Simulate $hstatus"
1324                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1325                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1326                         error "Should have failed"
1327                 $LCTL net_drop_del *
1328         done
1329
1330         lnet_health_post
1331
1332         check_no_resends || return $?
1333         check_no_local_health || return $?
1334
1335         return 0
1336 }
1337 run_test 204 "Check no health or resends for single-rail local failures"
1338
1339 test_205() {
1340         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1341
1342         local hstatus
1343         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1344                 reinit_dlc || return $?
1345                 add_net "tcp" "eth0" || return $?
1346                 add_net "tcp1" "eth0" || return $?
1347
1348                 echo "Simulate $hstatus"
1349                 lnet_health_pre
1350
1351                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1352                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -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 *
1356
1357                 lnet_health_post
1358
1359                 check_resends || return $?
1360                 check_local_health || return $?
1361         done
1362
1363         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1364                 reinit_dlc || return $?
1365                 add_net "tcp" "eth0" || return $?
1366                 add_net "tcp1" "eth0" || return $?
1367
1368                 echo "Simulate $hstatus"
1369                 lnet_health_pre || return $?
1370
1371                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1372                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1373                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1374                         error "Should have failed"
1375                 $LCTL net_drop_del *
1376
1377                 lnet_health_post
1378
1379                 check_no_resends || return $?
1380                 check_local_health || return $?
1381         done
1382
1383         return 0
1384 }
1385 run_test 205 "Check health and resends for multi-rail local failures"
1386
1387 # See lnet/lnet/lib-msg.c:lnet_health_check()
1388 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1389 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout network_timeout"
1390 test_206() {
1391         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1392         reinit_dlc || return $?
1393         add_net "tcp" "eth0" || return $?
1394
1395         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1396                 error "failed to discover myself"
1397
1398         lnet_health_pre || return $?
1399
1400         local hstatus
1401         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1402                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1403                 echo "Simulate $hstatus"
1404                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1405                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1406                         error "Should have failed"
1407                 $LCTL net_drop_del *
1408         done
1409
1410         lnet_health_post
1411
1412         check_no_resends || return $?
1413         check_no_local_health || return $?
1414         check_no_remote_health || return $?
1415
1416         return 0
1417 }
1418 run_test 206 "Check no health or resends for single-rail remote failures"
1419
1420 test_207() {
1421         have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
1422
1423         local hstatus
1424         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1425                 reinit_dlc || return $?
1426                 add_net "tcp" "eth0" || return $?
1427                 add_net "tcp1" "eth0" || return $?
1428
1429                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1430                         error "failed to discover myself"
1431
1432                 echo "Simulate $hstatus"
1433                 lnet_health_pre || return $?
1434                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1435                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1436                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1437                         error "Should have failed"
1438                 $LCTL net_drop_del *
1439
1440                 lnet_health_post
1441
1442                 check_resends || return $?
1443                 check_no_local_health || return $?
1444                 check_remote_health || return $?
1445         done
1446         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1447                 reinit_dlc || return $?
1448                 add_net "tcp" "eth0" || return $?
1449                 add_net "tcp1" "eth0" || return $?
1450
1451                 do_lnetctl discover $($LCTL list_nids | head -n 1) ||
1452                         error "failed to discover myself"
1453
1454                 echo "Simulate $hstatus"
1455                 lnet_health_pre || return $?
1456                 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e ${hstatus}
1457                 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e ${hstatus}
1458                 do_lnetctl discover $($LCTL list_nids | head -n 1) &&
1459                         error "Should have failed"
1460                 $LCTL net_drop_del *
1461
1462                 lnet_health_post
1463
1464                 check_no_resends || return $?
1465                 check_no_local_health || return $?
1466                 check_remote_health || return $?
1467         done
1468
1469         return 0
1470 }
1471 run_test 207 "Check health and resends for multi-rail remote errors"
1472
1473 test_300() {
1474         # LU-13274
1475         local header
1476         local out=$TMP/$tfile
1477         local prefix=/usr/include/linux/lnet
1478
1479         # We use a hard coded prefix so that this test will not fail
1480         # when run in tree.
1481         CC=${CC:-cc}
1482         if ! which $CC > /dev/null 2>&1; then
1483                 skip_env "$CC is not installed"
1484         fi
1485
1486         cleanup_lnet || exit 1
1487         load_lnet
1488
1489         if ! [[ -d $prefix ]]; then
1490                 # Assume we're running in tree and fixup the include path.
1491                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
1492         fi
1493
1494         for header in $prefix/*.h; do
1495                 if ! [[ -f "$header" ]]; then
1496                         continue
1497                 fi
1498
1499                 $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
1500                         error "cannot compile '$header'"
1501         done
1502         rm -f $out
1503 }
1504 run_test 300 "packaged LNet UAPI headers can be compiled"
1505
1506 complete $SECONDS
1507
1508 cleanup_testsuite
1509 exit_status