Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / tests / sanity-sec.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 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
11 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
12
13 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
14
15 SRCDIR=`dirname $0`
16 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
17 export SECURITY=${SECURITY:-"null"}
18
19 TMP=${TMP:-/tmp}
20 FSTYPE=${FSTYPE:-ext3}
21 NETTYPE=${NETTYPE:-tcp}
22
23 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
24 CREATETEST=${CREATETEST:-createtest}
25 LFS=${LFS:-lfs}
26 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
27 LFIND=${LFIND:-"$LFS find"}
28 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
29 LCTL=${LCTL:-lctl}
30 MCREATE=${MCREATE:-mcreate}
31 OPENFILE=${OPENFILE:-openfile}
32 OPENUNLINK=${OPENUNLINK:-openunlink}
33 TOEXCL=${TOEXCL:-toexcl}
34 TRUNCATE=${TRUNCATE:-truncate}
35 MUNLINK=${MUNLINK:-munlink}
36 SOCKETSERVER=${SOCKETSERVER:-socketserver}
37 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
38 IOPENTEST1=${IOPENTEST1:-iopentest1}
39 IOPENTEST2=${IOPENTEST2:-iopentest2}
40 RUNAS=${RUNAS:-"runas"}
41
42 . krb5_env.sh
43
44 if [ $UID -ne 0 ]; then
45     echo "Must be run as root"
46     exit 1
47 fi
48
49 export NAME=${NAME:-local}
50
51 SAVE_PWD=$PWD
52
53 clean() {
54         echo -n "cln.."
55         sh llmountcleanup.sh > /dev/null || exit 20
56         I_MOUNTED=no
57 }
58 CLEAN=${CLEAN:-clean}
59
60 start() {
61         echo -n "mnt.."
62         sh llrmount.sh > /dev/null || exit 10
63         I_MOUNTED=yes
64         echo "done"
65 }
66 START=${START:-start}
67
68 log() {
69         echo "$*"
70         lctl mark "$*" 2> /dev/null || true
71 }
72
73 trace() {
74         log "STARTING: $*"
75         strace -o $TMP/$1.strace -ttt $*
76         RC=$?
77         log "FINISHED: $*: rc $RC"
78         return 1
79 }
80 TRACE=${TRACE:-""}
81
82 check_kernel_version() {
83         VERSION_FILE=/proc/fs/lustre/kernel_version
84         WANT_VER=$1
85         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
86         GOT_VER=`cat $VERSION_FILE`
87         [ $GOT_VER -ge $WANT_VER ] && return 0
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 run_one() {
93         if ! cat /proc/mounts | grep -q $DIR; then
94                 $START
95         fi
96         echo -1 >/proc/sys/portals/debug        
97         log "== test $1: $2"
98         export TESTNAME=test_$1
99         test_$1 || error "test_$1: exit with rc=$?"
100         unset TESTNAME
101         pass
102         cd $SAVE_PWD
103         $CLEAN
104 }
105
106 build_test_filter() {
107         for O in $ONLY; do
108             eval ONLY_${O}=true
109         done
110         for E in $EXCEPT $ALWAYS_EXCEPT; do
111             eval EXCEPT_${E}=true
112         done
113 }
114
115 _basetest() {
116     echo $*
117 }
118
119 basetest() {
120     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
121 }
122
123 run_test() {
124          base=`basetest $1`
125          if [ "$ONLY" ]; then
126                  testname=ONLY_$1
127                  if [ ${!testname}x != x ]; then
128                         run_one $1 "$2"
129                         return $?
130                  fi
131                  testname=ONLY_$base
132                  if [ ${!testname}x != x ]; then
133                          run_one $1 "$2"
134                          return $?
135                  fi
136                  echo -n "."
137                  return 0
138         fi
139         testname=EXCEPT_$1
140         if [ ${!testname}x != x ]; then
141                  echo "skipping excluded test $1"
142                  return 0
143         fi
144         testname=EXCEPT_$base
145         if [ ${!testname}x != x ]; then
146                  echo "skipping excluded test $1 (base $base)"
147                  return 0
148         fi
149         run_one $1 "$2"
150         return $?
151 }
152
153 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
154
155 error() { 
156         log "FAIL: $@"
157         if [ "$SANITYLOG" ]; then
158                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
159         else
160                 exit 1
161         fi
162 }
163
164 pass() { 
165         echo PASS
166 }
167
168 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
169 if [ -z "$MOUNT" ]; then
170         sh llmount.sh
171         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
172         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
173         I_MOUNTED=yes
174 fi
175
176 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
177
178 DIR=${DIR:-$MOUNT}
179 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
180
181 OSTCOUNT=`cat /proc/fs/lustre/llite/fs0/lov/numobd`
182 STRIPECOUNT=`cat /proc/fs/lustre/llite/fs0/lov/stripecount`
183 STRIPESIZE=`cat /proc/fs/lustre/llite/fs0/lov/stripesize`
184
185 build_test_filter
186
187 test_0() {
188         touch $DIR/f
189         $CHECKSTAT -t file $DIR/f || error
190         rm $DIR/f
191         $CHECKSTAT -a $DIR/f || error
192 }
193 run_test 0 "touch .../f ; rm .../f ============================="
194
195 mdsdevice(){
196         lctl << EOF
197         dl
198         quit
199 EOF
200 }
201
202 mynidstr(){
203         lctl << EOF
204         network $NETTYPE
205         shownid
206         quit
207 EOF
208 }
209
210 test_1(){
211         mdsnum=`mdsdevice|awk ' $3=="mds" {print $1}'`
212         if [ ! -z "$mdsnum" ];then
213         mynid=`mynidstr`
214         mkdir $DIR/test_0a_dir1
215         touch $DIR/test_0a_file1
216         ln -s $DIR/test_0a_file1 $DIR/test_0a_filelink1
217         chmod 0777 $DIR
218         lctl << EOF
219         device $mdsnum 
220         root_squash 500:500
221         root_squash
222         quit
223 EOF
224         mkdir $DIR/test_0a_dir2
225         touch $DIR/test_0a_file2
226         ln -s $DIR/test_0a_file2 $DIR/test_0a_filelink2
227         $CHECKSTAT -t dir   -u 500  $DIR/test_0a_dir2 || error
228         $CHECKSTAT -t file  -u 500  $DIR/test_0a_file2 || error
229         $CHECKSTAT -t link  -u 500  $DIR/test_0a_filelink2 || error
230         lctl << EOF
231         device $mdsnum 
232         root_squash 500:500 $mynid
233         root_squash
234         quit
235 EOF
236         mkdir $DIR/test_0a_dir3
237         touch $DIR/test_0a_file3
238         ln -s $DIR/test_0a_file3 $DIR/test_0a_filelink3
239         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir3 || error
240         $CHECKSTAT -t file -u root $DIR/test_0a_file3 || error
241         $CHECKSTAT -t link -u root $DIR/test_0a_filelink3 || error
242         lctl << EOF
243         device $mdsnum 
244         root_squash root:root
245         root_squash
246         quit
247 EOF
248         mkdir $DIR/test_0a_dir4
249         touch $DIR/test_0a_file4
250         ln -s $DIR/test_0a_file4 $DIR/test_0a_filelink4
251         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir4 || error
252         $CHECKSTAT -t file -u root $DIR/test_0a_file4 || error
253         $CHECKSTAT -t link -u root $DIR/test_0a_filelink4 || error
254         rm -rf $DIR/test_0a*
255         chmod 0755 $DIR
256         fi
257 }
258
259 run_test 1 "test root_squash ============================"
260
261 test_2() {
262         touch $DIR/f2
263                                                                                                                              
264         #test set/get xattr
265         setfattr -n trusted.name1 -v value1 $DIR/f2 || error
266         [ "`getfattr -n trusted.name1 $DIR/f2 2> /dev/null | \
267         grep "trusted.name1"`" == "trusted.name1=\"value1\"" ] || error
268                                                                                                                              
269         setfattr -n user.author1 -v author1 $DIR/f2 || error
270         [ "`getfattr -n user.author1 $DIR/f2 2> /dev/null | \
271         grep "user.author1"`" == "user.author1=\"author1\"" ] || error
272
273         # test listxattr
274         setfattr -n trusted.name2 -v value2 $DIR/f2 || error
275         setfattr -n trusted.name3 -v value3 $DIR/f2 || error
276         [ `getfattr -d -m "^trusted" $DIR/f2 2> /dev/null | \
277         grep "trusted" | wc -l` -eq 5 ] || error
278
279                                                                                                                              
280         setfattr -n user.author2 -v author2 $DIR/f2 || error
281         setfattr -n user.author3 -v author3 $DIR/f2 || error
282         [ `getfattr -d -m "^user" $DIR/f2 2> /dev/null | \
283         grep "user" | wc -l` -eq 3 ] || error
284         #test removexattr
285         setfattr -x trusted.name1 $DIR/f2 2> /dev/null || error
286         getfattr -d -m trusted $DIR/f2 2> /dev/null | \
287         grep "trusted.name1" && error || true
288
289         setfattr -x user.author1 $DIR/f2 2> /dev/null || error
290         getfattr -d -m user $DIR/f2 2> /dev/null | \
291         grep "user.author1" && error || true
292 }
293 run_test 2 "set/get xattr test (trusted xattr only) ============"
294
295 run_acl_subtest()
296 {
297     $SAVE_PWD/acl/run $SAVE_PWD/acl/$1.test
298     return $?
299 }
300
301 test_3 () {
302     # acl tests are using user "bin" and "daemon", which uid are 1 and 2
303     # in most distributions
304     if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
305         $RUNAS -u 1 ./krb5_refresh_cache.sh || exit 20
306         $RUNAS -u 2 ./krb5_refresh_cache.sh || exit 21
307     fi
308
309     SAVE_UMASK=`umask`
310     cd $DIR
311
312     run_acl_subtest cp || return 1
313     run_acl_subtest getfacl-noacl || return 2
314     run_acl_subtest misc || return 3
315     run_acl_subtest permissions || return 4
316     run_acl_subtest setfacl || return 5
317
318     # inheritance test got from HP
319     cp $SAVE_PWD/acl/make-tree . || return 6
320     chmod +x make-tree || return 7
321     run_acl_subtest inheritance || return 8
322     rm -f make-tree
323
324     cd $SAVED_PWD
325     umask $SAVE_UMASK
326 }
327 run_test 3 "==============acl test ============="
328
329 TMPDIR=$OLDTMPDIR
330 TMP=$OLDTMP
331 HOME=$OLDHOME
332
333 log "cleanup: ======================================================"
334 if [ "`mount | grep ^$NAME`" ]; then
335         rm -rf $DIR/[Rdfs][1-9]*
336         if [ "$I_MOUNTED" = "yes" ]; then
337                 sh llmountcleanup.sh || error
338         fi
339 fi
340
341 echo '=========================== finished ==============================='
342 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true