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