Whamcloud - gitweb
97f7f36a0eba6dea2fa05098c16332c240a4945f
[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
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skip the grant tests for ARM until they are fixed
16 if [[ $(uname -m) = aarch64 ]]; then
17         # bug number:    LU-14067
18         ALWAYS_EXCEPT+=" 300"
19 fi
20
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
22
23 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24
25 . $LUSTRE/tests/test-framework.sh
26 CLEANUP=${CLEANUP:-:}
27 SETUP=${SETUP:-:}
28 init_test_env "$@"
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 init_logging
31
32 build_test_filter
33
34 [[ -z $LNETCTL ]] && skip "Need lnetctl"
35
36 restore_mounts=false
37
38 if is_mounted $MOUNT || is_mounted $MOUNT2; then
39         cleanupall || error "Failed cleanup prior to test execution"
40         restore_mounts=true
41 fi
42
43 cleanup_lnet() {
44         echo "Cleaning up LNet"
45         lsmod | grep -q lnet &&
46                 $LNETCTL lnet unconfigure 2>/dev/null
47         unload_modules
48 }
49
50 restore_modules=false
51 if module_loaded lnet ; then
52         cleanup_lnet || error "Failed to unload modules before test execution"
53         restore_modules=true
54 fi
55
56 cleanup_testsuite() {
57         trap "" EXIT
58         # Cleanup any tmp files created by the sub tests
59         rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
60         cleanup_netns
61         cleanup_lnet
62         if $restore_mounts; then
63                 setupall || error "Failed to setup Lustre after test execution"
64         elif $restore_modules; then
65                 load_modules ||
66                         error "Couldn't load modules after test execution"
67         fi
68         return 0
69 }
70
71 TESTNS='test_ns'
72 FAKE_IF="test1pg"
73 FAKE_IP="10.1.2.3"
74 do_ns() {
75         echo "ip netns exec $TESTNS $*"
76         ip netns exec $TESTNS "$@"
77 }
78
79 setup_fakeif() {
80         local netns="$1"
81
82         local netns_arg=""
83         [[ -n $netns ]] &&
84                 netns_arg="netns $netns"
85
86         ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
87         ip link set 'test1pl' up
88         if [[ -n $netns ]]; then
89                 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
90                 do_ns ip link set $FAKE_IF up
91         else
92                 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
93                 ip link set $FAKE_IF up
94         fi
95 }
96
97 cleanup_fakeif() {
98         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
99 }
100
101 setup_netns() {
102         cleanup_netns
103
104         ip netns add $TESTNS
105         setup_fakeif $TESTNS
106 }
107
108 cleanup_netns() {
109         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
110         cleanup_fakeif
111 }
112
113 configure_dlc() {
114         echo "Loading LNet and configuring DLC"
115         load_lnet
116         do_lnetctl lnet configure
117 }
118
119 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
120 define_global_yaml() {
121         $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
122                 error "Failed to export global yaml $?"
123 }
124
125 reinit_dlc() {
126         if lsmod | grep -q lnet; then
127                 do_lnetctl lnet unconfigure ||
128                         error "lnetctl lnet unconfigure failed $?"
129                 do_lnetctl lnet configure ||
130                         error "lnetctl lnet configure failed $?"
131         else
132                 configure_dlc || error "configure_dlc failed $?"
133         fi
134         define_global_yaml
135 }
136
137 append_global_yaml() {
138         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
139                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
140
141         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
142 }
143
144 create_base_yaml_file() {
145         append_global_yaml
146 }
147
148 compare_yaml_files() {
149         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
150         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
151         local rc=0
152         ! [[ -e $expected ]] && echo "$expected not found" && return 1
153         ! [[ -e $actual ]] && echo "$actual not found" && return 1
154         diff -upN ${actual} ${expected} || rc=$?
155         echo "Expected:"
156         cat $expected
157         echo "Actual:"
158         cat $actual
159         return $rc
160 }
161
162 validate_nid() {
163         local nid="$1"
164         local net="${nid//*@/}"
165         local addr="${nid//@*/}"
166
167         local num_re='[0-9]\+'
168         local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
169
170         if [[ $net =~ gni[0-9]* ]]; then
171                 [[ $addr =~ ${num_re} ]] && return 0
172         else
173                 [[ $addr =~ ${ip_re} ]] && return 0
174         fi
175 }
176
177 validate_nids() {
178         local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
179         local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
180         local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
181         local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
182
183         local nid
184         for nid in $primary_nids $secondary_nids; do
185                 validate_nid "$nid" || error "Bad NID \"${nid}\""
186         done
187         return 0
188 }
189
190 validate_peer_nids() {
191         local num_peers="$1"
192         local nids_per_peer="$2"
193
194         local expect_p="$num_peers"
195         # The primary nid also shows up in the list of secondary nids
196         local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
197
198         local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
199         local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
200         if [[ $expect_p -ne $actual_p ]]; then
201                 compare_yaml_files
202                 error "Expected $expect_p but found $actual_p primary nids"
203         elif [[ $expect_s -ne $actual_s ]]; then
204                 compare_yaml_files
205                 error "Expected $expect_s but found $actual_s secondary nids"
206         fi
207         validate_nids
208 }
209
210 validate_gateway_nids() {
211         local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
212         local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
213         if [[ $expect_gw -ne $actual_gw ]]; then
214                 compare_yaml_files
215                 error "Expected $expect_gw gateways but found $actual_gw gateways"
216         fi
217         validate_nids
218 }
219
220 cleanupall -f
221 setup_netns || error "setup_netns failed with $?"
222
223 # Determine the local interface(s) used for LNet
224 load_lnet "config_on_load=1" || error "Failed to load modules"
225
226 do_lnetctl net show
227 ip a
228
229 INTERFACES=( $(lnet_if_list) )
230
231 cleanup_lnet || error "Failed to cleanup LNet"
232
233 stack_trap 'cleanup_testsuite' EXIT
234
235 test_0() {
236         load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
237         do_lnetctl lnet configure || error "lnet configure failed rc = $?"
238         define_global_yaml
239         reinit_dlc || return $?
240         do_lnetctl import <  ${GLOBAL_YAML_FILE} || error "Import failed $?"
241         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
242         create_base_yaml_file
243         compare_yaml_files || error "Configuration changed after import"
244 }
245 run_test 0 "Export empty config, import the config, compare"
246
247 compare_peer_add() {
248         local prim_nid="${1:+--prim_nid $1}"
249         local nid="${2:+--nid $2}"
250
251         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
252
253         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
254         $LNETCTL export --backup > $actual || error "export failed $?"
255         compare_yaml_files
256         return $?
257 }
258
259 test_1() {
260         reinit_dlc || return $?
261         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
262 peer:
263     - primary nid: 1.1.1.1@tcp
264       Multi-Rail: True
265       peer ni:
266         - nid: 1.1.1.1@tcp
267 EOF
268         append_global_yaml
269         compare_peer_add "1.1.1.1@tcp"
270 }
271 run_test 1 "Add peer with single nid (tcp)"
272
273 test_2() {
274         reinit_dlc || return $?
275         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
276 peer:
277     - primary nid: 2.2.2.2@o2ib
278       Multi-Rail: True
279       peer ni:
280         - nid: 2.2.2.2@o2ib
281 EOF
282         append_global_yaml
283         compare_peer_add "2.2.2.2@o2ib"
284 }
285 run_test 2 "Add peer with single nid (o2ib)"
286
287 test_3() {
288         reinit_dlc || return $?
289         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
290 peer:
291     - primary nid: 3.3.3.3@tcp
292       Multi-Rail: True
293       peer ni:
294         - nid: 3.3.3.3@tcp
295         - nid: 3.3.3.3@o2ib
296 EOF
297         append_global_yaml
298         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
299 }
300 run_test 3 "Add peer with tcp primary o2ib secondary"
301
302 test_4() {
303         reinit_dlc || return $?
304         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
305 peer:
306     - primary nid: 4.4.4.4@tcp
307       Multi-Rail: True
308       peer ni:
309         - nid: 4.4.4.4@tcp
310         - nid: 4.4.4.1@tcp
311         - nid: 4.4.4.2@tcp
312         - nid: 4.4.4.3@tcp
313 EOF
314         append_global_yaml
315         echo "Add peer with nidrange (tcp)"
316         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
317
318         echo "Add peer with nidrange that overlaps primary nid (tcp)"
319         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
320 }
321 run_test 4 "Add peer with nidrange (tcp)"
322
323 test_5() {
324         reinit_dlc || return $?
325         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
326 peer:
327     - primary nid: 5.5.5.5@o2ib
328       Multi-Rail: True
329       peer ni:
330         - nid: 5.5.5.5@o2ib
331         - nid: 5.5.5.1@o2ib
332         - nid: 5.5.5.2@o2ib
333         - nid: 5.5.5.3@o2ib
334         - nid: 5.5.5.4@o2ib
335 EOF
336         append_global_yaml
337         echo "Add peer with nidrange (o2ib)"
338         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
339
340         echo "Add peer with nidranage that overlaps primary nid (o2ib)"
341         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
342 }
343 run_test 5 "Add peer with nidrange (o2ib)"
344
345 test_6() {
346         reinit_dlc || return $?
347         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
348 peer:
349     - primary nid: 6.6.6.6@tcp
350       Multi-Rail: True
351       peer ni:
352         - nid: 6.6.6.6@tcp
353         - nid: 6.6.6.0@tcp
354         - nid: 6.6.6.2@tcp
355         - nid: 6.6.6.4@tcp
356         - nid: 6.6.7.0@tcp
357         - nid: 6.6.7.2@tcp
358         - nid: 6.6.7.4@tcp
359         - nid: 6.6.1.0@o2ib
360         - nid: 6.6.1.3@o2ib
361         - nid: 6.6.1.6@o2ib
362         - nid: 6.6.3.0@o2ib
363         - nid: 6.6.3.3@o2ib
364         - nid: 6.6.3.6@o2ib
365         - nid: 6@gni
366         - nid: 10@gni
367 EOF
368         append_global_yaml
369         compare_peer_add "6.6.6.6@tcp" \
370                 "6.6.[6-7].[0-4/2]@tcp,6.6.[1-4/2].[0-6/3]@o2ib,[6-12/4]@gni"
371 }
372 run_test 6 "Add peer with multiple nidranges"
373
374 compare_peer_del() {
375         local prim_nid="${1:+--prim_nid $1}"
376         local nid="${2:+--nid $2}"
377
378         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
379
380         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
381         $LNETCTL export --backup > $actual || error "export failed $?"
382         compare_yaml_files
383         return $?
384 }
385
386 test_7() {
387         reinit_dlc || return $?
388         create_base_yaml_file
389
390         echo "Delete peer with single nid (tcp)"
391         do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
392         compare_peer_del "7.7.7.7@tcp"
393
394         echo "Delete peer with single nid (o2ib)"
395         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
396         compare_peer_del "7.7.7.7@o2ib"
397
398         echo "Delete peer that has multiple nids (tcp)"
399         do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
400                 error "Peer add failed $?"
401         compare_peer_del "7.7.7.7@tcp"
402
403         echo "Delete peer that has multiple nids (o2ib)"
404         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
405                 error "Peer add failed $?"
406         compare_peer_del "7.7.7.7@o2ib"
407
408         echo "Delete peer that has both tcp and o2ib nids"
409         do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
410                 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
411                 error "Peer add failed $?"
412         compare_peer_del "7.7.7.7@tcp"
413
414         echo "Delete peer with single nid (gni)"
415         do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
416         compare_peer_del "7@gni"
417
418         echo "Delete peer that has multiple nids (gni)"
419         do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
420                 error "Peer add failed $?"
421         compare_peer_del "7@gni"
422
423         echo "Delete peer that has tcp, o2ib and gni nids"
424         do_lnetctl peer add --prim_nid 7@gni \
425                 --nid [8-12]@gni,7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
426                 error "Peer add failed $?"
427         compare_peer_del "7@gni"
428 }
429 run_test 7 "Various peer delete tests"
430
431 test_8() {
432         reinit_dlc || return $?
433
434         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
435 peer:
436     - primary nid: 8.8.8.8@tcp
437       Multi-Rail: True
438       peer ni:
439         - nid: 8.8.8.8@tcp
440         - nid: 8.8.8.10@tcp
441         - nid: 8.8.8.11@tcp
442         - nid: 8.8.8.12@tcp
443         - nid: 8.8.8.14@tcp
444         - nid: 8.8.8.15@tcp
445 EOF
446         append_global_yaml
447
448         do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
449                 error "Peer add failed $?"
450         compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
451 }
452 run_test 8 "Delete single secondary nid from peer (tcp)"
453
454 test_9() {
455         reinit_dlc || return $?
456
457         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
458 peer:
459     - primary nid: 9.9.9.9@tcp
460       Multi-Rail: True
461       peer ni:
462         - nid: 9.9.9.9@tcp
463 EOF
464         append_global_yaml
465
466         do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
467                 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
468         compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
469 }
470 run_test 9 "Delete all secondary nids from peer (tcp)"
471
472 test_10() {
473         reinit_dlc || return $?
474
475         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
476 peer:
477     - primary nid: 10.10.10.10@tcp
478       Multi-Rail: True
479       peer ni:
480         - nid: 10.10.10.10@tcp
481         - nid: 10.10.10.12@tcp
482         - nid: 10.10.10.13@tcp
483         - nid: 10.10.10.15@tcp
484         - nid: 10.10.10.16@tcp
485 EOF
486         append_global_yaml
487         do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
488                 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
489         compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
490 }
491 run_test 10 "Delete single secondary nid from peer (o2ib)"
492
493 test_11() {
494         reinit_dlc || return $?
495
496         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
497 peer:
498     - primary nid: 11.11.11.11@tcp
499       Multi-Rail: True
500       peer ni:
501         - nid: 11.11.11.11@tcp
502 EOF
503         append_global_yaml
504         do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
505                 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
506         compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
507 }
508 run_test 11 "Delete all secondary nids from peer (o2ib)"
509
510 test_12() {
511         reinit_dlc || return $?
512
513         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
514 peer:
515     - primary nid: 12.12.12.12@o2ib
516       Multi-Rail: True
517       peer ni:
518         - nid: 12.12.12.12@o2ib
519         - nid: 13.13.13.13@o2ib
520         - nid: 14.13.13.13@o2ib
521         - nid: 14.15.13.13@o2ib
522         - nid: 15.17.1.5@tcp
523         - nid: 15.17.1.10@tcp
524         - nid: 15.17.1.20@tcp
525 EOF
526         append_global_yaml
527         do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
528                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
529                 error "Peer add failed $?"
530         compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
531 }
532 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
533
534 test_13() {
535         reinit_dlc || return $?
536
537         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
538 peer:
539     - primary nid: 13.13.13.13@o2ib
540       Multi-Rail: True
541       peer ni:
542         - nid: 13.13.13.13@o2ib
543 EOF
544         append_global_yaml
545         do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
546                 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
547                 error "Peer add failed $?"
548         compare_peer_del "13.13.13.13@o2ib" \
549                 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
550 }
551 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
552
553 create_nid() {
554         local num="$1"
555         local net="$2"
556
557         if [[ $net =~ gni* ]]; then
558                 echo "${num}@${net}"
559         else
560                 echo "${num}.${num}.${num}.${num}@${net}"
561         fi
562 }
563
564 create_mr_peer_yaml() {
565         local num_peers="$1"
566         local secondary_nids="$2"
567         local net="$3"
568
569         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
570         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
571         local i
572         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
573         local created=0
574         local nidnum=1
575         while [[ $created -lt $num_peers ]]; do
576                 local primary=$(create_nid ${nidnum} ${net})
577         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
578     - primary nid: $primary
579       Multi-Rail: True
580       peer ni:
581         - nid: $primary
582 EOF
583                 local j
584                 local start=$((nidnum + 1))
585                 local end=$((nidnum + $secondary_nids))
586                 for j in $(seq ${start} ${end}); do
587                         local nid=$(create_nid $j ${net})
588                         echo "        - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
589                 done
590                 nidnum=$((end + 1))
591                 ((created++))
592         done
593 }
594
595 test_14() {
596         reinit_dlc || return $?
597
598         echo "Create single peer, single nid, using import"
599         create_mr_peer_yaml 1 0 tcp
600         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
601                 error "Import failed $?"
602         append_global_yaml
603         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
604         compare_yaml_files
605
606         echo "Delete single peer using import --del"
607         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
608                 error "Import failed $?"
609         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
610         create_base_yaml_file
611         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
612         compare_yaml_files
613 }
614 run_test 14 "import peer create/delete with single nid"
615
616 test_15() {
617         reinit_dlc || return $?
618
619         echo "Create multiple peers, single nid per peer, using import"
620         create_mr_peer_yaml 5 0 o2ib
621         # The ordering of nids for this use-case is non-deterministic, so we
622         # we can't just diff the expected/actual output.
623         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
624                 error "Import failed $?"
625         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
626         validate_peer_nids 5 0
627
628         echo "Delete multiple peers, single nid per peer, using import --del"
629         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
630                 error "Import failed $?"
631         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
632         create_base_yaml_file
633         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
634         compare_yaml_files
635 }
636 run_test 15 "import multi peer create/delete with single nid per peer"
637
638 test_16() {
639         reinit_dlc || return $?
640
641         echo "Create single peer, multiple nids, using import"
642         create_mr_peer_yaml 1 5 tcp
643         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
644                 error "Import failed $?"
645         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
646         validate_peer_nids 1 5
647
648         echo "Delete single peer, multiple nids, using import --del"
649         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
650                 error "Import failed $?"
651         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
652         create_base_yaml_file
653         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
654         compare_yaml_files
655 }
656 run_test 16 "import peer create/delete with multiple nids"
657
658 test_17() {
659         reinit_dlc || return $?
660
661         echo "Create multiple peers, multiple nids per peer, using import"
662         create_mr_peer_yaml 5 7 o2ib
663         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
664                 error "Import failed $?"
665         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
666         validate_peer_nids 5 7
667
668         echo "Delete multiple peers, multiple nids per peer, using import --del"
669         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
670                 error "Import failed $?"
671         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
672         create_base_yaml_file
673         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
674         compare_yaml_files
675 }
676 run_test 17 "import multi peer create/delete with multiple nids"
677
678 test_18a() {
679         reinit_dlc || return $?
680
681         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
682 peer:
683     - primary nid: 1.1.1.1@tcp
684       Multi-Rail: True
685       peer ni:
686         - nid: 1.1.1.1@tcp
687         - nid: 2.2.2.2@tcp
688         - nid: 4.4.4.4@tcp
689         - nid: 3.3.3.3@o2ib
690         - nid: 5@gni
691 EOF
692         echo "Import peer with 5 nids"
693         cat $TMP/sanity-lnet-$testnum-expected.yaml
694         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
695                 error "Import failed $?"
696         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
697 peer:
698     - primary nid: 1.1.1.1@tcp
699       Multi-Rail: True
700       peer ni:
701         - nid: 2.2.2.2@tcp
702         - nid: 3.3.3.3@o2ib
703         - nid: 5@gni
704 EOF
705         echo "Delete three of the nids"
706         cat $TMP/sanity-lnet-$testnum-expected.yaml
707         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
708         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
709 peer:
710     - primary nid: 1.1.1.1@tcp
711       Multi-Rail: True
712       peer ni:
713         - nid: 1.1.1.1@tcp
714         - nid: 4.4.4.4@tcp
715 EOF
716         echo "Check peer has expected nids remaining"
717         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
718         append_global_yaml
719         compare_yaml_files
720 }
721 run_test 18a "Delete a subset of nids from a single peer using import --del"
722
723 test_18b() {
724         reinit_dlc || return $?
725
726         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
727 peer:
728     - primary nid: 1.1.1.1@tcp
729       Multi-Rail: True
730       peer ni:
731         - nid: 1.1.1.1@tcp
732         - nid: 2.2.2.2@tcp
733         - nid: 4.4.4.4@tcp
734         - nid: 3.3.3.3@o2ib
735         - nid: 5@gni
736     - primary nid: 6.6.6.6@o2ib
737       Multi-Rail: True
738       peer ni:
739         - nid: 6.6.6.6@o2ib
740         - nid: 7.7.7.7@tcp
741         - nid: 8.8.8.8@tcp
742         - nid: 9.9.9.9@tcp
743         - nid: 10@gni
744 EOF
745         echo "Import two peers with 5 nids each"
746         cat $TMP/sanity-lnet-$testnum-expected.yaml
747         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
748                 error "Import failed $?"
749         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
750 peer:
751     - primary nid: 1.1.1.1@tcp
752       Multi-Rail: True
753       peer ni:
754         - nid: 2.2.2.2@tcp
755         - nid: 3.3.3.3@o2ib
756         - nid: 5@gni
757     - primary nid: 6.6.6.6@o2ib
758       Multi-Rail: True
759       peer ni:
760         - nid: 7.7.7.7@tcp
761         - nid: 8.8.8.8@tcp
762         - nid: 10@gni
763 EOF
764         echo "Delete three of the nids from each peer"
765         cat $TMP/sanity-lnet-$testnum-expected.yaml
766         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
767         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
768 peer:
769     - primary nid: 6.6.6.6@o2ib
770       Multi-Rail: True
771       peer ni:
772         - nid: 6.6.6.6@o2ib
773         - nid: 7.7.7.7@tcp
774     - primary nid: 1.1.1.1@tcp
775       Multi-Rail: True
776       peer ni:
777         - nid: 1.1.1.1@tcp
778         - nid: 4.4.4.4@tcp
779 EOF
780         append_global_yaml
781         echo "Check peers have expected nids remaining"
782         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
783         compare_yaml_files
784         validate_peer_nids 2 1
785 }
786 run_test 18b "Delete multiple nids from multiple peers using import --del"
787
788 test_19() {
789         reinit_dlc || return $?
790         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
791 peer:
792     - primary nid: 19@gni
793       Multi-Rail: True
794       peer ni:
795         - nid: 19@gni
796 EOF
797         append_global_yaml
798         compare_peer_add "19@gni"
799 }
800 run_test 19 "Add peer with single nid (gni)"
801
802 test_20() {
803         reinit_dlc || return $?
804         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
805 peer:
806     - primary nid: 20@gni
807       Multi-Rail: True
808       peer ni:
809         - nid: 20@gni
810         - nid: 20.20.20.20@tcp
811         - nid: 20.20.20.20@o2ib
812 EOF
813         append_global_yaml
814         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
815 }
816 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
817
818 test_21() {
819         reinit_dlc || return $?
820         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
821 peer:
822     - primary nid: 21@gni
823       Multi-Rail: True
824       peer ni:
825         - nid: 21@gni
826         - nid: 22@gni
827         - nid: 23@gni
828         - nid: 24@gni
829         - nid: 25@gni
830 EOF
831         append_global_yaml
832         echo "Add peer with nidrange (gni)"
833         compare_peer_add "21@gni" "[22-25]@gni" || error
834         echo "Add peer with nidrange that overlaps primary nid (gni)"
835         compare_peer_add "21@gni" "[21-25]@gni"
836 }
837 run_test 21 "Add peer with nidrange (gni)"
838
839 test_22() {
840         reinit_dlc || return $?
841         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
842 peer:
843     - primary nid: 22@gni
844       Multi-Rail: True
845       peer ni:
846         - nid: 22@gni
847         - nid: 24@gni
848         - nid: 25@gni
849         - nid: 27@gni
850         - nid: 28@gni
851         - nid: 29@gni
852 EOF
853         append_global_yaml
854         do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
855                 error "Peer add failed $?"
856         compare_peer_del "22@gni" "26@gni"
857 }
858 run_test 22 "Delete single secondary nid from peer (gni)"
859
860 test_23() {
861         reinit_dlc || return $?
862         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
863 peer:
864     - primary nid: 23@gni
865       Multi-Rail: True
866       peer ni:
867         - nid: 23@gni
868 EOF
869         append_global_yaml
870
871         do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
872                 error "Peer add failed $?"
873         compare_peer_del "23@gni" "[25-29]@gni"
874 }
875 run_test 23 "Delete all secondary nids from peer (gni)"
876
877 test_24() {
878         reinit_dlc || return $?
879         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
880 peer:
881     - primary nid: 24@gni
882       Multi-Rail: True
883       peer ni:
884         - nid: 24@gni
885         - nid: 11@gni
886         - nid: 13.13.13.13@o2ib
887         - nid: 14.13.13.13@o2ib
888         - nid: 14.15.13.13@o2ib
889         - nid: 15.17.1.5@tcp
890         - nid: 15.17.1.10@tcp
891         - nid: 15.17.1.20@tcp
892 EOF
893         append_global_yaml
894         do_lnetctl peer add --prim_nid 24@gni \
895                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp,[5-12/6]@gni ||
896                 error "Peer add failed $?"
897         compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
898 }
899 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
900
901 test_25() {
902         reinit_dlc || return $?
903         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
904 peer:
905     - primary nid: 25@gni
906       Multi-Rail: True
907       peer ni:
908         - nid: 25@gni
909 EOF
910         append_global_yaml
911         do_lnetctl peer add --prim_nid 25@gni \
912                 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
913                 error "Peer add failed $?"
914         compare_peer_del "25@gni" \
915                 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
916 }
917 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
918
919 test_99a() {
920         reinit_dlc || return $?
921
922         echo "Invalid prim_nid - peer add"
923         do_lnetctl peer add --prim_nid foobar &&
924                 error "Command should have failed"
925
926         echo "Invalid prim_nid - peer del"
927         do_lnetctl peer del --prim_nid foobar &&
928                 error "Command should have failed"
929
930         echo "Delete non-existing peer"
931         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
932                 error "Command should have failed"
933
934         echo "Don't provide mandatory argument for peer del"
935         do_lnetctl peer del --nid 1.1.1.1@tcp &&
936                 error "Command should have failed"
937
938         echo "Don't provide mandatory argument for peer add"
939         do_lnetctl peer add --nid 1.1.1.1@tcp &&
940                 error "Command should have failed"
941
942         echo "Don't provide mandatory arguments peer add"
943         do_lnetctl peer add &&
944                 error "Command should have failed"
945
946         echo "Invalid secondary nids"
947         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
948                 error "Command should have failed"
949
950         echo "Exceed max nids per peer"
951         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
952                 error "Command should have failed"
953
954         echo "Invalid net type"
955         do_lnetctl peer add --prim_nid 1@foo &&
956                 error "Command should have failed"
957
958         echo "Invalid nid format"
959         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
960
961         local nid
962         for nid in ${invalid_nids}; do
963                 echo "Check invalid primary nid - '$nid'"
964                 do_lnetctl peer add --prim_nid $nid &&
965                         error "Command should have failed"
966         done
967
968         local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
969         invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
970         invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
971
972         local nidstr
973         for nidstr in ${invalid_strs}; do
974                 echo "Check invalid nidstring - '$nidstr'"
975                 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
976                         error "Command should have failed"
977         done
978
979         echo "Add non-local gateway"
980         do_lnetctl route add --net tcp --gateway 1@gni &&
981                 error "Command should have failed"
982
983         return 0
984 }
985 run_test 99a "Check various invalid inputs to lnetctl peer"
986
987 test_99b() {
988         reinit_dlc || return $?
989
990         create_base_yaml_file
991
992         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
993 peer:
994     - primary nid: 99.99.99.99@tcp
995       Multi-Rail: Foobar
996       peer ni:
997         - nid: 99.99.99.99@tcp
998 EOF
999         do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1000                 error "import should have failed"
1001         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1002         compare_yaml_files
1003 }
1004 run_test 99b "Invalid value for Multi-Rail in yaml import"
1005
1006 have_interface() {
1007         local if="$1"
1008         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1009         [[ -n $ip ]]
1010 }
1011
1012 add_net() {
1013         local net="$1"
1014         local if="$2"
1015
1016         if ! lsmod | grep -q ksocklnd ; then
1017                 load_module ../lnet/klnds/socklnd/ksocklnd ||
1018                         error "Can't load ksocklnd.ko"
1019         fi
1020
1021         do_lnetctl net add --net ${net} --if ${if} ||
1022                 error "Failed to add net ${net} on if ${if}"
1023 }
1024
1025 compare_route_add() {
1026         local rnet="$1"
1027         local gw="$2"
1028
1029         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1030
1031         do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1032                 error "route add failed $?"
1033         # CPT configuration is pruned from the exported yaml, since the default
1034         # can vary across test systems (unlike default values for things like
1035         # peer_credits, peer_timeout, etc.)
1036         $LNETCTL export --backup | grep -v CPT > $actual ||
1037                 error "export failed $?"
1038         validate_gateway_nids
1039         return $?
1040 }
1041
1042 test_100() {
1043         reinit_dlc || return $?
1044         add_net "tcp" "${INTERFACES[0]}"
1045         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1046 net:
1047     - net type: tcp
1048       local NI(s):
1049         - interfaces:
1050               0: ${INTERFACES[0]}
1051           tunables:
1052               peer_timeout: 180
1053               peer_credits: 8
1054               peer_buffer_credits: 0
1055               credits: 256
1056           lnd tunables:
1057               conns_per_peer: 1
1058 route:
1059     - net: tcp7
1060       gateway: 7.7.7.7@tcp
1061       hop: -1
1062       priority: 0
1063       health_sensitivity: 1
1064 peer:
1065     - primary nid: 7.7.7.7@tcp
1066       Multi-Rail: False
1067       peer ni:
1068         - nid: 7.7.7.7@tcp
1069 EOF
1070         append_global_yaml
1071         compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1072         compare_yaml_files
1073 }
1074 run_test 100 "Add route with single gw (tcp)"
1075
1076 test_101() {
1077         reinit_dlc || return $?
1078         add_net "tcp" "${INTERFACES[0]}"
1079         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1080 net:
1081     - net type: tcp
1082       local NI(s):
1083         - interfaces:
1084               0: ${INTERFACES[0]}
1085           tunables:
1086               peer_timeout: 180
1087               peer_credits: 8
1088               peer_buffer_credits: 0
1089               credits: 256
1090           lnd tunables:
1091               conns_per_peer: 1
1092 route:
1093     - net: tcp8
1094       gateway: 8.8.8.10@tcp
1095       hop: -1
1096       priority: 0
1097       health_sensitivity: 1
1098     - net: tcp8
1099       gateway: 8.8.8.9@tcp
1100       hop: -1
1101       priority: 0
1102       health_sensitivity: 1
1103     - net: tcp8
1104       gateway: 8.8.8.8@tcp
1105       hop: -1
1106       priority: 0
1107       health_sensitivity: 1
1108 peer:
1109     - primary nid: 8.8.8.9@tcp
1110       Multi-Rail: False
1111       peer ni:
1112         - nid: 8.8.8.9@tcp
1113     - primary nid: 8.8.8.10@tcp
1114       Multi-Rail: False
1115       peer ni:
1116         - nid: 8.8.8.10@tcp
1117     - primary nid: 8.8.8.8@tcp
1118       Multi-Rail: False
1119       peer ni:
1120         - nid: 8.8.8.8@tcp
1121 EOF
1122         append_global_yaml
1123         compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1124 }
1125 run_test 101 "Add route with multiple gw (tcp)"
1126
1127 compare_route_del() {
1128         local rnet="$1"
1129         local gw="$2"
1130
1131         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1132
1133         do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1134                 error "route del failed $?"
1135         $LNETCTL export --backup > $actual ||
1136                 error "export failed $?"
1137         validate_gateway_nids
1138 }
1139
1140 test_102() {
1141         reinit_dlc || return $?
1142         add_net "tcp" "${INTERFACES[0]}"
1143         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1144         do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1145                 error "route add failed $?"
1146         compare_route_del "tcp102" "102.102.102.102@tcp"
1147 }
1148 run_test 102 "Delete route with single gw (tcp)"
1149
1150 test_103() {
1151         reinit_dlc || return $?
1152         add_net "tcp" "${INTERFACES[0]}"
1153         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1154         do_lnetctl route add --net tcp103 \
1155                 --gateway 103.103.103.[103-120/4]@tcp ||
1156                 error "route add failed $?"
1157         compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1158 }
1159 run_test 103 "Delete route with multiple gw (tcp)"
1160
1161 test_104() {
1162         local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1163
1164         reinit_dlc || return $?
1165
1166         # Default value is '3'
1167         local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1168         [[ $val -ne 3 ]] &&
1169                 error "Expect 3 found $val"
1170
1171         echo "Set < 0;  Should fail"
1172         do_lnetctl set response_tracking -1 &&
1173                 error "should have failed $?"
1174
1175         reinit_dlc || return $?
1176         cat <<EOF > $tyaml
1177 global:
1178     response_tracking: -10
1179 EOF
1180         do_lnetctl import < $tyaml &&
1181                 error "should have failed $?"
1182
1183         echo "Check valid values; Should succeed"
1184         local i
1185         for ((i = 0; i < 4; i++)); do
1186                 reinit_dlc || return $?
1187                 do_lnetctl set response_tracking $i ||
1188                         error "should have succeeded $?"
1189                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1190                         error "Failed to set response_tracking to $i"
1191                 reinit_dlc || return $?
1192                 cat <<EOF > $tyaml
1193 global:
1194     response_tracking: $i
1195 EOF
1196                 do_lnetctl import < $tyaml ||
1197                         error "should have succeeded $?"
1198                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1199                         error "Failed to set response_tracking to $i"
1200         done
1201
1202         reinit_dlc || return $?
1203         echo "Set > 3; Should fail"
1204         do_lnetctl set response_tracking 4 &&
1205                 error "should have failed $?"
1206
1207         reinit_dlc || return $?
1208         cat <<EOF > $tyaml
1209 global:
1210     response_tracking: 10
1211 EOF
1212         do_lnetctl import < $tyaml &&
1213                 error "should have failed $?"
1214         return 0
1215 }
1216 run_test 104 "Set/check response_tracking param"
1217
1218 test_105() {
1219         reinit_dlc || return $?
1220         add_net "tcp" "${INTERFACES[0]}"
1221         do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1222                 error "route add failed $?"
1223         do_lnetctl peer add --prim 105.105.105.105@tcp &&
1224                 error "peer add should fail"
1225
1226         return 0
1227 }
1228 run_test 105 "Adding duplicate GW peer should fail"
1229
1230 test_106() {
1231         reinit_dlc || return $?
1232         add_net "tcp" "${INTERFACES[0]}"
1233         do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1234                 error "route add failed $?"
1235         do_lnetctl peer del --prim 106.106.106.106@tcp &&
1236                 error "peer del should fail"
1237
1238         return 0
1239 }
1240 run_test 106 "Deleting GW peer should fail"
1241
1242 test_200() {
1243         cleanup_lnet || exit 1
1244         load_lnet "networks=\"\""
1245         do_ns $LNETCTL lnet configure --all || exit 1
1246         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1247 }
1248 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1249
1250 test_201() {
1251         cleanup_lnet || exit 1
1252         load_lnet "networks=tcp($FAKE_IF)"
1253         do_ns $LNETCTL lnet configure --all || exit 1
1254         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1255 }
1256 run_test 201 "load lnet using networks module options in a non-default namespace"
1257
1258 test_202() {
1259         cleanup_lnet || exit 1
1260         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1261         do_ns $LNETCTL lnet configure --all || exit 1
1262         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1263 }
1264 run_test 202 "load lnet using ip2nets in a non-default namespace"
1265
1266
1267 ### Add the interfaces in the target namespace
1268
1269 test_203() {
1270         cleanup_lnet || exit 1
1271         load_lnet
1272         do_lnetctl lnet configure || exit 1
1273         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1274 }
1275 run_test 203 "add a network using an interface in the non-default namespace"
1276
1277 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1278 function save_lnet_params() {
1279         $LNETCTL global show | egrep -v '^global:$' |
1280                                sed 's/://' > $LNET_PARAMS_FILE
1281 }
1282
1283 function restore_lnet_params() {
1284         local param value
1285         while read param value; do
1286                 [[ $param == max_intf ]] && continue
1287                 [[ $param == lnd_timeout ]] && continue
1288                 $LNETCTL set ${param} ${value} ||
1289                         error "Failed to restore ${param} to ${value}"
1290         done < $LNET_PARAMS_FILE
1291 }
1292
1293 function lnet_health_pre() {
1294         save_lnet_params
1295
1296         # Lower transaction timeout to speed up test execution
1297         $LNETCTL set transaction_timeout 10 ||
1298                 error "Failed to set transaction_timeout $?"
1299
1300         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1301         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1302         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1303                       xargs echo | sed 's/ /+/g' | bc -l)
1304
1305         RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1306                        awk '/health value/{print $NF}' | xargs echo |
1307                        sed 's/ /+/g' | bc -l)
1308
1309         # Might not have any peers so initialize to zero.
1310         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1311
1312         return 0
1313 }
1314
1315 function lnet_health_post() {
1316         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1317         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1318                        awk '/health value/{print $NF}' |
1319                        xargs echo | sed 's/ /+/g' | bc -l)
1320
1321         RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1322                         awk '/health value/{print $NF}' | xargs echo |
1323                         sed 's/ /+/g' | bc -l)
1324
1325         # Might not have any peers so initialize to zero.
1326         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1327
1328         ${VERBOSE} &&
1329         echo "Pre resends: $RSND_PRE" &&
1330         echo "Post resends: $RSND_POST" &&
1331         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1332         echo "Pre local health: $LO_HVAL_PRE" &&
1333         echo "Post local health: $LO_HVAL_POST" &&
1334         echo "Pre remote health: $RMT_HVAL_PRE" &&
1335         echo "Post remote health: $RMT_HVAL_POST"
1336
1337         restore_lnet_params
1338
1339         do_lnetctl peer set --health 1000 --all
1340         do_lnetctl net set --health 1000 --all
1341
1342         return 0
1343 }
1344
1345 function check_no_resends() {
1346         echo "Check that no resends took place"
1347         [[ $RSND_POST -ne $RSND_PRE ]] &&
1348                 error "Found resends: $RSND_POST != $RSND_PRE"
1349
1350         return 0
1351 }
1352
1353 function check_resends() {
1354         local delta=$((RSND_POST - RSND_PRE))
1355
1356         echo "Check that $RETRY_PARAM resends took place"
1357         [[ $delta -ne $RETRY_PARAM ]] &&
1358                 error "Expected $RETRY_PARAM resends found $delta"
1359
1360         return 0
1361 }
1362
1363 function check_no_local_health() {
1364         echo "Check that local NI health is unchanged"
1365         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1366                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1367
1368         return 0
1369 }
1370
1371 function check_local_health() {
1372         echo "Check that local NI health has been changed"
1373         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1374                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1375
1376         return 0
1377 }
1378
1379 function check_no_remote_health() {
1380         echo "Check that remote NI health is unchanged"
1381         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1382                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1383
1384         return 0
1385 }
1386
1387 function check_remote_health() {
1388         echo "Check that remote NI health has been changed"
1389         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1390                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1391
1392         return 0
1393 }
1394
1395 RNODE=""
1396 RLOADED=false
1397 NET_DEL_ARGS=""
1398 RNIDS=( )
1399 LNIDS=( )
1400 setup_health_test() {
1401         local need_mr=$1
1402         local rc=0
1403
1404         local rnodes=$(remote_nodes_list)
1405         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1406
1407         cleanup_lnet || error "Failed to cleanup before test execution"
1408
1409         # Loading modules should configure LNet with the appropriate
1410         # test-framework configuration
1411         load_lnet "config_on_load=1" || error "Failed to load modules"
1412
1413         LNIDS=( $($LCTL list_nids | xargs echo) )
1414
1415         RNODE=$(awk '{print $1}' <<<$rnodes)
1416         RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1417
1418         if [[ -z ${RNIDS[@]} ]]; then
1419                 do_rpc_nodes $RNODE load_lnet "config_on_load=1"
1420                 RLOADED=true
1421                 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1422         fi
1423
1424         [[ ${#LNIDS[@]} -lt 1 ]] &&
1425                 error "No NIDs configured for local host $HOSTNAME"
1426         [[ ${#RNIDS[@]} -lt 1 ]] &&
1427                 error "No NIDs configured for remote host $RNODE"
1428
1429         do_lnetctl discover ${RNIDS[0]} ||
1430                 error "Unable to discover ${RNIDS[0]}"
1431
1432         local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1433                    awk '/Multi-Rail/{print $NF}')
1434
1435         if ${need_mr} && [[ $mr == False ]]; then
1436                 cleanup_health_test || return $?
1437                 skip "Need MR peer"
1438         fi
1439
1440         if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1441            ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1442                 cleanup_health_test || return $?
1443                 skip "Need SR peer"
1444         fi
1445
1446         if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1447                 # Add a second, reachable NID to rnode.
1448                 local net=${RNIDS[0]}
1449
1450                 net="${net//*@/}1"
1451
1452                 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1453                 [[ -z $if ]] &&
1454                         error "Failed to determine interface for $RNODE"
1455
1456                 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1457                 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1458                         rc=$?
1459                 if [[ $rc -ne 0 ]]; then
1460                         error "Failed to add interface to $RNODE rc=$?"
1461                 else
1462                         RNIDS[1]="${RNIDS[0]}1"
1463                         NET_DEL_ARGS="--net $net --if $if"
1464                 fi
1465         fi
1466
1467         if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1468                 local net=${LNIDS[0]}
1469                 net="${net//*@/}1"
1470
1471                 do_lnetctl lnet configure &&
1472                         do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1473                         rc=$?
1474                 if [[ $rc -ne 0 ]]; then
1475                         error "Failed to add interface rc=$?"
1476                 else
1477                         LNIDS[1]="${LNIDS[0]}1"
1478                 fi
1479         fi
1480
1481         $LNETCTL net show
1482
1483         $LNETCTL peer show -v 2 | egrep -e nid -e health
1484
1485         $LCTL set_param debug=+net
1486
1487         return 0
1488
1489 }
1490
1491 cleanup_health_test() {
1492         local rc=0
1493
1494         if [[ -n $NET_DEL_ARGS ]]; then
1495                 do_rpc_nodes $RNODE \
1496                         "$LNETCTL net del $NET_DEL_ARGS" ||
1497                         rc=$((rc + $?))
1498                 NET_DEL_ARGS=""
1499         fi
1500
1501         unload_modules || rc=$?
1502
1503         if $RLOADED; then
1504                 do_rpc_nodes $RNODE unload_modules_local ||
1505                         rc=$((rc + $?))
1506                 RLOADED=false
1507         fi
1508
1509         [[ $rc -ne 0 ]] &&
1510                 error "Failed cleanup"
1511
1512         return $rc
1513 }
1514
1515 add_health_test_drop_rules() {
1516         local hstatus=$1
1517         local lnid rnid
1518
1519         for lnid in "${LNIDS[@]}"; do
1520                 for rnid in "${RNIDS[@]}"; do
1521                         $LCTL net_drop_add -s $lnid -d $rnid -m GET -r 1 -e ${hstatus}
1522                 done
1523         done
1524 }
1525
1526 # See lnet/lnet/lib-msg.c:lnet_health_check()
1527 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1528 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1529 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1530 test_204() {
1531         setup_health_test false || return $?
1532
1533         local hstatus
1534         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1535                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1536                 echo "Simulate $hstatus"
1537                 lnet_health_pre || return $?
1538
1539                 add_health_test_drop_rules ${hstatus}
1540                 do_lnetctl discover ${RNIDS[0]} &&
1541                         error "Should have failed"
1542                 $LCTL net_drop_del -a
1543
1544                 lnet_health_post
1545
1546                 check_no_resends || return $?
1547                 check_no_local_health || return $?
1548         done
1549
1550         cleanup_health_test || return $?
1551
1552         return 0
1553 }
1554 run_test 204 "Check no health or resends for single-rail local failures"
1555
1556 test_205() {
1557         setup_health_test true || return $?
1558
1559         local hstatus
1560         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1561                 echo "Simulate $hstatus"
1562                 lnet_health_pre || return $?
1563
1564                 add_health_test_drop_rules ${hstatus}
1565                 do_lnetctl discover ${RNIDS[0]} &&
1566                         error "Should have failed"
1567                 $LCTL net_drop_del -a
1568
1569                 lnet_health_post
1570
1571                 check_resends || return $?
1572                 check_local_health || return $?
1573         done
1574
1575         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1576                 echo "Simulate $hstatus"
1577                 lnet_health_pre || return $?
1578
1579                 add_health_test_drop_rules ${hstatus}
1580                 do_lnetctl discover ${RNIDS[0]} &&
1581                         error "Should have failed"
1582                 $LCTL net_drop_del -a
1583
1584                 lnet_health_post
1585
1586                 check_no_resends || return $?
1587                 check_local_health || return $?
1588         done
1589
1590         cleanup_health_test || return $?
1591
1592         return 0
1593 }
1594 run_test 205 "Check health and resends for multi-rail local failures"
1595
1596 # See lnet/lnet/lib-msg.c:lnet_health_check()
1597 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1598 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1599 test_206() {
1600         setup_health_test false || return $?
1601
1602         local hstatus
1603         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1604                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1605                 echo "Simulate $hstatus"
1606                 lnet_health_pre || return $?
1607
1608                 add_health_test_drop_rules ${hstatus}
1609                 do_lnetctl discover ${RNIDS[0]} &&
1610                         error "Should have failed"
1611                 $LCTL net_drop_del -a
1612
1613                 lnet_health_post
1614
1615                 check_no_resends || return $?
1616                 check_no_local_health || return $?
1617                 check_no_remote_health || return $?
1618         done
1619
1620         cleanup_health_test || return $?
1621
1622         return 0
1623 }
1624 run_test 206 "Check no health or resends for single-rail remote failures"
1625
1626 test_207() {
1627         setup_health_test true || return $?
1628
1629         local hstatus
1630         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1631                 echo "Simulate $hstatus"
1632                 lnet_health_pre || return $?
1633
1634                 add_health_test_drop_rules ${hstatus}
1635
1636                 do_lnetctl discover ${RNIDS[0]} &&
1637                         error "Should have failed"
1638
1639                 lnet_health_post
1640
1641                 $LCTL net_drop_del -a
1642
1643                 check_resends || return $?
1644                 check_no_local_health || return $?
1645                 check_remote_health || return $?
1646                 do_lnetctl peer set --health 1000 --all ||
1647                         error "Unable to reset health rc=$?"
1648         done
1649         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1650                 echo "Simulate $hstatus"
1651                 lnet_health_pre || return $?
1652
1653                 add_health_test_drop_rules ${hstatus}
1654
1655                 do_lnetctl discover ${RNIDS[0]} &&
1656                         error "Should have failed"
1657
1658                 lnet_health_post
1659
1660                 $LCTL net_drop_del -a
1661
1662                 check_no_resends || return $?
1663                 check_no_local_health || return $?
1664                 check_remote_health || return $?
1665                 do_lnetctl peer set --health 1000 --all ||
1666                         error "Unable to reset health rc=$?"
1667         done
1668
1669         cleanup_health_test || return $?
1670
1671         return 0
1672 }
1673 run_test 207 "Check health and resends for multi-rail remote errors"
1674
1675 test_208_load_and_check_lnet() {
1676         local ip2nets="$1"
1677         local p_nid="$2"
1678         local s_nid="$3"
1679         local num_expected=1
1680
1681         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1682
1683         $LCTL net up ||
1684                 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1685
1686         [[ -n $s_nid ]] &&
1687                 num_expected=2
1688
1689         declare -a nids
1690         nids=( $($LCTL list_nids) )
1691
1692         [[ ${#nids[@]} -ne ${num_expected} ]] &&
1693                 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1694
1695         [[ ${nids[0]} == ${p_nid} ]] ||
1696                 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1697
1698         [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1699                 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1700
1701         $LCTL net down &>/dev/null
1702         cleanup_lnet
1703 }
1704
1705 test_208() {
1706         cleanup_netns || error "Failed to cleanup netns before test execution"
1707         cleanup_lnet || error "Failed to unload modules before test execution"
1708         setup_fakeif || error "Failed to add fake IF"
1709
1710         have_interface "$FAKE_IF" ||
1711                 error "Expect $FAKE_IF configured but not found"
1712
1713         local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1714                        awk '/inet /{print $4}' |
1715                        sed 's:/.*::')
1716         if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1717         local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1718
1719         echo "Configure single NID \"$ip2nets_str\""
1720         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1721
1722         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1723         echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1724         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1725                                      "${FAKE_IP}@tcp1"
1726
1727         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1728         echo "Configure two NIDs; one NET \"$ip2nets_str\""
1729         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1730                                      "${FAKE_IP}@tcp"
1731         local addr1=( ${if0_ip//./ } )
1732         local addr2=( ${FAKE_IP//./ } )
1733         local range="[${addr1[0]},${addr2[0]}]"
1734
1735         local i
1736         for i in $(seq 1 3); do
1737                 range+=".[${addr1[$i]},${addr2[$i]}]"
1738         done
1739         ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1740
1741         echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1742         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1743                                      "${FAKE_IP}@tcp"
1744
1745         cleanup_fakeif
1746
1747         echo "alt syntax with missing IF \"$ip2nets_str\""
1748         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1749
1750         echo "$LCTL net up should fail"
1751         $LCTL net up &&
1752                 error "LNet bringup should have failed"
1753
1754         cleanup_lnet
1755 }
1756 run_test 208 "Test various kernel ip2nets configurations"
1757
1758 test_209() {
1759         setup_health_test false || return $?
1760
1761         echo "Simulate network_timeout w/SR config"
1762         lnet_health_pre
1763
1764         add_health_test_drop_rules network_timeout
1765
1766         do_lnetctl discover ${RNIDS[0]} &&
1767                 error "Should have failed"
1768         $LCTL net_drop_del -a
1769
1770         lnet_health_post
1771
1772         check_no_resends || return $?
1773         check_no_local_health || return $?
1774         check_no_remote_health || return $?
1775
1776         cleanup_health_test || return $?
1777
1778         setup_health_test true || return $?
1779
1780         echo "Simulate network_timeout w/MR config"
1781
1782         lnet_health_pre
1783
1784         add_health_test_drop_rules network_timeout
1785
1786         do_lnetctl discover ${RNIDS[0]} &&
1787                 error "Should have failed"
1788         $LCTL net_drop_del -a
1789
1790         lnet_health_post
1791
1792         check_no_resends || return $?
1793         check_local_health || return $?
1794         check_remote_health || return $?
1795
1796         cleanup_health_test || return $?
1797
1798         return 0
1799 }
1800 run_test 209 "Check health, but not resends, for network timeout"
1801
1802 check_nid_in_recovq() {
1803         local recovq=$($LNETCTL debug recovery $1)
1804         local expect="$2"
1805         local nids=$($LCTL list_nids | xargs echo)
1806         local found=false
1807         local nid=""
1808
1809         echo "Check \"$1\" recovery queue"
1810         echo "$recovq"
1811         if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1812                 error "Expect $expect NIDs found: \"$recovq\""
1813         fi
1814
1815         [[ $expect -eq 0 ]] && return 0
1816
1817         for nid in ${nids}; do
1818                 grep -q "nid-0: $nid"<<<$recovq &&
1819                         found=true
1820         done
1821
1822         if ! $found; then
1823                 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1824         fi
1825
1826         return 0
1827 }
1828
1829 # First enqueue happens at time 0.
1830 # 2nd at 0 + 2^0 = 1
1831 # 3rd at 1 + 2^1 = 3
1832 # 4th at 3 + 2^2 = 7
1833 # 5th at 7 + 2^3 = 15
1834 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1835 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1836 # happen
1837 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1838 # we expect the peer NI to have aged out, so it will not actually be
1839 # queued.
1840 # If max_recovery_ping_interval is set to 2 then:
1841 #  First enqueue happens at time 0.
1842 #  2nd at 0 + 2^0 = 1
1843 #  3rd at 1 + 2^1 = 3
1844 #  4th at 3 + 2^1 = 5
1845 #  5th at 5 + 2^1 = 7
1846 #  6th at 7 + 2^1 = 9
1847 #  7th at 9 + 2^1 = 11
1848 # e.g. after 4 seconds we would expect to have seen the 3th enqueue,
1849 # (2 pings sent, 3rd about to happen), and the 4th enqueue is yet to happen
1850 # e.g. after 10 seconds we would expect to have seen the 6th enqueue,
1851 # (5 pings sent, 6th about to happen), and the 8th enqueue is yet to happen
1852 check_ping_count() {
1853         local queue="$1"
1854         local expect="$2"
1855
1856         echo "Check ping counts:"
1857         local ping_count
1858         if [[ $queue == "ni" ]]; then
1859                 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1860                 ping_count=( $($LNETCTL net show -v 2 |
1861                                 awk '/ping_count/{print $NF}') )
1862         elif [[ $queue == "peer_ni" ]]; then
1863                 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1864                 ping_count=( $($LNETCTL peer show -v 2 |
1865                                 awk '/ping_count/{print $NF}') )
1866         else
1867                 error "Unrecognized queue \"$queue\""
1868                 return 1
1869         fi
1870
1871         local count
1872         local found=false
1873         for count in "${ping_count[@]}"; do
1874                 if [[ $count -eq $expect ]]; then
1875                         if [[ $expect -ne 0 ]] && $found ; then
1876                                 error "Found more than one interface matching \"$expect\" ping count"
1877                                 return 1
1878                         else
1879                                 echo "Expect ping count \"$expect\" found \"$count\""
1880                                 found=true;
1881                         fi
1882                 elif [[ $count -ne 0 ]]; then
1883                         error "Found interface with ping count \"$count\" but expect \"$expect\""
1884                         return 1
1885                 fi
1886         done
1887
1888         return 0
1889 }
1890
1891 test_210() {
1892         reinit_dlc || return $?
1893         add_net "tcp" "${INTERFACES[0]}" || return $?
1894         add_net "tcp1" "${INTERFACES[0]}" || return $?
1895
1896         local prim_nid=$($LCTL list_nids | head -n 1)
1897
1898         do_lnetctl discover $prim_nid ||
1899                 error "failed to discover myself"
1900
1901         local default=$($LNETCTL global show |
1902                         awk '/recovery_limit/{print $NF}')
1903         # Set recovery limit to 10 seconds.
1904         do_lnetctl set recovery_limit 10 ||
1905                 error "failed to set recovery_limit"
1906
1907         $LCTL set_param debug=+net
1908         # Use local_error so LNet doesn't attempt to resend the discovery ping
1909         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1910         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1911         do_lnetctl discover $prim_nid &&
1912                 error "Expected discovery to fail"
1913
1914         # See comment for check_ping_count()
1915         sleep 5
1916         check_nid_in_recovq "-l" "1"
1917         check_ping_count "ni" "2"
1918
1919         sleep 5
1920
1921         check_nid_in_recovq "-l" "1"
1922         check_ping_count "ni" "3"
1923
1924         $LCTL net_drop_del -a
1925
1926         reinit_dlc || return $?
1927         add_net "tcp" "${INTERFACES[0]}" || return $?
1928         add_net "tcp1" "${INTERFACES[0]}" || return $?
1929
1930         local prim_nid=$($LCTL list_nids | head -n 1)
1931
1932         do_lnetctl discover $prim_nid ||
1933                 error "failed to discover myself"
1934
1935         do_lnetctl set recovery_limit $default ||
1936                 error "failed to set recovery_limit"
1937
1938         default=$($LNETCTL global show |
1939                   awk '/max_recovery_ping_interval/{print $NF}')
1940         do_lnetctl set max_recovery_ping_interval 2 ||
1941                 error "failed to set max_recovery_ping_interval"
1942
1943         $LCTL set_param debug=+net
1944         # Use local_error so LNet doesn't attempt to resend the discovery ping
1945         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1946         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1947         do_lnetctl discover $prim_nid &&
1948                 error "Expected discovery to fail"
1949
1950         # See comment for check_ping_count()
1951         sleep 4
1952         check_nid_in_recovq "-l" "1"
1953         check_ping_count "ni" "2"
1954
1955         sleep 6
1956         check_nid_in_recovq "-l" "1"
1957         check_ping_count "ni" "5"
1958
1959         $LCTL net_drop_del -a
1960
1961         do_lnetctl set max_recovery_ping_interval $default ||
1962                 error "failed to set max_recovery_ping_interval"
1963
1964         return 0
1965 }
1966 run_test 210 "Local NI recovery checks"
1967
1968 test_211() {
1969         reinit_dlc || return $?
1970         add_net "tcp" "${INTERFACES[0]}" || return $?
1971         add_net "tcp1" "${INTERFACES[0]}" || return $?
1972
1973         local prim_nid=$($LCTL list_nids | head -n 1)
1974
1975         do_lnetctl discover $prim_nid ||
1976                 error "failed to discover myself"
1977
1978         local default=$($LNETCTL global show |
1979                         awk '/recovery_limit/{print $NF}')
1980         # Set recovery limit to 10 seconds.
1981         do_lnetctl set recovery_limit 10 ||
1982                 error "failed to set recovery_limit"
1983
1984         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1985         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1986
1987         # Set health to 0 on one interface. This forces it onto the recovery
1988         # queue.
1989         $LNETCTL peer set --nid $prim_nid --health 0
1990
1991         # After 5 seconds, we expect the peer NI to still be in recovery
1992         sleep 5
1993         check_nid_in_recovq "-p" 1
1994         check_ping_count "peer_ni" "2"
1995
1996         # After 15 seconds, the peer NI should have been fully processed out of
1997         # the recovery queue. We'll allow a total of 17 seconds to account for
1998         # differences in sleeping for whole seconds vs. the more accurate time
1999         # keeping that is done in the recovery code.
2000         sleep 12
2001         check_nid_in_recovq "-p" 0
2002         check_ping_count "peer_ni" "4"
2003
2004         $LCTL net_drop_del -a
2005
2006         # Set health to force it back onto the recovery queue. Set to 500 means
2007         # in 5 seconds it should be back at maximum value. We'll wait a couple
2008         # more seconds than that to be safe.
2009         # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
2010         # eligible again
2011         do_lnetctl set recovery_limit 0 ||
2012                 error "failed to set recovery_limit"
2013
2014         $LNETCTL peer set --nid $prim_nid --health 500
2015
2016         check_nid_in_recovq "-p" 1
2017         check_ping_count "peer_ni" "2"
2018
2019         sleep 7
2020
2021         check_nid_in_recovq "-p" 0
2022         check_ping_count "peer_ni" "0"
2023
2024         reinit_dlc || return $?
2025         add_net "tcp" "${INTERFACES[0]}" || return $?
2026         add_net "tcp1" "${INTERFACES[0]}" || return $?
2027
2028         local prim_nid=$($LCTL list_nids | head -n 1)
2029
2030         do_lnetctl discover $prim_nid ||
2031                 error "failed to discover myself"
2032
2033         do_lnetctl set recovery_limit $default ||
2034                 error "failed to set recovery_limit"
2035
2036         default=$($LNETCTL global show |
2037                   awk '/max_recovery_ping_interval/{print $NF}')
2038         do_lnetctl set max_recovery_ping_interval 2 ||
2039                 error "failed to set max_recovery_ping_interval"
2040
2041         $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
2042         $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
2043
2044         # Set health to 0 on one interface. This forces it onto the recovery
2045         # queue.
2046         $LNETCTL peer set --nid $prim_nid --health 0
2047
2048         # See comment for check_ping_count()
2049         sleep 4
2050         check_nid_in_recovq "-p" "1"
2051         check_ping_count "peer_ni" "2"
2052
2053         sleep 6
2054         check_nid_in_recovq "-p" "1"
2055         check_ping_count "peer_ni" "5"
2056
2057         $LCTL net_drop_del -a
2058
2059         do_lnetctl set max_recovery_ping_interval $default ||
2060                 error "failed to set max_recovery_ping_interval"
2061
2062         return 0
2063 }
2064 run_test 211 "Remote NI recovery checks"
2065
2066 test_212() {
2067         local rnodes=$(remote_nodes_list)
2068         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
2069
2070         cleanup_lnet || error "Failed to cleanup before test execution"
2071
2072         # Loading modules should configure LNet with the appropriate
2073         # test-framework configuration
2074         load_lnet "config_on_load=1" || error "Failed to load modules"
2075
2076         local my_nid=$($LCTL list_nids | head -n 1)
2077         [[ -z $my_nid ]] &&
2078                 error "Failed to get primary NID for local host $HOSTNAME"
2079
2080         local rnode=$(awk '{print $1}' <<<$rnodes)
2081         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2082         local rloaded=false
2083
2084         if [[ -z $rnodenids ]]; then
2085                 do_rpc_nodes $rnode load_lnet "config_on_load=1"
2086                 rloaded=true
2087                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2088         fi
2089
2090         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
2091
2092         [[ -z $rnodepnid ]] &&
2093                 error "Failed to get primary NID for remote host $rnode"
2094
2095         log "Initial discovery"
2096         do_lnetctl discover --force $rnodepnid ||
2097                 error "Failed to discover $rnodepnid"
2098
2099         do_node $rnode "$LNETCTL discover --force $my_nid" ||
2100                 error "$rnode failed to discover $my_nid"
2101
2102         log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2103         $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2104         do_lnetctl discover --force $rnodepnid &&
2105                 error "Discovery should have failed"
2106         $LCTL net_drop_del -a
2107
2108         local nid
2109         for nid in $rnodenids; do
2110                 # We need GET (PING) delay just long enough so we can trigger
2111                 # discovery on the remote peer
2112                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2113                 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2114                 # We need PUT (PUSH) delay just long enough so we can process
2115                 # the PING failure
2116                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2117         done
2118
2119         log "Force $HOSTNAME to discover $rnodepnid (in background)"
2120         # We want to get a PING sent that we know will eventually fail.
2121         # The delay rules we added will ensure the ping is not sent until
2122         # the PUSH is also in flight (see below), and the drop rule ensures that
2123         # when the PING is eventually sent it will error out
2124         do_lnetctl discover --force $rnodepnid &
2125         local pid1=$!
2126
2127         # We want a discovery PUSH from rnode to put rnode back on our
2128         # discovery queue. This should cause us to try and send a PUSH to rnode
2129         # while the PING is still outstanding.
2130         log "Force $rnode to discover $my_nid"
2131         do_node $rnode $LNETCTL discover --force $my_nid
2132
2133         # At this point we'll have both PING_SENT and PUSH_SENT set for the
2134         # rnode peer. Wait for the PING to error out which should terminate the
2135         # discovery process that we backgrounded.
2136         log "Wait for $pid1"
2137         wait $pid1
2138         log "Finished wait on $pid1"
2139
2140         # The PING send failure clears the PING_SENT flag and puts the peer back
2141         # on the discovery queue. When discovery thread processes the peer it
2142         # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2143         # Discovery will then complete for this peer even though we have an
2144         # outstanding PUSH.
2145         # When PUSH is actually unlinked it will be forced back onto the
2146         # discovery queue, but we no longer have a ref on the peer. When
2147         # discovery completes again, we'll trip the ASSERT in
2148         # lnet_destroy_peer_locked()
2149
2150         # Delete the delay rules to send the PUSH
2151         $LCTL net_delay_del -a
2152         # Delete the drop rules
2153         $LCTL net_drop_del -a
2154
2155         unload_modules ||
2156                 error "Failed to unload modules"
2157         if $rloaded; then
2158                 do_rpc_nodes $rnode unload_modules_local ||
2159                         error "Failed to unload modules on $rnode"
2160         fi
2161
2162         return 0
2163 }
2164 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2165
2166 test_213() {
2167         cleanup_netns || error "Failed to cleanup netns before test execution"
2168         cleanup_lnet || error "Failed to unload modules before test execution"
2169
2170         setup_fakeif || error "Failed to add fake IF"
2171         have_interface "$FAKE_IF" ||
2172                 error "Expect $FAKE_IF configured but not found"
2173
2174         reinit_dlc || return $?
2175
2176         add_net "tcp" "${INTERFACES[0]}" || return $?
2177         add_net "tcp" "$FAKE_IF" || return $?
2178
2179         local nid1=$(lctl list_nids | head -n 1)
2180         local nid2=$(lctl list_nids | tail --lines 1)
2181
2182         [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2183                 error "Expect nid1 \"$nid1\" to be preferred"
2184
2185         [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2186                 error "Expect nid2 \"$nid2\" to be preferred"
2187
2188         return 0
2189 }
2190 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2191
2192 function check_ni_status() {
2193         local nid="$1"
2194         local expect="$2"
2195
2196         local status=$($LNETCTL net show |
2197                        grep -A 1 ${nid} |
2198                        awk '/status/{print $NF}')
2199
2200         echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2201         if [[ $status != $expect ]]; then
2202                 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2203         fi
2204
2205         return 0
2206 }
2207
2208 test_214() {
2209         cleanup_netns || error "Failed to cleanup netns before test execution"
2210         cleanup_lnet || error "Failed to unload modules before test execution"
2211
2212         setup_fakeif || error "Failed to add fake IF"
2213         have_interface "$FAKE_IF" ||
2214                 error "Expect $FAKE_IF configured but not found"
2215
2216         reinit_dlc || return $?
2217
2218         add_net "tcp" "${INTERFACES[0]}" || return $?
2219         add_net "tcp" "$FAKE_IF" || return $?
2220
2221         local nid1=$(lctl list_nids | head -n 1)
2222         local nid2=$(lctl list_nids | tail --lines 1)
2223
2224         check_ni_status "0@lo" up
2225         check_ni_status "$nid1" up
2226         check_ni_status "$nid2" up
2227
2228         echo "Set $FAKE_IF down"
2229         echo "ip link set dev $FAKE_IF down"
2230         ip link set dev $FAKE_IF down
2231         check_ni_status "0@lo" up
2232         check_ni_status "$nid1" up
2233         check_ni_status "$nid2" down
2234 }
2235 run_test 214 "Check local NI status when link is downed"
2236
2237 get_ni_stat() {
2238         local nid=$1
2239         local stat=$2
2240
2241         $LNETCTL net show -v 2 |
2242                 egrep -e nid -e $stat |
2243                 grep -wA 1 $nid |
2244                 awk '/'$stat':/{print $NF}'
2245 }
2246
2247 ni_stats_pre() {
2248         local nidvar s
2249         for nidvar in nid1 nid2; do
2250                 for stat in send_count recv_count; do
2251                         s=$(get_ni_stat ${!nidvar} $stat)
2252                         eval ${nidvar}_pre_${stat}=$s
2253                 done
2254         done
2255 }
2256
2257 ni_stats_post() {
2258         local nidvar s
2259         for nidvar in nid1 nid2; do
2260                 for stat in send_count recv_count; do
2261                         s=$(get_ni_stat ${!nidvar} $stat)
2262                         eval ${nidvar}_post_${stat}=$s
2263                 done
2264         done
2265 }
2266
2267 ni_stat_changed() {
2268         local nidvar=$1
2269         local stat=$2
2270
2271         local pre post
2272         eval pre=\${${nidvar}_pre_${stat}}
2273         eval post=\${${nidvar}_post_${stat}}
2274
2275         echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2276
2277         [[ $pre -ne $post ]]
2278 }
2279
2280 test_215() {
2281         cleanup_netns || error "Failed to cleanup netns before test execution"
2282         cleanup_lnet || error "Failed to unload modules before test execution"
2283
2284         reinit_dlc || return $?
2285
2286         add_net "tcp1" "${INTERFACES[0]}" || return $?
2287         add_net "tcp2" "${INTERFACES[0]}" || return $?
2288
2289         local nid1=$($LCTL list_nids | head -n 1)
2290         local nid2=$($LCTL list_nids | tail --lines 1)
2291
2292         do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2293                 error "Failed to add peer"
2294
2295         local npings=25
2296
2297         for nidvarA in nid1 nid2; do
2298                 src=${!nidvarA}
2299                 dst=${!nidvarA}
2300                 for nidvarB in nid1 nid2; do
2301                         [[ $nidvarA == $nidvarB ]] && continue
2302
2303                         ni_stats_pre
2304
2305                         echo "$LNETCTL ping $dst x $npings"
2306                         for i in $(seq 1 $npings); do
2307                                 $LNETCTL ping $dst &>/dev/null ||
2308                                         error "$LNETCTL ping $dst failed"
2309                         done
2310
2311                         ni_stats_post
2312
2313                         # No source specified, sends to either NID should cause
2314                         # counts to increase across both NIs
2315                         for nidvar in nid1 nid2; do
2316                                 for stat in send_count recv_count; do
2317                                         ni_stat_changed $nidvar $stat ||
2318                                                 error "$stat unchanged for ${!nidvar}"
2319                                 done
2320                         done
2321
2322                         ni_stats_pre
2323
2324                         echo "$LNETCTL ping --source $src $dst x $npings"
2325                         for i in $(seq 1 $npings); do
2326                                 $LNETCTL ping --source $src $dst &>/dev/null ||
2327                                         error "$LNETCTL ping --source $src $dst failed"
2328                         done
2329
2330                         ni_stats_post
2331
2332                         # src nid == dest nid means stats for the _other_ NI
2333                         # should be unchanged
2334                         for nidvar in nid1 nid2; do
2335                                 for stat in send_count recv_count; do
2336                                         if [[ ${!nidvar} == $src ]]; then
2337                                                 ni_stat_changed $nidvar $stat ||
2338                                                         error "$stat unchanged for ${!nidvar}"
2339                                         else
2340                                                 ni_stat_changed $nidvar $stat &&
2341                                                         error "$stat changed for ${!nidvar}"
2342                                         fi
2343                                 done
2344                         done
2345                 done
2346                 # Double number of pings for next iteration because the net
2347                 # sequence numbers will have diverged
2348                 npings=$(($npings * 2))
2349         done
2350
2351         # Ping from nid1 to nid2 should fail
2352         do_lnetctl ping --source $nid1 $nid2 &&
2353                 error "ping from $nid1 to $nid2 should fail"
2354
2355         # Ping from nid2 to nid1 should fail
2356         do_lnetctl ping --source $nid2 $nid1 &&
2357                 error "ping from $nid2 to $nid1 should fail"
2358
2359         return 0
2360 }
2361 run_test 215 "Test lnetctl ping --source option"
2362
2363 test_216() {
2364         local rc=0
2365
2366         reinit_dlc || return $?
2367
2368         add_net "tcp" "${INTERFACES[0]}" || return $?
2369         add_net "tcp1" "${INTERFACES[0]}" || return $?
2370
2371         local nids=( $($LCTL list_nids | xargs echo) )
2372
2373         do_lnetctl discover ${nids[0]} ||
2374                 error "Initial discovery failed"
2375
2376         do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2377                 error "Initial ping failed $?"
2378
2379         do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2380                 error "Initial ping failed $?"
2381
2382         local src dst
2383         for src in "${nids[@]}"; do
2384                 for dst in "${nids[@]}"; do
2385                         $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2386                 done
2387         done
2388
2389         do_lnetctl ping ${nids[0]} || rc=$?
2390
2391         $LCTL net_drop_del -a
2392
2393         [[ $rc -eq 0 ]] &&
2394                 error "expected ping to fail"
2395
2396         check_nid_in_recovq "-p" 0
2397         check_nid_in_recovq "-l" 1
2398
2399         return 0
2400 }
2401 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2402
2403 test_217() {
2404         reinit_dlc || return $?
2405
2406         [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2407                 error "Unexpected number of NIs after initalizing DLC"
2408
2409         do_lnetctl discover 0@lo ||
2410                 error "Failed to discover 0@lo"
2411
2412         unload_modules
2413 }
2414 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2415
2416 test_218() {
2417         reinit_dlc || return $?
2418
2419         [[ ${#INTERFACES[@]} -lt 2 ]] &&
2420                 skip "Need two LNet interfaces"
2421
2422         add_net "tcp" "${INTERFACES[0]}" || return $?
2423
2424         local nid1=$($LCTL list_nids | head -n 1)
2425
2426         do_lnetctl ping $nid1 ||
2427                 error "ping failed"
2428
2429         add_net "tcp" "${INTERFACES[1]}" || return $?
2430
2431         local nid2=$($LCTL list_nids | tail --lines 1)
2432
2433         do_lnetctl ping $nid2 ||
2434                 error "ping failed"
2435
2436         $LCTL net_drop_add -s $nid1 -d $nid1 -e local_error -r 1
2437
2438         do_lnetctl ping $nid1 &&
2439                 error "ping should have failed"
2440
2441         local health_recovered
2442         local i
2443
2444         for i in $(seq 1 5); do
2445                 health_recovered=$($LNETCTL net show -v 2 |
2446                                    grep -c 'health value: 1000')
2447
2448                 if [[ $health_recovered -ne 2 ]]; then
2449                         echo "Wait 1 second for health to recover"
2450                         sleep 1
2451                 else
2452                         break
2453                 fi
2454         done
2455
2456         health_recovered=$($LNETCTL net show -v 2 |
2457                            grep -c 'health value: 1000')
2458
2459         $LCTL net_drop_del -a
2460
2461         [[ $health_recovered -ne 2 ]] &&
2462                 do_lnetctl net show -v 2 | egrep -e nid -e health &&
2463                 error "Health hasn't recovered"
2464
2465         return 0
2466 }
2467 run_test 218 "Local recovery pings should exercise all available paths"
2468
2469 test_219() {
2470         reinit_dlc || return $?
2471         add_net "tcp" "${INTERFACES[0]}" || return $?
2472         add_net "tcp1" "${INTERFACES[0]}" || return $?
2473
2474         local nid1=$(lctl list_nids | head -n 1)
2475         local nid2=$(lctl list_nids | tail --lines 1)
2476
2477         do_lnetctl ping $nid1 ||
2478                 error "Ping failed $?"
2479         do_lnetctl ping $nid2 ||
2480                 error "Ping failed $?"
2481
2482         do_lnetctl discover $nid2 ||
2483                 error "Discovery failed"
2484
2485         $LNETCTL peer show --nid $nid1 | grep -q $nid2 ||
2486                 error "$nid2 is not listed under $nid1"
2487 }
2488 run_test 219 "Consolidate peer entries"
2489
2490 test_230() {
2491         # LU-12815
2492         echo "Check valid values; Should succeed"
2493         local i
2494         local lnid
2495         local cmd
2496         for ((i = 4; i < 16; i+=1)); do
2497                 reinit_dlc || return $?
2498                 add_net "tcp" "${INTERFACES[0]}" || return $?
2499                 do_lnetctl net set --all --conns-per-peer $i ||
2500                         error "should have succeeded $?"
2501                 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2502                         error "failed to set conns-per-peer to $i"
2503                 lnid="$(lctl list_nids | head -n 1)"
2504                 do_lnetctl ping "$lnid" ||
2505                         error "failed to ping myself"
2506
2507                 # "lctl --net tcp conn_list" prints the list of active
2508                 # connections. Since we're pinging ourselves, there should be
2509                 # 2 Control connections plus 2*conns_per_peer connections
2510                 # created (one Bulk Input, one Bulk Output in each pair).
2511                 # Here's the sample output for conns_per_peer set to 1:
2512                 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2513                 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2514                 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2515                 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2516                 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2517
2518                 # Expect 2+conns_per_peer*2 connections. Wait no longer
2519                 # than 2 seconds.
2520                 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2521                         error "expected number of tcp connections $((2+i*2))"
2522         done
2523
2524         reinit_dlc || return $?
2525         add_net "tcp" "${INTERFACES[0]}" || return $?
2526         echo "Set > 127; Should fail"
2527         do_lnetctl net set --all --conns-per-peer 128 &&
2528                 error "should have failed $?"
2529
2530         reinit_dlc || return $?
2531         add_net "tcp" "${INTERFACES[0]}" || return $?
2532         echo "Set < 0; Should be ignored"
2533         do_lnetctl net set --all --conns-per-peer -1 ||
2534                 error "should have succeeded $?"
2535         $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
2536                 error "Did not stay at default"
2537 }
2538 run_test 230 "Test setting conns-per-peer"
2539
2540 ### Test that linux route is added for each ni
2541 test_250() {
2542         reinit_dlc || return $?
2543         add_net "tcp" "${INTERFACES[0]}" || return $?
2544         ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
2545 }
2546 run_test 250 "test that linux routes are added"
2547
2548 test_300() {
2549         # LU-13274
2550         local header
2551         local out=$TMP/$tfile
2552         local prefix=/usr/include/linux/lnet
2553
2554         # We use a hard coded prefix so that this test will not fail
2555         # when run in tree.
2556         CC=${CC:-cc}
2557         if ! which $CC > /dev/null 2>&1; then
2558                 skip_env "$CC is not installed"
2559         fi
2560
2561         cleanup_lnet || exit 1
2562         load_lnet
2563
2564         local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
2565         if ! [[ -d $prefix ]]; then
2566                 # Assume we're running in tree and fixup the include path.
2567                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
2568                 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
2569         fi
2570
2571         for header in $prefix/*.h; do
2572                 if ! [[ -f "$header" ]]; then
2573                         continue
2574                 fi
2575
2576                 echo "$CC $cc_args -include $header"
2577                 $CC $cc_args -include $header ||
2578                         error "cannot compile '$header'"
2579         done
2580         rm -f $out
2581 }
2582 run_test 300 "packaged LNet UAPI headers can be compiled"
2583
2584 complete $SECONDS
2585
2586 cleanup_testsuite
2587 exit_status