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