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