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