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