Whamcloud - gitweb
LU-2826 tests: add useful text to error() calls
[fs/lustre-release.git] / lustre / tests / sanity-gss.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 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test:
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"$SANITY_GSS_EXCEPT"}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13
14 SRCDIR=`dirname $0`
15 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../utils/gss:$PATH:/sbin
16 export NAME=${NAME:-local}
17 SAVE_PWD=$PWD
18
19 export MULTIOP=${MULTIOP:-multiop}
20
21 CLEANUP=${CLEANUP:-""}
22 SETUP=${SETUP:-""}
23
24 LUSTRE=${LUSTRE:-`dirname $0`/..}
25 . $LUSTRE/tests/test-framework.sh
26 init_test_env $@
27 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 init_logging
29
30 require_dsh_mds || exit 0
31
32 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
33
34 # $RUNAS_ID may get set incorrectly somewhere else
35 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
36
37 # remove $SEC, we'd like to control everything by ourselves
38 unset SEC
39
40 #
41 # global variables of this sanity
42 #
43 KRB5_CCACHE_DIR=/tmp
44 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
45 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
46 DBENCH_PID=0
47
48 # set manually
49 GSS=true
50 GSS_KRB5=true
51
52 prepare_krb5_creds() {
53     echo prepare krb5 cred
54     rm -f $KRB5_CRED_SAVE
55     echo RUNAS=$RUNAS
56     $RUNAS krb5_login.sh || exit 1
57     [ -f $KRB5_CRED ] || exit 2
58     echo CRED=$KRB5_CRED
59     cp $KRB5_CRED $KRB5_CRED_SAVE
60 }
61
62 prepare_krb5_creds
63
64 # we want double mount
65 MOUNT_2=${MOUNT_2:-"yes"}
66 check_and_setup_lustre
67
68 rm -rf $DIR/[df][0-9]*
69
70 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
71
72 build_test_filter
73
74 start_dbench()
75 {
76     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
77     [ $NPROC -gt 2 ] && NPROC=2
78     sh rundbench $NPROC 1>/dev/null &
79     DBENCH_PID=$!
80     sleep 2
81
82     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
83     if [ $num -ne 1 ]; then
84         error "failed to start dbench $NPROC"
85     else
86         echo "started dbench with $NPROC processes at background"
87     fi
88
89     return 0
90 }
91
92 check_dbench()
93 {
94     num=`ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l`
95     if [ $num -eq 0 ]; then
96         echo "dbench $DBENCH_PID already finished"
97         wait $DBENCH_PID || error "dbench $PID exit with error"
98         start_dbench
99     elif [ $num -ne 1 ]; then
100         killall -9 dbench
101         error "found $num instance of pid $DBENCH_PID ???"
102     fi
103
104     return 0
105 }
106
107 stop_dbench()
108 {
109     for ((;;)); do
110         killall dbench 2>/dev/null
111         num=`ps --no-headers -p $DBENCH_PID | wc -l`
112         if [ $num -eq 0 ]; then
113             echo "dbench finished"
114             break
115         fi
116         echo "dbench $DBENCH_PID is still running, waiting 2s..."
117         sleep 2
118     done
119
120     wait $DBENCH_PID || true
121     sync || true
122 }
123
124 restore_krb5_cred() {
125     cp $KRB5_CRED_SAVE $KRB5_CRED
126     chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
127     chmod 0600 $KRB5_CRED
128 }
129
130 check_multiple_gss_daemons() {
131     local facet=$1
132     local gssd=$2
133     local gssd_name=`basename $gssd`
134
135     for ((i=0;i<10;i++)); do
136         do_facet $facet "$gssd -v &"
137     done
138
139     # wait daemons entering "stable" status
140     sleep 5
141
142     num=`do_facet $facet ps -o cmd -C $gssd_name | grep $gssd_name | wc -l`
143     echo "$num instance(s) of $gssd_name are running"
144
145     if [ $num -ne 1 ]; then
146         error "$gssd_name not unique"
147     fi
148 }
149
150 calc_connection_cnt
151 umask 077
152
153 test_0() {
154     local my_facet=mds
155
156     echo "bring up gss daemons..."
157     start_gss_daemons
158
159     echo "check with someone already running..."
160     check_multiple_gss_daemons $my_facet $LSVCGSSD
161     if $GSS_PIPEFS; then
162         check_multiple_gss_daemons $my_facet $LGSSD
163     fi
164
165     echo "check with someone run & finished..."
166     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
167     sleep 5 # wait fully exit
168     check_multiple_gss_daemons $my_facet $LSVCGSSD
169     if $GSS_PIPEFS; then
170         check_multiple_gss_daemons $my_facet $LGSSD
171     fi
172
173     echo "check refresh..."
174     do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
175     sleep 5 # wait fully exit
176     do_facet $my_facet ipcrm -S 0x3b92d473
177     check_multiple_gss_daemons $my_facet $LSVCGSSD
178     if $GSS_PIPEFS; then
179         do_facet $my_facet ipcrm -S 0x3a92d473
180         check_multiple_gss_daemons $my_facet $LGSSD
181     fi
182 }
183 run_test 0 "start multiple gss daemons"
184
185 set_flavor_all krb5p
186
187 test_1() {
188     local file=$DIR/$tfile
189
190     chmod 0777 $DIR || error "chmod $DIR failed"
191     $RUNAS touch $DIR
192     # access w/o cred
193     $RUNAS kdestroy
194     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
195     $RUNAS touch $file && error "unexpected success"
196
197     # access w/ cred
198     restore_krb5_cred
199     $RUNAS touch $file || error "should not fail"
200     [ -f $file ] || error "$file not found"
201 }
202 run_test 1 "access with or without krb5 credential"
203
204 test_2() {
205     local file1=$DIR/$tfile-1
206     local file2=$DIR/$tfile-2
207
208     chmod 0777 $DIR || error "chmod $DIR failed"
209     # current access should be ok
210     $RUNAS touch $file1 || error "can't touch $file1"
211     [ -f $file1 ] || error "$file1 not found"
212
213     # cleanup all cred/ctx and touch
214     $RUNAS kdestroy
215     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
216     $RUNAS touch $file2 && error "unexpected success"
217
218     # restore and touch
219     restore_krb5_cred
220     $RUNAS touch $file2 || error "should not fail"
221     [ -f $file2 ] || error "$file2 not found"
222 }
223 run_test 2 "lfs flushctx"
224
225 test_3() {
226     local file=$DIR/$tfile
227
228     # create file
229     echo "aaaaaaaaaaaaaaaaa" > $file
230     chmod 0666 $file
231     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
232     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
233     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
234
235     # start multiop
236     $RUNAS $MULTIOP $file o_r &
237     OPPID=$!
238     # wait multiop finish its open()
239     sleep 1
240
241     # cleanup all cred/ctx and check
242     # metadata check should fail, but file data check should success
243     # because we always use root credential to OSTs
244     $RUNAS kdestroy
245     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
246     echo "destroied credentials/contexs for $RUNAS_ID"
247     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
248     kill -s 10 $OPPID
249     wait $OPPID || error "read file data failed"
250     echo "read file data OK"
251
252     # restore and check again
253     restore_krb5_cred
254     echo "restored credentials for $RUNAS_ID"
255     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
256     echo "$RUNAS_ID checkstat OK"
257     $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
258     echo "$UID checkstat OK"
259     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
260     echo "$RUNAS_ID read file data OK"
261 }
262 run_test 3 "local cache under DLM lock"
263
264 test_4() {
265     local file1=$DIR/$tfile-1
266     local file2=$DIR/$tfile-2
267
268     ! $GSS_PIPEFS && skip "pipefs not used" && return
269
270     chmod 0777 $DIR || error "chmod $DIR failed"
271     # current access should be ok
272     $RUNAS touch $file1 || error "can't touch $file1"
273     [ -f $file1 ] || error "$file1 not found"
274
275     # stop lgssd
276     send_sigint client lgssd
277     sleep 5
278     check_gss_daemon_facet client lgssd && error "lgssd still running"
279
280     # flush context, and touch
281     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
282     $RUNAS touch $file2 &
283     TOUCHPID=$!
284     echo "waiting touch pid $TOUCHPID"
285     wait $TOUCHPID && error "touch should fail"
286
287     # restart lgssd
288     do_facet client "$LGSSD -v"
289     sleep 5
290     check_gss_daemon_facet client lgssd
291
292     # touch new should succeed
293     $RUNAS touch $file2 || error "can't touch $file2"
294     [ -f $file2 ] || error "$file2 not found"
295 }
296 run_test 4 "lgssd dead, operations should wait timeout and fail"
297
298 test_5() {
299     local file1=$DIR/$tfile-1
300     local file2=$DIR/$tfile-2
301     local wait_time=$((TIMEOUT + TIMEOUT / 2))
302
303     chmod 0777 $DIR || error "chmod $DIR failed"
304     # current access should be ok
305     $RUNAS touch $file1 || error "can't touch $file1"
306     [ -f $file1 ] || error "$file1 not found"
307
308     # stop lsvcgssd
309     send_sigint $(comma_list $(mdts_nodes)) lsvcgssd
310     sleep 5
311     check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd && error "lsvcgssd still running"
312
313     # flush context, and touch
314     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
315     $RUNAS touch $file2 &
316     TOUCHPID=$!
317
318     # wait certain time
319     echo "waiting $wait_time seconds for touch pid $TOUCHPID"
320     sleep $wait_time
321     num=`ps --no-headers -p $TOUCHPID | wc -l`
322     [ $num -eq 1 ] || error "touch already ended ($num)"
323     echo "process $TOUCHPID still hanging there... OK"
324
325     # restart lsvcgssd, expect touch suceed
326     echo "restart lsvcgssd and recovering"
327     start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -v"
328     sleep 5
329     check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd
330     wait $TOUCHPID || error "touch fail"
331     [ -f $file2 ] || error "$file2 not found"
332 }
333 run_test 5 "lsvcgssd dead, operations lead to recovery"
334
335 test_6() {
336     local nfile=10
337
338     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
339     for ((i=0; i<$nfile; i++)); do
340         dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
341     done
342     ls -l $DIR/d6/* > /dev/null || error "ls failed"
343     rm -rf $DIR2/d6/* || error "rm failed"
344     rmdir $DIR2/d6/ || error "rmdir failed"
345 }
346 run_test 6 "test basic DLM callback works"
347
348 test_7() {
349         local tdir=$DIR/d7
350         local num_osts
351
352         # for open(), client only reserve space for default stripe count lovea,
353         # and server may return larger lovea in reply (because of larger stripe
354         # count), client need call enlarge_reqbuf() and save the replied lovea
355         # in request for future possible replay.
356         #
357         # Note: current script does NOT guarantee enlarge_reqbuf() will be in
358         # the path, however it does work in local test which has 2 OSTs and
359         # default stripe count is 1.
360         num_osts=$($LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l)
361         echo "found $num_osts active OSTs"
362         [ $num_osts -lt 2 ] &&
363                 echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
364
365         mkdir $tdir || error "mkdir $tdir failed"
366         $LFS setstripe -c $num_osts $tdir || error "setstripe -c $num_osts"
367
368         echo "creating..."
369         for ((i = 0; i < 20; i++)); do
370                 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
371         done
372         echo "reading..."
373         for ((i = 0; i < 20; i++)); do
374                 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
375         done
376         rm -rf $tdir
377 }
378 run_test 7 "exercise enlarge_reqbuf()"
379
380 test_8()
381 {
382     local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
383     local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
384     local REQ_DELAY
385     do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
386
387     mkdir -p $DIR/d8
388     chmod a+w $DIR/d8
389
390     $LCTL dk > /dev/null
391     debugsave
392     sysctl -w lnet.debug="+other"
393
394     # wait for the at estimation come down, this is faster
395     while [ true ]; do
396         REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
397                    awk '/portal 12/ {print $5}' | tail -1`
398         [ $REQ_DELAY -le 5 ] && break
399         echo "current AT estimation is $REQ_DELAY, wait a little bit"
400         sleep 8
401     done
402     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
403
404     # sleep sometime in ctx handle
405     do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
406 #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
407     do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
408
409     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
410
411     $RUNAS touch $DIR/d8/f &
412     TOUCHPID=$!
413     echo "waiting for touch (pid $TOUCHPID) to finish..."
414     sleep 2 # give it a chance to really trigger context init rpc
415     do_facet $SINGLEMDS $LCTL set_param fail_loc=0
416     wait $TOUCHPID || error "touch should have succeeded"
417
418     $LCTL dk | grep "Early reply #" || error "No early reply"
419
420     debugrestore
421     do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
422 }
423 run_test 8 "Early reply sent for slow gss context negotiation"
424
425 #
426 # following tests will manipulate flavors and may end with any flavor set,
427 # so each test should not assume any start flavor.
428 #
429
430 test_90() {
431     if [ "$SLOW" = "no" ]; then
432         total=10
433     else
434         total=60
435     fi
436
437     restore_to_default_flavor
438     set_rule $FSNAME any any krb5p
439     wait_flavor all2all krb5p
440
441     start_dbench
442
443     for ((n=0;n<$total;n++)); do
444         sleep 2
445         check_dbench
446         echo "flush ctx ($n/$total) ..."
447         $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
448     done
449     check_dbench
450     #sleep to let ctxs be re-established
451     sleep 10
452     stop_dbench
453 }
454 run_test 90 "recoverable from losing contexts under load"
455
456 test_99() {
457     local nrule_old=0
458     local nrule_new=0
459     local max=64
460
461     #
462     # general rules
463     #
464     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
465                | grep "$FSNAME.srpc.flavor." | wc -l`
466     echo "original general rules: $nrule_old"
467
468     for ((i = $nrule_old; i < $max; i++)); do
469         set_rule $FSNAME elan$i any krb5n || error "set rule $i"
470     done
471     for ((i = $nrule_old; i < $max; i++)); do
472         set_rule $FSNAME elan$i any || error "remove rule $i"
473     done
474
475     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
476                | grep "$FSNAME.srpc.flavor." | wc -l`
477     if [ $nrule_new != $nrule_old ]; then
478         error "general rule: $nrule_new != $nrule_old"
479     fi
480
481     #
482     # target-specific rules
483     #
484     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
485                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
486     echo "original target rules: $nrule_old"
487
488     for ((i = $nrule_old; i < $max; i++)); do
489         set_rule $FSNAME-MDT0000 elan$i any krb5i || error "set rule $i"
490     done
491     for ((i = $nrule_old; i < $max; i++)); do
492         set_rule $FSNAME-MDT0000 elan$i any || error "remove rule $i"
493     done
494
495     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
496                | grep "$FSNAME-MDT0000.srpc.flavor." | wc -l`
497     if [ $nrule_new != $nrule_old ]; then
498         error "general rule: $nrule_new != $nrule_old"
499     fi
500 }
501 run_test 99 "set large number of sptlrpc rules"
502
503 error_dbench()
504 {
505     local err_str=$1
506
507     killall -9 dbench
508     sleep 1
509
510     error $err_str
511 }
512
513 test_100() {
514     # started from default flavors
515     restore_to_default_flavor
516
517     # running dbench background
518     start_dbench
519
520     #
521     # all: null -> krb5n -> krb5a -> krb5i -> krb5p -> plain
522     #
523     set_rule $FSNAME any any krb5n
524     wait_flavor all2all krb5n || error_dbench "1"
525     check_dbench
526
527     set_rule $FSNAME any any krb5a
528     wait_flavor all2all krb5a || error_dbench "2"
529     check_dbench
530
531     set_rule $FSNAME any any krb5i
532     wait_flavor all2all krb5i || error_dbench "3"
533     check_dbench
534
535     set_rule $FSNAME any any krb5p
536     wait_flavor all2all krb5p || error_dbench "4"
537     check_dbench
538
539     set_rule $FSNAME any any plain
540     wait_flavor all2all plain || error_dbench "5"
541     check_dbench
542
543     #
544     # M - M: krb5a
545     # C - M: krb5i
546     # M - O: krb5p
547     # C - O: krb5n
548     #
549     set_rule $FSNAME any mdt2mdt krb5a
550     wait_flavor mdt2mdt krb5a || error_dbench "6"
551     check_dbench
552
553     set_rule $FSNAME any cli2mdt krb5i
554     wait_flavor cli2mdt krb5i || error_dbench "7"
555     check_dbench
556
557     set_rule $FSNAME any mdt2ost krb5p
558     wait_flavor mdt2ost krb5p || error_dbench "8"
559     check_dbench
560
561     set_rule $FSNAME any cli2ost krb5n
562     wait_flavor cli2ost krb5n || error_dbench "9"
563     check_dbench
564
565     #
566     # * - MDT0: krb5p
567     # * - OST0: krb5i
568     #
569     # nothing should be changed because they are override by above dir rules
570     #
571     set_rule $FSNAME-MDT0000 any any krb5p
572     set_rule $FSNAME-OST0000 any any krb5i
573     wait_flavor mdt2mdt krb5a || error_dbench "10"
574     wait_flavor cli2mdt krb5i || error_dbench "11"
575     check_dbench
576     wait_flavor mdt2ost krb5p || error_dbench "12"
577     wait_flavor cli2ost krb5n || error_dbench "13"
578
579     #
580     # delete all dir-specific rules
581     #
582     set_rule $FSNAME any mdt2mdt
583     set_rule $FSNAME any cli2mdt
584     set_rule $FSNAME any mdt2ost
585     set_rule $FSNAME any cli2ost
586     wait_flavor mdt2mdt krb5p $((MDSCOUNT - 1)) || error_dbench "14"
587     wait_flavor cli2mdt krb5p $(get_clients_mount_count) || error_dbench "15"
588     check_dbench
589     wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
590     wait_flavor cli2ost krb5i $(get_clients_mount_count) || error_dbench "17"
591     check_dbench
592
593     #
594     # remove:
595     #  * - MDT0: krb5p
596     #  * - OST0: krb5i
597     #
598     set_rule $FSNAME-MDT0000 any any
599     set_rule $FSNAME-OST0000 any any || error_dbench "18"
600     wait_flavor all2all plain || error_dbench "19"
601     check_dbench
602
603     stop_dbench
604 }
605 run_test 100 "change security flavor on the fly under load"
606
607 switch_sec_test()
608 {
609     local flavor0=$1
610     local flavor1=$2
611     local filename=$DIR/$tfile
612     local multiop_pid
613     local num
614
615     #
616     # after set to flavor0, start multop which use flavor0 rpc, and let
617     # server drop the reply; then switch to flavor1, the resend should be
618     # completed using flavor1. To exercise the code of switching ctx/sec
619     # for a resend request.
620     #
621     log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
622
623     set_rule $FSNAME any cli2mdt $flavor0
624     wait_flavor cli2mdt $flavor0
625     rm -f $filename || error "remove old $filename failed"
626
627 #MDS_REINT = 36
628 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
629     do_facet $SINGLEMDS lctl set_param fail_val=36
630     do_facet $SINGLEMDS lctl set_param fail_loc=0x513
631     log "starting multiop"
632     $MULTIOP $filename m &
633     multiop_pid=$!
634     echo "multiop pid=$multiop_pid"
635     sleep 1
636
637     set_rule $FSNAME any cli2mdt $flavor1
638     wait_flavor cli2mdt $flavor1
639
640     num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
641     [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
642     echo "process $multiop_pid is still hanging there... OK"
643
644     do_facet $SINGLEMDS lctl set_param fail_loc=0
645     log "waiting for multiop ($multiop_pid) to finish"
646     wait $multiop_pid || error "multiop returned error"
647 }
648
649 test_101()
650 {
651     # started from default flavors
652     restore_to_default_flavor
653
654     switch_sec_test null  plain
655     switch_sec_test plain krb5n
656     switch_sec_test krb5n krb5a
657     switch_sec_test krb5a krb5i
658     switch_sec_test krb5i krb5p
659     switch_sec_test krb5p null
660     switch_sec_test null  krb5p
661     switch_sec_test krb5p krb5i
662     switch_sec_test krb5i plain
663     switch_sec_test plain krb5p
664 }
665 run_test 101 "switch ctx/sec for resending request"
666
667 error_102()
668 {
669     local err_str=$1
670
671     killall -9 dbench
672     sleep 1
673
674     error $err_str
675 }
676
677 test_102() {
678     # started from default flavors
679     restore_to_default_flavor
680
681     # run dbench background
682     start_dbench
683
684     echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
685     set_rule $FSNAME any any krb5n
686     set_rule $FSNAME any any krb5a
687     set_rule $FSNAME any any krb5i
688     set_rule $FSNAME any any krb5p
689     set_rule $FSNAME any any plain
690     set_rule $FSNAME any any null
691
692     check_dbench
693     wait_flavor all2all null || error_dbench "1"
694     check_dbench
695
696     echo "waiting for 15s and check again"
697     sleep 15
698     check_dbench
699
700     echo "Testing null->krb5i->null->krb5i->null..."
701     for ((i=0; i<10; i++)); do
702         set_rule $FSNAME any any krb5i
703         set_rule $FSNAME any any null
704     done
705     set_rule $FSNAME any any krb5i
706
707     check_dbench
708     wait_flavor all2all krb5i || error_dbench "2"
709     check_dbench
710
711     echo "waiting for 15s and check again"
712     sleep 15
713     check_dbench
714
715     stop_dbench
716 }
717 run_test 102 "survive from insanely fast flavor switch"
718
719 test_150() {
720     local save_opts
721     local count
722     local clients=$CLIENTS
723
724     [ -z $clients ] && clients=$HOSTNAME
725
726     # started from default flavors
727     restore_to_default_flavor
728
729     # at this time no rules has been set on mgs; mgc use null
730     # flavor connect to mgs.
731     count=`flvr_cnt_mgc2mgs null`
732     [ $count -eq 1 ] || error "$count mgc connection use null flavor"
733
734     zconf_umount_clients $clients $MOUNT || return 1
735
736     # mount client with conflict flavor - should fail
737     save_opts=$MOUNTOPT
738     MOUNTOPT="$MOUNTOPT,mgssec=krb5p"
739     zconf_mount_clients $clients $MOUNT && \
740         error "mount with conflict flavor should have failed"
741     MOUNTOPT=$save_opts
742
743     # mount client with same flavor - should succeed
744     save_opts=$MOUNTOPT
745     MOUNTOPT="$MOUNTOPT,mgssec=null"
746     zconf_mount_clients $clients $MOUNT || \
747         error "mount with same flavor should have succeeded"
748     MOUNTOPT=$save_opts
749     zconf_umount_clients $clients $MOUNT || return 2
750
751     # mount client with default flavor - should succeed
752     zconf_mount_clients $clients $MOUNT || \
753         error "mount with default flavor should have succeeded"
754 }
755 run_test 150 "secure mgs connection: client flavor setting"
756
757 test_151() {
758     local save_opts
759
760     # set mgs only accept krb5p
761     set_rule _mgs any any krb5p
762
763     # umount everything, modules still loaded
764     stopall
765
766     # mount mgs with default flavor, in current framework it means mgs+mdt1.
767     # the connection of mgc of mdt1 to mgs is expected fail.
768     DEVNAME=$(mdsdevname 1)
769     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
770
771     # mount with unauthorized flavor should fail
772     save_opts=$MDS_MOUNT_OPTS
773     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
774     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
775     MDS_MOUNT_OPTS=$save_opts
776
777     # mount with designated flavor should succeed
778     save_opts=$MDS_MOUNT_OPTS
779     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=krb5p"
780     start mds1 $DEVNAME $MDS_MOUNT_OPTS || error "mount with designated flavor should have succeeded"
781     MDS_MOUNT_OPTS=$save_opts
782
783     stop mds1 -f
784 }
785 run_test 151 "secure mgs connection: server flavor control"
786
787 complete $SECONDS
788 check_and_cleanup_lustre
789 exit_status