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