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