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