Whamcloud - gitweb
LU-9795 tests: exclude several tests which conflict with SSK
[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 if $SHARED_KEY; then
14 # bug number for skipped tests: LU-9795 LU-9795
15         ALWAYS_EXCEPT="         8       90      $ALWAYS_EXCEPT"
16 fi
17
18 SRCDIR=`dirname $0`
19
20 export MULTIOP=${MULTIOP:-multiop}
21
22 LUSTRE=${LUSTRE:-`dirname $0`/..}
23 . $LUSTRE/tests/test-framework.sh
24 init_test_env $@
25 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
26 init_logging
27
28 require_dsh_mds || exit 0
29
30 [ "$SLOW" = "no" ] && EXCEPT_SLOW="100 101"
31
32 # $RUNAS_ID may get set incorrectly somewhere else
33 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
34
35 # remove $SEC, we'd like to control everything by ourselves
36 unset SEC
37
38 #
39 # global variables of this sanity
40 #
41 DBENCH_PID=0
42
43 # set manually
44 GSS=true
45
46 # we want double mount
47 MOUNT_2=${MOUNT_2:-"yes"}
48 check_and_setup_lustre
49
50 rm -rf $DIR/[df][0-9]*
51
52 check_runas_id $RUNAS_ID $RUNAS_ID $RUNAS
53
54 build_test_filter
55
56 start_dbench()
57 {
58     NPROC=`cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l`
59     [ $NPROC -gt 2 ] && NPROC=2
60     sh rundbench $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         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 calc_connection_cnt
107 umask 077
108
109 # Stop previously existing gss daemons
110 stop_gss_daemons
111
112 echo "bring up gss daemons..."
113 # start gss daemon with -z flag for gssnull
114 start_gss_daemons $(comma_list $(mdts_nodes)) "$LSVCGSSD -z -vv" ||
115     error "can't start gss daemons on MDTs"
116 start_gss_daemons $(comma_list $(osts_nodes)) "$LSVCGSSD -z -vv" ||
117     error "can't start gss daemons on OSTs"
118
119 lctl set_param sptlrpc.gss.lgss_keyring.debug_level=4
120
121 echo "cat /etc/request-key.d/lgssc.conf"
122 cat /etc/request-key.d/lgssc.conf ||
123     error_noexit "/etc/request-key.d/lgssc.conf does not exist"
124 echo "cat /etc/request-key.conf"
125 cat /etc/request-key.conf ||
126     error_noexit "/etc/request-key.conf does not exist"
127
128 set_flavor_all gssnull
129
130 test_1() {
131         local file=$DIR/$tfile
132
133         chmod 0777 $DIR || error "chmod $DIR failed"
134         # access w/o context
135         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
136         $RUNAS touch $DIR
137         $RUNAS touch $file || error "should not fail"
138         [ -f $file ] || error "$file not found"
139 }
140 run_test 1 "create file"
141
142 test_2() {
143     local file1=$DIR/$tfile-1
144     local file2=$DIR/$tfile-2
145
146     chmod 0777 $DIR || error "chmod $DIR failed"
147     # current access should be ok
148     $RUNAS touch $file1 || error "can't touch $file1"
149     [ -f $file1 ] || error "$file1 not found"
150
151         # cleanup all cred/ctx and touch
152         $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
153         $RUNAS touch $file2 && error "unexpected success"
154 }
155 run_test 2 "lfs flushctx"
156
157 test_3() {
158     local file=$DIR/$tfile
159
160     # create file
161     echo "aaaaaaaaaaaaaaaaa" > $file
162     chmod 0666 $file
163     $CHECKSTAT -p 0666 $file || error "$UID checkstat error"
164     $RUNAS $CHECKSTAT -p 0666 $file || error "$RUNAS_ID checkstat error"
165     $RUNAS cat $file > /dev/null || error "$RUNAS_ID cat error"
166
167     # start multiop
168     $RUNAS $MULTIOP $file o_r &
169     OPPID=$!
170     # wait multiop finish its open()
171     sleep 1
172
173     # cleanup all cred/ctx and check
174     # metadata check should fail, but file data check should success
175     # because we always use root credential to OSTs
176     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
177     echo "destroied credentials/contexs for $RUNAS_ID"
178     $RUNAS $CHECKSTAT -p 0666 $file && error "checkstat succeed"
179     kill -s 10 $OPPID
180     wait $OPPID || error "read file data failed"
181     echo "read file data OK"
182 }
183 run_test 3 "local cache under DLM lock"
184
185 test_6() {
186     local nfile=10
187
188     mkdir $DIR/d6 || error "mkdir $DIR/d6 failed"
189     for ((i=0; i<$nfile; i++)); do
190         dd if=/dev/zero of=$DIR/d6/file$i bs=8k count=1 || error "dd file$i failed"
191     done
192     ls -l $DIR/d6/* > /dev/null || error "ls failed"
193     rm -rf $DIR2/d6/* || error "rm failed"
194     rmdir $DIR2/d6/ || error "rmdir failed"
195 }
196 run_test 6 "test basic DLM callback works"
197
198 test_7() {
199         local tdir=$DIR/d7
200         local num_osts
201
202         # for open(), client only reserve space for default stripe count lovea,
203         # and server may return larger lovea in reply (because of larger stripe
204         # count), client need call enlarge_reqbuf() and save the replied lovea
205         # in request for future possible replay.
206         #
207         # Note: current script does NOT guarantee enlarge_reqbuf() will be in
208         # the path, however it does work in local test which has 2 OSTs and
209         # default stripe count is 1.
210         num_osts=$($LFS getstripe $MOUNT | egrep "^[0-9]*:.*ACTIVE" | wc -l)
211         echo "found $num_osts active OSTs"
212         [ $num_osts -lt 2 ] &&
213                 echo "skipping $TESTNAME (must have >= 2 OSTs)" && return
214
215         mkdir $tdir || error "mkdir $tdir failed"
216         $LFS setstripe -c $num_osts $tdir || error "setstripe -c $num_osts"
217
218         echo "creating..."
219         for ((i = 0; i < 20; i++)); do
220                 dd if=/dev/zero of=$tdir/f$i bs=4k count=16 2>/dev/null
221         done
222         echo "reading..."
223         for ((i = 0; i < 20; i++)); do
224                 dd if=$tdir/f$i of=/dev/null bs=4k count=16 2>/dev/null
225         done
226         rm -rf $tdir
227 }
228 run_test 7 "exercise enlarge_reqbuf()"
229
230 test_8()
231 {
232     local ATHISTORY=$(do_facet $SINGLEMDS "find /sys/ -name at_history")
233     local ATOLDBASE=$(do_facet $SINGLEMDS "cat $ATHISTORY")
234     local REQ_DELAY
235     do_facet $SINGLEMDS "echo 8 >> $ATHISTORY"
236
237     mkdir -p $DIR/d8
238     chmod a+w $DIR/d8
239
240     $LCTL dk > /dev/null
241     debugsave
242     sysctl -w lnet.debug="+other"
243
244     # wait for the at estimation come down, this is faster
245     while [ true ]; do
246         REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
247                    awk '/portal 12/ {print $5}' | tail -1`
248         [ $REQ_DELAY -le 5 ] && break
249         echo "current AT estimation is $REQ_DELAY, wait a little bit"
250         sleep 8
251     done
252     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
253
254     # sleep sometime in ctx handle
255     do_facet $SINGLEMDS lctl set_param fail_val=$REQ_DELAY
256 #define OBD_FAIL_SEC_CTX_HDL_PAUSE       0x1204
257     do_facet $SINGLEMDS lctl set_param fail_loc=0x1204
258
259     $RUNAS $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
260
261     $RUNAS touch $DIR/d8/f &
262     TOUCHPID=$!
263     echo "waiting for touch (pid $TOUCHPID) to finish..."
264     sleep 2 # give it a chance to really trigger context init rpc
265     do_facet $SINGLEMDS $LCTL set_param fail_loc=0
266     wait $TOUCHPID || error "touch should have succeeded"
267
268     $LCTL dk | grep "Early reply #" || error "No early reply"
269
270     debugrestore
271     do_facet $SINGLEMDS "echo $ATOLDBASE >> $ATHISTORY" || true
272 }
273 run_test 8 "Early reply sent for slow gss context negotiation"
274
275 #
276 # following tests will manipulate flavors and may end with any flavor set,
277 # so each test should not assume any start flavor.
278 #
279
280 test_90() {
281     if [ "$SLOW" = "no" ]; then
282         total=10
283     else
284         total=60
285     fi
286
287     restore_to_default_flavor
288         set_rule $FSNAME any any gssnull
289         wait_flavor all2all gssnull
290
291     start_dbench
292
293     for ((n=0;n<$total;n++)); do
294         sleep 2
295         check_dbench
296         echo "flush ctx ($n/$total) ..."
297         $LFS flushctx $MOUNT || error "can't flush context on $MOUNT"
298     done
299     check_dbench
300     #sleep to let ctxs be re-established
301     sleep 10
302     stop_dbench
303 }
304 run_test 90 "recoverable from losing contexts under load"
305
306 test_99() {
307     local nrule_old=0
308     local nrule_new=0
309     local max=64
310
311     #
312     # general rules
313     #
314     nrule_old=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
315                | grep "$FSNAME.srpc.flavor." | wc -l`
316     echo "original general rules: $nrule_old"
317
318     for ((i = $nrule_old; i < $max; i++)); do
319         set_rule $FSNAME elan$i any gssnull || error "set rule $i"
320     done
321     for ((i = $nrule_old; i < $max; i++)); do
322         set_rule $FSNAME elan$i any || error "remove rule $i"
323     done
324
325     nrule_new=`do_facet mgs lctl get_param -n mgs.MGS.live.$FSNAME 2>/dev/null \
326                | grep "$FSNAME.srpc.flavor." | wc -l`
327     if [ $nrule_new != $nrule_old ]; then
328         error "general rule: $nrule_new != $nrule_old"
329     fi
330 }
331 run_test 99 "set large number of sptlrpc rules"
332
333 error_dbench()
334 {
335     local err_str=$1
336
337     killall -9 dbench
338     sleep 1
339
340     error $err_str
341 }
342
343 test_100() {
344         # started from default flavors
345         restore_to_default_flavor
346
347         # running dbench background
348         start_dbench
349
350         #
351         # all: null -> gssnull -> plain
352         #
353         set_rule $FSNAME any any gssnull
354         wait_flavor all2all gssnull || error_dbench "1"
355         check_dbench
356
357         set_rule $FSNAME any any plain
358         wait_flavor all2all plain || error_dbench "2"
359         check_dbench
360
361         #
362         # M - M: gssnull
363         # C - M: gssnull
364         # M - O: gssnull
365         # C - O: gssnull
366         #
367         set_rule $FSNAME any mdt2mdt gssnull
368         wait_flavor mdt2mdt gssnull || error_dbench "3"
369         check_dbench
370
371         set_rule $FSNAME any cli2mdt gssnull
372         wait_flavor cli2mdt gssnull || error_dbench "4"
373         check_dbench
374
375         set_rule $FSNAME any mdt2ost gssnull
376         wait_flavor mdt2ost gssnull || error_dbench "5"
377         check_dbench
378
379         set_rule $FSNAME any cli2ost gssnull
380         wait_flavor cli2ost gssnull || error_dbench "6"
381         check_dbench
382
383         #
384         # * - MDT0: plain
385         # * - OST0: plain
386         #
387         # nothing should be changed because they are override by above dir rules
388         #
389         set_rule $FSNAME-MDT0000 any any plain
390         set_rule $FSNAME-OST0000 any any plain
391         wait_flavor mdt2mdt gssnull || error_dbench "7"
392         wait_flavor cli2mdt gssnull || error_dbench "8"
393         check_dbench
394         wait_flavor mdt2ost gssnull || error_dbench "9"
395         wait_flavor cli2ost gssnull || error_dbench "10"
396
397         #
398         # delete all dir-specific rules
399         #
400         set_rule $FSNAME any mdt2mdt
401         set_rule $FSNAME any cli2mdt
402         set_rule $FSNAME any mdt2ost
403         set_rule $FSNAME any cli2ost
404         wait_flavor mdt2mdt gssnull $((MDSCOUNT - 1)) || error_dbench "11"
405         wait_flavor cli2mdt gssnull $(get_clients_mount_count) ||
406                 error_dbench "12"
407         check_dbench
408         wait_flavor mdt2ost gssnull $MDSCOUNT || error_dbench "13"
409         wait_flavor cli2ost gssnull $(get_clients_mount_count) ||
410                 error_dbench "14"
411         check_dbench
412
413         #
414         # remove:
415         #  * - MDT0: gssnull
416         #  * - OST0: gssnull
417         #
418         set_rule $FSNAME-MDT0000 any any
419         set_rule $FSNAME-OST0000 any any || error_dbench "15"
420         wait_flavor all2all plain || error_dbench "16"
421         check_dbench
422
423         stop_dbench
424 }
425 run_test 100 "change security flavor on the fly under load"
426
427 switch_sec_test()
428 {
429     local flavor0=$1
430     local flavor1=$2
431     local filename=$DIR/$tfile
432     local multiop_pid
433     local num
434
435     #
436     # after set to flavor0, start multop which use flavor0 rpc, and let
437     # server drop the reply; then switch to flavor1, the resend should be
438     # completed using flavor1. To exercise the code of switching ctx/sec
439     # for a resend request.
440     #
441     log ">>>>>>>>>>>>>>> Testing $flavor0 -> $flavor1 <<<<<<<<<<<<<<<<<<<"
442
443     set_rule $FSNAME any cli2mdt $flavor0
444     wait_flavor cli2mdt $flavor0
445     rm -f $filename || error "remove old $filename failed"
446
447 #MDS_REINT = 36
448 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC     0x513
449     do_facet $SINGLEMDS lctl set_param fail_val=36
450     do_facet $SINGLEMDS lctl set_param fail_loc=0x513
451     log "starting multiop"
452     $MULTIOP $filename m &
453     multiop_pid=$!
454     echo "multiop pid=$multiop_pid"
455     sleep 1
456
457     set_rule $FSNAME any cli2mdt $flavor1
458     wait_flavor cli2mdt $flavor1
459
460     num=`ps --no-headers -p $multiop_pid 2>/dev/null | wc -l`
461     [ $num -eq 1 ] || error "multiop($multiop_pid) already ended ($num)"
462     echo "process $multiop_pid is still hanging there... OK"
463
464     do_facet $SINGLEMDS lctl set_param fail_loc=0
465     log "waiting for multiop ($multiop_pid) to finish"
466     wait $multiop_pid || error "multiop returned error"
467 }
468
469 test_101()
470 {
471         # started from default flavors
472         restore_to_default_flavor
473
474         switch_sec_test null    plain
475         switch_sec_test plain   gssnull
476         switch_sec_test gssnull null
477         switch_sec_test null    gssnull
478         switch_sec_test gssnull plain
479         switch_sec_test plain   gssnull
480 }
481 run_test 101 "switch ctx/sec for resending request"
482
483 error_102()
484 {
485     local err_str=$1
486
487     killall -9 dbench
488     sleep 1
489
490     error $err_str
491 }
492
493 test_102() {
494     # started from default flavors
495     restore_to_default_flavor
496
497     # run dbench background
498     start_dbench
499
500         echo "Testing null->gssnull->plain->null"
501         set_rule $FSNAME any any gssnull
502         set_rule $FSNAME any any plain
503         set_rule $FSNAME any any null
504
505     check_dbench
506     wait_flavor all2all null || error_dbench "1"
507     check_dbench
508
509     echo "waiting for 15s and check again"
510     sleep 15
511     check_dbench
512
513         echo "Testing null->gssnull->null->gssnull->null..."
514         for ((i=0; i<10; i++)); do
515                 set_rule $FSNAME any any gssnull
516                 set_rule $FSNAME any any null
517         done
518         set_rule $FSNAME any any gssnull
519
520         check_dbench
521         wait_flavor all2all gssnull || error_dbench "2"
522         check_dbench
523
524     echo "waiting for 15s and check again"
525     sleep 15
526     check_dbench
527
528     stop_dbench
529 }
530 run_test 102 "survive from insanely fast flavor switch"
531
532 test_150() {
533     local mount_opts
534     local count
535     local clients=$CLIENTS
536
537     [ -z $clients ] && clients=$HOSTNAME
538
539     # started from default flavors
540     restore_to_default_flavor
541
542     # at this time no rules has been set on mgs; mgc use null
543     # flavor connect to mgs.
544     count=`flvr_cnt_mgc2mgs null`
545     [ $count -eq 1 ] || error "$count mgc connection use null flavor"
546
547     zconf_umount_clients $clients $MOUNT || return 1
548
549     # mount client with conflict flavor - should fail
550     mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=gssnull"
551     zconf_mount_clients $clients $MOUNT $mount_opts &&
552         error "mount with conflict flavor should have failed"
553
554     # mount client with same flavor - should succeed
555     mount_opts="${MOUNT_OPTS:+$MOUNT_OPTS,}mgssec=null"
556     zconf_mount_clients $clients $MOUNT $mount_opts ||
557         error "mount with same flavor should have succeeded"
558     zconf_umount_clients $clients $MOUNT || return 2
559
560     # mount client with default flavor - should succeed
561     zconf_mount_clients $clients $MOUNT || \
562         error "mount with default flavor should have succeeded"
563 }
564 run_test 150 "secure mgs connection: client flavor setting"
565
566 test_151() {
567         local save_opts
568
569         # set mgs only accept gssnull
570         set_rule _mgs any any gssnull
571
572     # umount everything, modules still loaded
573     stopall
574
575     # mount mgs with default flavor, in current framework it means mgs+mdt1.
576     # the connection of mgc of mdt1 to mgs is expected fail.
577     DEVNAME=$(mdsdevname 1)
578     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with default flavor should have failed"
579
580     # mount with unauthorized flavor should fail
581     save_opts=$MDS_MOUNT_OPTS
582     MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=null"
583     start mds1 $DEVNAME $MDS_MOUNT_OPTS && error "mount with unauthorized flavor should have failed"
584     MDS_MOUNT_OPTS=$save_opts
585
586     # mount with designated flavor should succeed
587     save_opts=$MDS_MOUNT_OPTS
588         MDS_MOUNT_OPTS="$MDS_MOUNT_OPTS,mgssec=gssnull"
589         start mds1 $DEVNAME $MDS_MOUNT_OPTS ||
590                 error "mount with designated flavor should have succeeded"
591         MDS_MOUNT_OPTS=$save_opts
592
593         stop mds1 -f
594 }
595 run_test 151 "secure mgs connection: server flavor control"
596
597 stop_gss_daemons
598 if $GSS_KRB5 || $GSS_SK; then
599         start_gss_daemons
600 fi
601
602 restore_to_default_flavor
603
604 complete $SECONDS
605 check_and_cleanup_lustre
606 exit_status