Whamcloud - gitweb
LU-14739 quota: nodemap squashed root cannot bypass quota
[fs/lustre-release.git] / lustre / tests / auster
1 #!/bin/bash
2 #
3 #
4 # auster - drive lustre tests
5 # TODO
6 #  1. --time-limt <seconds>  add per test time limit, kill test if it runs to long
7 #  2. Read list of tests to run from a file. same syntax as cli, but one test per line
8 #  3. Run test on remote node
9 #  4. Use long opts for auster options
10
11 set -e
12
13 export TF_FAIL=/tmp/tf.fail
14 export TF_SKIP=/tmp/tf.skip
15
16 usage() {
17         less -F <<EOF
18 Usage ${0##*/} [options]  suite [suite options] [suite [suite options]]
19 Run Lustre regression tests suites.
20       -c CONFIG Test environment config file
21       -d LOGDIR Top level directory for logs
22       -D FULLLOGDIR Full directory for logs
23       -f STR    Config name (cfg/<name>.sh)
24       -g GROUP  Test group file (Overrides tests listed on command line)
25       -S TESTSUITE First test suite to run allows for restarts
26       -H        Honor the EXCEPT and ALWAYS_EXCEPT list when --only is used
27       -i N      Repeat tests N times (default 1). A new directory
28                 will be created under LOGDIR for each iteration.
29       -k        Don't stop when subtests fail
30       -R        Remount lustre between tests
31       -r        Reformat (during initial configuration if needed)
32       -s        SLOW=yes
33       -v        Verbose mode
34       -l        Send logs to the Maloo database after run
35                   (can be done later by running maloo_upload.sh)
36       -L        Script language of test suite. Default: bash
37       -N        No setup. Do not setup Lustre prior to executing test suite.
38       -h        This help.
39
40 Suite options
41 These are suite specific options that can be specified after each suite on
42 the command line.
43    suite-name  [options]
44       --only LIST         Run only specific list of subtests
45       --except LIST       Skip list of subtests
46       --start-at SUBTEST  Start testing from subtest
47       --stop-at SUBTEST   Stop testing at subtest
48       --time-limit LIMIT  Don't allow this suite to run longer
49                           than LIMT seconds. [UNIMPLEMENTED]
50
51 Example usage:
52 Run all of sanity and all of replay-single except for 70b with SLOW=y using
53 the default "local" configuration.
54
55   auster -s sanity replay-single --except 70b
56
57 Run all tests in the regression group 5 times using large config.
58
59   auster -f large -g test-groups/regression -i 5
60
61 EOF
62         exit
63 }
64
65 dry_run=false
66 do_reset=false
67 verbose=false
68 repeat_count=1
69 upload_logs=false
70 reformat=false
71 script_lang=bash
72 test_logs_dir=/tmp/test_logs/$(date +%Y-%m-%d)/$(date +%H%M%S)
73 export HONOR_EXCEPT=
74 do_setup=true
75 export ${SLOW:=no}
76 export ${NAME:=local}
77 while getopts "c:d:D:nkf:S:g:Hi:rRslL:Nhv" opt
78 do
79         case "$opt" in
80                 c) export CONFIG=$OPTARG;;
81                 d) test_logs_dir=$OPTARG/$(date +%Y-%m-%d)/$(date +%H%M%S);;
82                 D) test_logs_dir=$OPTARG;;
83                 g) test_group_file=$OPTARG;;
84                 S) FIRST_SUITE=$OPTARG;;
85                 k) export FAIL_ON_ERROR=false;;
86                 n) dry_run=:;;
87                 v) verbose=:;;
88                 H) export HONOR_EXCEPT="y";;
89                 i) repeat_count=$OPTARG;;
90                 f) NAME=$OPTARG;;
91                 R) do_reset=:;;
92                 r) reformat=:;;
93                 s) export SLOW=yes;;
94                 l) upload_logs=true;;
95                 L) script_lang=$OPTARG;;
96                 N) do_setup=false;;
97                 h|\?) usage;;
98         esac
99 done
100
101 # If a test_group_file is specified, then ignore rest of command line
102 if [[ $test_group_file ]]; then
103     export TEST_GROUP=$(basename $test_group_file)
104     set $(sed 's/#.*$//' $test_group_file)
105 else
106     shift $((OPTIND -1))
107 fi
108
109 reset_lustre() {
110     if $do_reset; then
111         stopall
112         setupall
113     fi
114 }
115
116 STARTTIME=`date +%s`
117
118 : ${LUSTRE:=$(cd $(dirname $0)/..; echo $PWD)}
119 . $LUSTRE/tests/test-framework.sh
120 init_test_env
121
122 print_summary () {
123     trap 0
124     local form="%-13s %-17s %s\n"
125     printf "$form" "status" "script" "skipped tests E(xcluded) S(low)"
126     echo "------------------------------------------------------------------------------------"
127     echo "Done!"
128 }
129
130
131 setup_if_needed() {
132         ! ${do_setup} && return
133         nfs_client_mode && return
134         AUSTER_CLEANUP=false
135
136         local MOUNTED=$(mounted_lustre_filesystems)
137         if $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
138                 check_config_clients $MOUNT
139                 # init_facets_vars
140                 # init_param_vars
141                 return
142         fi
143
144         echo "Lustre is not mounted, trying to do setup ... "
145         $reformat && CLEANUP_DM_DEV=true formatall
146         setupall
147
148         MOUNTED=$(mounted_lustre_filesystems)
149         if ! $(echo $MOUNTED' ' | grep -w -q $MOUNT' '); then
150                 echo "Lustre is not mounted after setup! "
151                 exit 1
152         fi
153         AUSTER_CLEANUP=true
154 }
155
156 cleanup_if_needed() {
157         if $AUSTER_CLEANUP; then
158                 cleanupall
159         fi
160 }
161
162 find_script_in_path() {
163     target=$1
164     path=$2
165     for dir in $(tr : " " <<< $path); do
166         if [ -f $dir/$target ]; then
167             echo $dir/$target
168             return 0
169         fi
170         if [ -f $dir/$target.sh ]; then
171             echo $dir/$target.sh
172             return 0
173         fi
174     done
175     return 1
176 }
177
178 title() {
179     log "-----============= acceptance-small: "$*" ============----- `date`"
180 }
181
182 doit() {
183     if $dry_run; then
184         printf "Would have run: %s\n" "$*"
185         return 0
186     fi
187     if $verbose; then
188         printf "Running: %s\n" "$*"
189     fi
190     "$@"
191 }
192
193
194 run_suite() {
195         local suite_name=$1
196         local suite_script=$2
197         title $suite_name
198         log_test $suite_name
199
200         rm -f $TF_FAIL
201         touch $TF_SKIP
202         local start_ts=$(date +%s)
203         doit $script_lang $suite_script
204         local rc=$?
205         local duration=$(($(date +%s) - $start_ts))
206
207         local status="PASS"
208         if [[ $rc -ne 0 || -f $TF_FAIL ]]; then
209                 status="FAIL"
210         elif [[ -f $TF_SKIP ]]; then
211                 status="SKIP"
212         fi
213         log_test_status $duration $status
214         [[ ! -f $TF_SKIP ]] || rm -f $TF_SKIP
215
216         reset_lustre
217 }
218
219 run_suite_logged() {
220     local suite_name=${1%.sh}
221     local suite=$(echo ${suite_name} | tr "[:lower:]-" "[:upper:]_")
222
223     suite_script=$(find_script_in_path $suite_name $LUSTRE/tests)
224
225     if [[ -z $suite_script ]]; then
226         echo "Can't find test script for $suite_name"
227         return 1
228     fi
229
230     echo "run_suite $suite_name $suite_script"
231     local log_name=${suite_name}.suite_log.$(hostname -s).log
232     if $verbose; then
233         run_suite $suite_name $suite_script 2>&1 |tee  $LOGDIR/$log_name
234     else
235         run_suite $suite_name $suite_script > $LOGDIR/$log_name 2>&1
236     fi
237
238 }
239
240 #
241 # Add this to test-framework somewhere.
242 reset_logging() {
243     export LOGDIR=$1
244     unset YAML_LOG
245     init_logging
246 }
247
248 split_commas() {
249     echo "${*//,/ }"
250 }
251
252 run_suites() {
253     local n=0
254     local argv=("$@")
255     while ((n < repeat_count)); do
256         local RC=0
257         local logdir=${test_logs_dir}
258         local first_suite=$FIRST_SUITE
259         ((repeat_count > 1)) && logdir="$logdir/$n"
260         reset_logging $logdir
261         set -- "${argv[@]}"
262         while [[ -n $1 ]]; do
263             unset ONLY EXCEPT START_AT STOP_AT
264             local opts=""
265             local time_limit=""
266             #echo "argv: $*"
267             suite=$1
268             shift;
269             while [[ -n $1 ]]; do
270                 case "$1" in
271                     --only)
272                         shift;
273                         export ONLY=$(split_commas $1)
274                         opts+="ONLY=$ONLY ";;
275                     --except)
276                         shift;
277                         export EXCEPT=$(split_commas $1)
278                         opts+="EXCEPT=$EXCEPT ";;
279                     --start-at)
280                         shift;
281                         export START_AT=$1
282                         opts+="START_AT=$START_AT ";;
283                     --stop-at)
284                         shift;
285                         export STOP_AT=$1
286                         opts+="STOP_AT=$STOP_AT ";;
287                     --time-limit)
288                         shift;
289                         time_limit=$1;;
290                     *)
291                         break;;
292                 esac
293                 shift
294             done
295             if [ "x"$first_suite == "x" ] || [ $first_suite == $suite ]; then   # If first_suite not set or this is the first suite
296                 echo "running: $suite $opts"
297                 run_suite_logged $suite || RC=$?
298                 unset first_suite
299                 echo $suite returned $RC
300             fi
301         done
302         if $upload_logs; then
303             $upload_script $LOGDIR
304         fi
305         n=$((n + 1))
306     done
307 }
308
309 if [ $upload_logs = true ] ; then
310     upload_script=$(find_script_in_path maloo_upload.sh $PATH:$LUSTRE/tests)
311     if [[ -z $upload_script ]]; then
312         echo "Can't find maloo_upload.sh script"
313         exit 1
314     fi
315
316     if [ ! -r ~/.maloorc ] ; then
317         echo "A ~/.maloorc file is required in order to upload results."
318         echo "Visit your maloo web interface to download your .maloorc file"
319         exit 1
320     fi
321 fi
322
323 export NAME MOUNT START CLEAN
324 . ${CONFIG:-$LUSTRE/tests/cfg/$NAME.sh}
325
326 assert_env mds_HOST
327 assert_env ost_HOST OSTCOUNT
328 assert_env FSNAME MOUNT MOUNT2
329
330 echo "Started at `date`"
331 setup_if_needed
332
333 run_suites "$@"
334 RC=$?
335
336 if [[ $RC -eq 0 ]]; then
337     cleanup_if_needed
338 fi
339
340 echo "Finished at `date` in $((`date +%s` - $STARTTIME))s"
341 echo "$0: completed with rc $RC" && exit $RC