Whamcloud - gitweb
d38ad0034c46910f9f7cdb5bd0b176a111c23e46
[fs/lustre-release.git] / lustre / tests / sanity-krb5.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 SAVE_PWD=$PWD
16
17 export MULTIOP=${MULTIOP:-multiop}
18
19 LUSTRE=${LUSTRE:-$(dirname $0)/..}
20 . $LUSTRE/tests/test-framework.sh
21 init_test_env $@
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
23 init_logging
24
25 require_dsh_mds || exit 0
26
27 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
28
29 # $RUNAS_ID may get set incorrectly somewhere else
30 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
31     error "RUNAS_ID set to 0, but UID is also 0!"
32
33 # remove $SEC, we'd like to control everything by ourselves
34 unset SEC
35
36 #
37 # global variables of this sanity
38 #
39 KRB5_CCACHE_DIR=/tmp
40 KRB5_CRED=$KRB5_CCACHE_DIR/krb5cc_$RUNAS_ID
41 KRB5_CRED_SAVE=$KRB5_CCACHE_DIR/krb5cc.sanity.save
42 DBENCH_PID=0
43
44 # set manually
45 GSS=true
46 GSS_KRB5=true
47
48 prepare_krb5_creds() {
49         echo prepare krb5 cred
50         rm -f $KRB5_CRED_SAVE
51         echo RUNAS=$RUNAS
52         $RUNAS krb5_login.sh || exit 1
53         [ -f $KRB5_CRED ] || exit 2
54         echo CRED=$KRB5_CRED
55         cp $KRB5_CRED $KRB5_CRED_SAVE
56 }
57
58 prepare_krb5_creds
59
60 # we want double mount
61 MOUNT_2=${MOUNT_2:-"yes"}
62 check_and_setup_lustre
63
64 rm -rf $DIR/[df][0-9]*
65
66 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
67
68 build_test_filter
69
70 start_dbench()
71 {
72         local NPROC=$(grep -c ^processor /proc/cpuinfo)
73         [ $NPROC -gt 2 ] && NPROC=2
74         sh rundbench $NPROC 1>/dev/null &
75         DBENCH_PID=$!
76         sleep 2
77
78         num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
79         if [ $num -ne 1 ]; then
80                 error "failed to start dbench $NPROC"
81         else
82                 echo "started dbench with $NPROC processes at background"
83         fi
84
85         return 0
86 }
87
88 check_dbench()
89 {
90         num=$(ps --no-headers -p $DBENCH_PID 2>/dev/null | wc -l)
91         if [ $num -eq 0 ]; then
92                 echo "dbench $DBENCH_PID already finished"
93                 wait $DBENCH_PID || error "dbench $PID exit with error"
94                 start_dbench
95         elif [ $num -ne 1 ]; then
96                 killall -9 dbench
97                 error "found $num instance of pid $DBENCH_PID ???"
98         fi
99
100         return 0
101 }
102
103 stop_dbench()
104 {
105         for ((;;)); do
106                 killall dbench 2>/dev/null
107                 local num=$(ps --no-headers -p $DBENCH_PID | wc -l)
108                 if [ $num -eq 0 ]; then
109                         echo "dbench finished"
110                         break
111                 fi
112                 echo "dbench $DBENCH_PID is still running, waiting 2s..."
113                 sleep 2
114         done
115
116         wait $DBENCH_PID || true
117         sync || true
118 }
119
120 restore_krb5_cred() {
121         cp $KRB5_CRED_SAVE $KRB5_CRED
122         chown $RUNAS_ID:$RUNAS_ID $KRB5_CRED
123         chmod 0600 $KRB5_CRED
124 }
125
126 check_multiple_gss_daemons() {
127         local facet=$1
128         local gssd=$2
129         local gssd_name=$(basename $gssd)
130
131         for ((i = 0; i < 10; i++)); do
132                 do_facet $facet "$gssd -v &"
133         done
134
135         # wait daemons entering "stable" status
136         sleep 5
137
138         local num=$(do_facet $facet ps -o cmd -C $gssd_name |
139                 grep -c $gssd_name)
140         echo "$num instance(s) of $gssd_name are running"
141
142         if [ $num -ne 1 ]; then
143                 error "$gssd_name not unique"
144         fi
145 }
146
147 calc_connection_cnt
148 umask 077
149
150 test_0() {
151         local my_facet=mds
152
153         echo "bring up gss daemons..."
154         start_gss_daemons
155
156         echo "check with someone already running..."
157         check_multiple_gss_daemons $my_facet $LSVCGSSD
158         if $GSS_PIPEFS; then
159                 check_multiple_gss_daemons $my_facet $LGSSD
160         fi
161
162         echo "check with someone run & finished..."
163         do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
164         sleep 5 # wait fully exit
165         check_multiple_gss_daemons $my_facet $LSVCGSSD
166         if $GSS_PIPEFS; then
167                 check_multiple_gss_daemons $my_facet $LGSSD
168         fi
169
170         echo "check refresh..."
171         do_facet $my_facet killall -q -2 lgssd lsvcgssd || true
172         sleep 5 # wait fully exit
173         do_facet $my_facet ipcrm -S 0x3b92d473
174         check_multiple_gss_daemons $my_facet $LSVCGSSD
175         if $GSS_PIPEFS; then
176                 do_facet $my_facet ipcrm -S 0x3a92d473
177                 check_multiple_gss_daemons $my_facet $LGSSD
178         fi
179 }
180 run_test 0 "start multiple gss daemons"
181
182 set_flavor_all krb5p
183
184 test_1() {
185         local file=$DIR/$tfile
186
187         chmod 0777 $DIR || error "chmod $DIR failed"
188         $RUNAS touch $DIR
189         # access w/o cred
190         $RUNAS kdestroy
191         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
192         $RUNAS touch $file && error "unexpected success"
193
194         # access w/ cred
195         restore_krb5_cred
196         $RUNAS touch $file || error "should not fail"
197         [ -f $file ] || error "$file not found"
198 }
199 run_test 1 "access with or without krb5 credential"
200
201 test_2() {
202         local file1=$DIR/$tfile-1
203         local file2=$DIR/$tfile-2
204
205         chmod 0777 $DIR || error "chmod $DIR failed"
206         # current access should be ok
207         $RUNAS touch $file1 || error "can't touch $file1"
208         [ -f $file1 ] || error "$file1 not found"
209
210         # cleanup all cred/ctx and touch
211         $RUNAS kdestroy
212         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
213         $RUNAS touch $file2 && error "unexpected success"
214
215         # restore and touch
216         restore_krb5_cred
217         $RUNAS touch $file2 || error "should not fail"
218         [ -f $file2 ] || error "$file2 not found"
219 }
220 run_test 2 "lfs flushctx"
221
222 test_3() {
223         local file=$DIR/$tfile
224
225         # create file
226         echo "aaaaaaaaaaaaaaaaa" > $file
227         chmod 0666 $file
228         $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
229         $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
230         $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
231
232         # start multiop
233         $RUNAS $MULTIOP $file o_r &
234         OPPID=$!
235         # wait multiop finish its open()
236         sleep 1
237
238         # cleanup all cred/ctx and check
239         # metadata check should fail, but file data check should success
240         # because we always use root credential to OSTs
241         $RUNAS kdestroy
242         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
243         echo "destroyed credentials/contexs for $RUNAS_ID"
244         $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
245         kill -s 10 $OPPID
246         wait $OPPID || error "read file data failed"
247         echo "read file data OK"
248
249         # restore and check again
250         restore_krb5_cred
251         echo "restored credentials for $RUNAS_ID"
252         $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat (2) error"
253         echo "$RUNAS_ID checkstat OK"
254         $CHECKSTAT -p 0666 $file || error "$UID checkstat (2) error"
255         echo "$UID checkstat OK"
256         $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat (2) error"
257         echo "$RUNAS_ID read file data OK"
258 }
259 run_test 3 "local cache under DLM lock"
260
261 test_4() {
262         local file1=$DIR/$tfile-1
263         local file2=$DIR/$tfile-2
264
265         ! $GSS_PIPEFS && skip "pipefs not used" && return
266
267         chmod 0777 $DIR || error "chmod $DIR failed"
268         # current access should be ok
269         $RUNAS touch $file1 || error "can't touch $file1"
270         [ -f $file1 ] || error "$file1 not found"
271
272         # stop lgssd
273         send_sigint client lgssd
274         sleep 5
275         check_gss_daemon_facet client lgssd && error "lgssd still running"
276
277         # flush context, and touch
278         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
279         $RUNAS touch $file2 &
280         TOUCHPID=$!
281         echo "waiting touch pid $TOUCHPID"
282         wait $TOUCHPID && error "touch should fail"
283
284         # restart lgssd
285         do_facet client "$LGSSD -v"
286         sleep 5
287         check_gss_daemon_facet client lgssd
288
289         # touch new should succeed
290         $RUNAS touch $file2 || error "can't touch $file2"
291         [ -f $file2 ] || error "$file2 not found"
292 }
293 run_test 4 "lgssd dead, operations should wait timeout and fail"
294
295 test_5() {
296         local file1=$DIR/$tfile-1
297         local file2=$DIR/$tfile-2
298         local wait_time=$((TIMEOUT + TIMEOUT / 2))
299
300         chmod 0777 $DIR || error "chmod $DIR failed"
301         # current access should be ok
302         $RUNAS touch $file1 || error "can't touch $file1"
303         [ -f $file1 ] || error "$file1 not found"
304
305         # stop lsvcgssd
306         send_sigint $(comma_list $(mdts_nodes)) lsvcgssd
307         sleep 5
308         check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd &&
309                 error "lsvcgssd still running"
310
311         # flush context, and touch
312         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
313         $RUNAS touch $file2 &
314         TOUCHPID=$!
315
316         # wait certain time
317         echo "waiting $wait_time seconds for touch pid $TOUCHPID"
318         sleep $wait_time
319         num=$(ps --no-headers -p $TOUCHPID | wc -l)
320         [ $num -eq 1 ] || error "touch already ended ($num)"
321         echo "process $TOUCHPID still hanging there... OK"
322
323         # restart lsvcgssd, expect touch suceed
324         echo "restart lsvcgssd and recovering"
325         start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -v"
326         sleep 5
327         check_gss_daemon_nodes $(comma_list $(mdts_nodes)) lsvcgssd
328         wait $TOUCHPID || error "touch fail"
329         [ -f $file2 ] || error "$file2 not found"
330 }
331 run_test 5 "lsvcgssd dead, operations lead to recovery"
332
333 test_6() {
334         local nfile=10
335
336         mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
337         for ((i=0; i<$nfile; i++)); do
338                 dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 ||
339                     error "dd file$i failed"
340         done
341         ls -l $DIR/d6/* > /dev/null || error "ls failed"
342         rm -rf $DIR2/d6/* || error "rm failed"
343         rmdir $DIR2/d6/ || error "rmdir failed"
344 }
345 run_test 6 "test basic DLM callback works"
346
347 test_7() {
348         local tdir=$DIR/d7
349         local num_osts
350
351         # for open(), client only reserve space for default stripe count lovea,
352         # and server may return larger lovea in reply (because of larger stripe
353         # count), client need call enlarge_reqbuf() and save the replied lovea
354         # in request for future possible replay.
355         #
356         # Note: current script does NOT guarantee enlarge_reqbuf() will be in
357         # the path, however it does work in local test which has 2 OSTs and
358         # default stripe count is 1.
359         num_osts=$($LFS getstripe $MOUNT | egrep -c "^[0-9]*:.*ACTIVE")
360         echo "found $num_osts active OSTs"
361         [ $num_osts -lt 2 ] &&
362                 echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
363
364         mkdir $tdir || error "mkdir $tdir failed"
365         $LFS setstripe -c $num_osts $tdir || error "setstripe -c $num_osts"
366
367         echo "creating..."
368         for ((i = 0; i < 20; i++)); do
369                 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
370         done
371         echo "reading..."
372         for ((i = 0; i < 20; i++)); do
373                 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
374         done
375         rm -rf $tdir
376 }
377 run_test 7 "exercise enlarge_reqbuf()"
378
379 test_8()
380 {
381         local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
382         local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
383         local REQ_DELAY
384         do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
385
386         mkdir -p $DIR/d8
387         chmod a+w $DIR/d8
388
389         $LCTL dk > /dev/null
390         debugsave
391         sysctl -w lnet.debug="+other"
392
393         # wait for the at estimation come down, this is faster
394         while [ true ]; do
395                 REQ_DELAY=$(lctl get_param -n \
396                         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
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 \
465             2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
466         echo "original general rules: $nrule_old"
467
468         for ((i = $nrule_old; i < $max; i++)); do
469                 set_rule $FSNAME ${NETTYPE}$i any krb5n || error "set rule $i"
470         done
471         for ((i = $nrule_old; i < $max; i++)); do
472                 set_rule $FSNAME ${NETTYPE}$i any || error "remove rule $i"
473         done
474
475         nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
476             2>/dev/null | grep -c "$FSNAME.srpc.flavor.")
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 \
485             2>/dev/null | grep -c "$FSNAME-MDT0000.srpc.flavor.")
486         echo "original target rules: $nrule_old"
487
488         for ((i = $nrule_old; i < $max; i++)); do
489                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i any krb5i || error "set rule $i"
490         done
491         for ((i = $nrule_old; i < $max; i++)); do
492                 set_rule $FSNAME-MDT0000 ${NETTYPE}$i any || error "remove rule $i"
493         done
494
495         nrule_new=$(do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME \
496             2>/dev/null \ | grep -c "$FSNAME-MDT0000.srpc.flavor.")
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) ||
588                 error_dbench "15"
589         check_dbench
590         wait_flavor mdt2ost krb5i $MDSCOUNT || error_dbench "16"
591         wait_flavor cli2ost krb5i $(get_clients_mount_count) ||
592                 error_dbench "17"
593         check_dbench
594
595         #
596         # remove:
597         #  * - MDT0: krb5p
598         #  * - OST0: krb5i
599         #
600         set_rule $FSNAME-MDT0000 any any
601         set_rule $FSNAME-OST0000 any any || error_dbench "18"
602         wait_flavor all2all plain || error_dbench "19"
603         check_dbench
604
605         stop_dbench
606 }
607 run_test 100 "change security flavor on the fly under load"
608
609 switch_sec_test()
610 {
611         local flavor0=$1
612         local flavor1=$2
613         local filename=$DIR/$tfile
614         local multiop_pid
615         local num
616
617         #
618         # after set to flavor0, start multop which use flavor0 rpc, and let
619         # server drop the reply; then switch to flavor1, the resend should be
620         # completed using flavor1. To exercise the code of switching ctx/sec
621         # for a resend request.
622         #
623         log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
624
625         set_rule $FSNAME any cli2mdt $flavor0
626         wait_flavor cli2mdt $flavor0
627         rm -f $filename || error "remove old $filename failed"
628
629         #MDS_REINT = 36
630         #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
631         do_facet $SINGLEMDS lctl set_param fail_val=36
632         do_facet $SINGLEMDS lctl set_param fail_loc=0x513
633         log "starting multiop"
634         $MULTIOP $filename m &
635         multiop_pid=$!
636         echo "multiop pid=$multiop_pid"
637         sleep 1
638
639         set_rule $FSNAME any cli2mdt $flavor1
640         wait_flavor cli2mdt $flavor1
641
642         num=$(ps --no-headers -p $multiop_pid 2>/dev/null | wc -l)
643         [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
644         echo "process $multiop_pid is still hanging there... OK"
645
646         do_facet $SINGLEMDS lctl set_param fail_loc=0
647         log "waiting for multiop ($multiop_pid) to finish"
648         wait $multiop_pid || error "multiop returned error"
649 }
650
651 test_101()
652 {
653         # started from default flavors
654         restore_to_default_flavor
655
656         switch_sec_test null  plain
657         switch_sec_test plain krb5n
658         switch_sec_test krb5n krb5a
659         switch_sec_test krb5a krb5i
660         switch_sec_test krb5i krb5p
661         switch_sec_test krb5p null
662         switch_sec_test null  krb5p
663         switch_sec_test krb5p krb5i
664         switch_sec_test krb5i plain
665         switch_sec_test plain krb5p
666 }
667 run_test 101 "switch ctx/sec for resending request"
668
669 error_102()
670 {
671         local err_str=$1
672
673         killall -9 dbench
674         sleep 1
675
676         error $err_str
677 }
678
679 test_102() {
680         # started from default flavors
681         restore_to_default_flavor
682
683         # run dbench background
684         start_dbench
685
686         echo "Testing null->krb5n->krb5a->krb5i->krb5p->plain->null"
687         set_rule $FSNAME any any krb5n
688         set_rule $FSNAME any any krb5a
689         set_rule $FSNAME any any krb5i
690         set_rule $FSNAME any any krb5p
691         set_rule $FSNAME any any plain
692         set_rule $FSNAME any any null
693
694         check_dbench
695         wait_flavor all2all null || error_dbench "1"
696         check_dbench
697
698         echo "waiting for 15s and check again"
699         sleep 15
700         check_dbench
701
702         echo "Testing null->krb5i->null->krb5i->null..."
703         for ((i=0; i<10; i++)); do
704                 set_rule $FSNAME any any krb5i
705                 set_rule $FSNAME any any null
706         done
707         set_rule $FSNAME any any krb5i
708
709         check_dbench
710         wait_flavor all2all krb5i || error_dbench "2"
711         check_dbench
712
713         echo "waiting for 15s and check again"
714         sleep 15
715         check_dbench
716
717         stop_dbench
718 }
719 run_test 102 "survive from insanely fast flavor switch"
720
721 test_150() {
722         local mount_opts
723         local count
724         local clients=$CLIENTS
725
726         [ -z $clients ] && clients=$HOSTNAME
727
728         # started from default flavors
729         restore_to_default_flavor
730
731         # at this time no rules has been set on mgs; mgc use null
732         # flavor connect to mgs.
733         count=$(flvr_cnt_mgc2mgs null)
734         [ $count -eq 1 ] || error "$count mgc connection use null flavor"
735
736         zconf_umount_clients $clients $MOUNT || return 1
737
738         # mount client with conflict flavor - should fail
739         mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=krb5p"
740         zconf_mount_clients $clients $MOUNT $mount_opts &&
741             error "mount with conflict flavor should have failed"
742
743         # mount client with same flavor - should succeed
744         mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=null"
745         zconf_mount_clients $clients $MOUNT $mount_opts ||
746             error "mount with same flavor should have succeeded"
747         zconf_umount_clients $clients $MOUNT || return 2
748
749         # mount client with default flavor - should succeed
750         zconf_mount_clients $clients $MOUNT ||
751             error "mount with default flavor should have succeeded"
752 }
753 run_test 150 "secure mgs connection: client flavor setting"
754
755 test_151() {
756         local save_opts
757
758         # set mgs only accept krb5p
759         set_rule _mgs any any krb5p
760
761         # umount everything, modules still loaded
762         stopall
763
764         # start gss daemon on mgs node
765         combined_mgs_mds || start_gss_daemons $mgs_HOST "$LSVCGSSD -v"
766
767         # start mgs
768         start mgs $(mgsdevname 1) $MDS_MOUNT_OPTS
769
770         # mount mgs with default flavor, in current framework it means mgs+mdt1.
771         # the connection of mgc of mdt1 to mgs is expected fail.
772         DEVNAME=$(mdsdevname 1)
773         start mds1 $DEVNAME $MDS_MOUNT_OPTS
774         wait_mgc_import_state mds FULL 0 &&
775             error "mount with default flavor should have failed"
776         stop mds1
777
778         # mount with unauthorized flavor should fail
779         save_opts=$MDS_MOUNT_OPTS
780         if [ -z "$MDS_MOUNT_OPTS" ]; then
781             MDS_MOUNT_OPTS="-o mgssec=null"
782         else
783         MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
784         fi
785         start mds1 $DEVNAME $MDS_MOUNT_OPTS
786         wait_mgc_import_state mds FULL 0 &&
787             error "mount with unauthorized flavor should have failed"
788         MDS_MOUNT_OPTS=$save_opts
789         stop mds1
790
791         # mount with designated flavor should succeed
792         save_opts=$MDS_MOUNT_OPTS
793         if [ -z "$MDS_MOUNT_OPTS" ]; then
794             MDS_MOUNT_OPTS="-o mgssec=krb5p"
795         else
796         MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=krb5p"
797         fi
798         start mds1 $DEVNAME $MDS_MOUNT_OPTS
799         wait_mgc_import_state mds FULL 0 ||
800             error "mount with designated flavor should have succeeded"
801         MDS_MOUNT_OPTS=$save_opts
802
803         stop mds1 -f
804 }
805 run_test 151 "secure mgs connection: server flavor control"
806
807 complete $SECONDS
808 check_and_cleanup_lustre
809 exit_status