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