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