Whamcloud - gitweb
land b_groups onto 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
18 TMP=${TMP:-/tmp}
19 FSTYPE=${FSTYPE:-ext3}
20
21 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
22 CREATETEST=${CREATETEST:-createtest}
23 LFS=${LFS:-lfs}
24 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
25 LFIND=${LFIND:-"$LFS find"}
26 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
27 LCTL=${LCTL:-lctl}
28 MCREATE=${MCREATE:-mcreate}
29 OPENFILE=${OPENFILE:-openfile}
30 OPENUNLINK=${OPENUNLINK:-openunlink}
31 TOEXCL=${TOEXCL:-toexcl}
32 TRUNCATE=${TRUNCATE:-truncate}
33 MUNLINK=${MUNLINK:-munlink}
34 SOCKETSERVER=${SOCKETSERVER:-socketserver}
35 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
36 IOPENTEST1=${IOPENTEST1:-iopentest1}
37 IOPENTEST2=${IOPENTEST2:-iopentest2}
38
39 if [ $UID -ne 0 ]; then
40         RUNAS_ID="$UID"
41         RUNAS=""
42 else
43         RUNAS_ID=${RUNAS_ID:-500}
44         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
45 fi
46
47 export NAME=${NAME:-local}
48
49 SAVE_PWD=$PWD
50
51 clean() {
52         echo -n "cln.."
53         sh llmountcleanup.sh > /dev/null || exit 20
54         I_MOUNTED=no
55 }
56 CLEAN=${CLEAN:-clean}
57
58 start() {
59         echo -n "mnt.."
60         sh llrmount.sh > /dev/null || exit 10
61         I_MOUNTED=yes
62         echo "done"
63 }
64 START=${START:-start}
65
66 log() {
67         echo "$*"
68         lctl mark "$*" 2> /dev/null || true
69 }
70
71 trace() {
72         log "STARTING: $*"
73         strace -o $TMP/$1.strace -ttt $*
74         RC=$?
75         log "FINISHED: $*: rc $RC"
76         return 1
77 }
78 TRACE=${TRACE:-""}
79
80 check_kernel_version() {
81         VERSION_FILE=/proc/fs/lustre/kernel_version
82         WANT_VER=$1
83         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
84         GOT_VER=`cat $VERSION_FILE`
85         [ $GOT_VER -ge $WANT_VER ] && return 0
86         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
87         return 1
88 }
89
90 run_one() {
91         if ! mount | grep -q $DIR; then
92                 $START
93         fi
94         echo -1 >/proc/sys/portals/debug        
95         log "== test $1: $2"
96         export TESTNAME=test_$1
97         test_$1 || error "test_$1: exit with rc=$?"
98         unset TESTNAME
99         pass
100         cd $SAVE_PWD
101         $CLEAN
102 }
103
104 build_test_filter() {
105         for O in $ONLY; do
106             eval ONLY_${O}=true
107         done
108         for E in $EXCEPT $ALWAYS_EXCEPT; do
109             eval EXCEPT_${E}=true
110         done
111 }
112
113 _basetest() {
114     echo $*
115 }
116
117 basetest() {
118     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
119 }
120
121 run_test() {
122          base=`basetest $1`
123          if [ "$ONLY" ]; then
124                  testname=ONLY_$1
125                  if [ ${!testname}x != x ]; then
126                         run_one $1 "$2"
127                         return $?
128                  fi
129                  testname=ONLY_$base
130                  if [ ${!testname}x != x ]; then
131                          run_one $1 "$2"
132                          return $?
133                  fi
134                  echo -n "."
135                  return 0
136         fi
137         testname=EXCEPT_$1
138         if [ ${!testname}x != x ]; then
139                  echo "skipping excluded test $1"
140                  return 0
141         fi
142         testname=EXCEPT_$base
143         if [ ${!testname}x != x ]; then
144                  echo "skipping excluded test $1 (base $base)"
145                  return 0
146         fi
147         run_one $1 "$2"
148         return $?
149 }
150
151 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
152
153 error() { 
154         log "FAIL: $@"
155         if [ "$SANITYLOG" ]; then
156                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
157         else
158                 exit 1
159         fi
160 }
161
162 pass() { 
163         echo PASS
164 }
165
166 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
167 if [ -z "$MOUNT" ]; then
168         sh llmount.sh
169         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
170         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
171         I_MOUNTED=yes
172 fi
173
174 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
175
176 DIR=${DIR:-$MOUNT}
177 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
178
179 OSTCOUNT=`cat /proc/fs/lustre/llite/fs0/lov/numobd`
180 STRIPECOUNT=`cat /proc/fs/lustre/llite/fs0/lov/stripecount`
181 STRIPESIZE=`cat /proc/fs/lustre/llite/fs0/lov/stripesize`
182
183 build_test_filter
184
185 test_0() {
186         touch $DIR/f
187         $CHECKSTAT -t file $DIR/f || error
188         rm $DIR/f
189         $CHECKSTAT -a $DIR/f || error
190 }
191 run_test 0 "touch .../f ; rm .../f ============================="
192
193 mdsdevice(){
194         lctl << EOF
195         dl
196         quit
197 EOF
198 }
199
200 mynidstr(){
201         lctl << EOF
202         network tcp
203         mynid
204         quit
205 EOF
206 }
207
208 test_1(){
209         mdsnum=`mdsdevice|awk ' $3=="mds" {print $1}'`
210         if [ ! -z "$mdsnum" ];then
211         mynid=`mynidstr|awk '{print $4}'`
212         mkdir $DIR/test_0a_dir1
213         touch $DIR/test_0a_file1
214         ln -s $DIR/test_0a_file1 $DIR/test_0a_filelink1
215         chmod 0777 $DIR
216         lctl << EOF
217         device $mdsnum 
218         root_squash 500:500
219         root_squash
220         quit
221 EOF
222         mkdir $DIR/test_0a_dir2
223         touch $DIR/test_0a_file2
224         ln -s $DIR/test_0a_file2 $DIR/test_0a_filelink2
225         $CHECKSTAT -t dir   -u 500  $DIR/test_0a_dir2 || error
226         $CHECKSTAT -t file  -u 500  $DIR/test_0a_file2 || error
227         $CHECKSTAT -t link  -u 500  $DIR/test_0a_filelink2 || error
228         lctl << EOF
229         device $mdsnum 
230         root_squash 500:500 $mynid
231         root_squash
232         quit
233 EOF
234         mkdir $DIR/test_0a_dir3
235         touch $DIR/test_0a_file3
236         ln -s $DIR/test_0a_file3 $DIR/test_0a_filelink3
237         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir3 || error
238         $CHECKSTAT -t file -u root $DIR/test_0a_file3 || error
239         $CHECKSTAT -t link -u root $DIR/test_0a_filelink3 || error
240         lctl << EOF
241         device $mdsnum 
242         root_squash root:root
243         root_squash
244         quit
245 EOF
246         mkdir $DIR/test_0a_dir4
247         touch $DIR/test_0a_file4
248         ln -s $DIR/test_0a_file4 $DIR/test_0a_filelink4
249         $CHECKSTAT -t dir -u root  $DIR/test_0a_dir4 || error
250         $CHECKSTAT -t file -u root $DIR/test_0a_file4 || error
251         $CHECKSTAT -t link -u root $DIR/test_0a_filelink4 || error
252         rm -rf $DIR/test_0a*
253         chmod 0755 $DIR
254         fi
255 }
256
257 run_test 1 "test root_squash ============================"
258
259 TMPDIR=$OLDTMPDIR
260 TMP=$OLDTMP
261 HOME=$OLDHOME
262
263 log "cleanup: ======================================================"
264 if [ "`mount | grep ^$NAME`" ]; then
265         rm -rf $DIR/[Rdfs][1-9]*
266         if [ "$I_MOUNTED" = "yes" ]; then
267                 sh llmountcleanup.sh || error
268         fi
269 fi
270
271 echo '=========================== finished ==============================='
272 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true