Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[fs/lustre-release.git] / lustre / tests / sanity-buffalo.sh
1 #!/bin/sh
2
3 # sanity-buffalo.sh
4 #
5 # This script is used to report the results from a sanity run to buffalo.
6 #
7 # Assumptions: 
8 # - the target host on which you are running the test (be it
9 #   a real machine or a uml session) is accessible via DSH
10
11 export TMP=${TMP:-"/tmp"}
12 export LOG=${LOG:-"$TMP/sanity-buffalo.log"}
13 export DMESGLOG=${DMESGLOG:-"$TMP/sanity-buffalo-dmesg.log"}
14 export OUTPUT=${OUTPUT:-"$TMP/buffalo_mail"}
15 export DSH=${DSH:-"pdsh -S -w"}
16 export LUSTRE_SRC=${LUSTRE_SRC:-"$PWD/.."}
17 export LTESTDIR=${LTESTDIR:-"$PWD/../../ltest"}
18 export TARGET=${TARGET:-"uml"}
19 export SCP=${SCP:-"scp"}
20 #export NO_SHARED_FS=0
21
22 # Changeable buffalo config variables.
23
24 # The following RECIPIENTS string sends results to the buffalo-sandbox.
25 RECIPIENTS=${RECIPIENTS:-"buffalo-sandbox@clusterfs.com"}
26 # The following RECIPIENTS string sends results to buffalo proper.
27 # RECIPIENTS=${RECIPIENTS:-"buffalo_results@clusterfs.com"}
28
29 export TESTNAME=${TESTNAME:-"sanity-buffalo"}
30 export TESTDESC=${TESTDESC:-"Local test in $TARGET for correctness"}
31 export TESTGROUP=${TESTGROUP:-"correctness"}
32 export LUSTRE_TAG=${LUSTRE_TAG:-`cat $PWD/CVS/Tag | cut -c 2-`}
33 export TESTARCH=${TESTARCH:-`uname -r`}
34 export NETWORKTYPE=${NETWORKTYPE:-"tcp"}
35 export MACHINENAME=${MACHINENAME:-`hostname`}
36
37 usage() {
38
39     echo "echo
40 Usage: sanity-buffalo.sh --sender=email_address [--config=config_name] [--test=test_name] [--extra-params=extra_parameters] [--target=hostname] [--help]"
41     if [ x$1 = x-h ]
42         then
43         echo "
44
45 --sender=email_address
46     Email address of the person running the test. (Required)
47
48 --config=config_name
49     Config type to use for lustre setup. Any of the standard script names
50     from lustre/tests are allowable:
51     lov, local, mount2lov, local-large-inode (default)
52
53 --test=test_script
54     Name of the test script to run. Default is \"sanity.sh\".   
55
56 --target=hostname
57     The machine (or uml session) on which to run the test. 
58     Defaults to \"uml\"
59
60 --extra-params=extra_parameters
61     Extra parameters to pass to the test script.
62     e.g. --extra-params=\"START=' ' CLEAN=' '\"
63     NOTE: NAME=lov should not be set here, use --config
64
65 --help
66     Display this usage message
67
68 "
69         exit 0
70     else
71         exit 1
72     fi
73 }
74
75 check_mail() {
76     if [ -z "$SENDER" ] ; then
77         echo "Please supply a valid email address for --sender"
78         usage
79     fi
80 }
81
82 check_config() {
83     if [ -z "$CONFIG_NAME" ] ; then
84         echo "Using default config: local-large-inode"
85         CONFIG_NAME="local-large-inode"
86     fi
87 }
88
89 check_test() {
90     if [ -z "$TESTSCRIPT" ] ; then
91         echo "Running default test: sanity.sh"
92         TESTSCRIPT="sanity.sh"
93     fi
94 }
95
96
97 do_prepare() {
98     if [ -e $LOG ] ; then
99         rm -fr $LOG
100     fi
101     dmesg -c > /dev/null
102     $DSH $TARGET "dmesg -c > /dev/null" || exit 1
103     return 0
104 }
105
106 run_test() {
107     $DSH $TARGET "cd $LUSTRE_SRC/tests && PATH=/sbin:/usr/sbin:\$PATH NAME=$CONFIG_NAME sh llmount.sh 2>&1" | dshbak -c >> $LOG
108     if ! [ $? = 0 ] ; then
109         echo "Can not mount lustre on remoute machine: $TARGET "
110         exit 2
111     fi
112     if [ $NO_SHARED_FS ]; then
113         $SCP $TARGET:$LUSTRE_SRC/tests/${CONFIG_NAME}.xml $PWD/config.xml
114         if ! [ $? = 0 ] ; then
115             echo "Can not get the config file from remoute machine: $TARGET "
116             exit 3
117         fi
118     fi
119
120     COMMAND="cd $LUSTRE_SRC/tests && NAME=$CONFIG_NAME PATH=/sbin:/usr/sbin:\$PATH $EXTRA_PARAMS sh $TESTSCRIPT"
121     echo >> $LOG;echo "COMMAND: $COMMAND" >> $LOG;echo >> $LOG
122
123     $DSH $TARGET "$COMMAND 2>&1" | dshbak -c >> $LOG
124     return $?
125 }
126
127 do_eval() {
128     RC=$1
129
130     if [ $RC -eq 0 ]; then
131         RESULT="pass"
132     else
133         RESULT="fail"
134     fi
135
136     if [ "$RESULT" = "fail" ] ; then   
137         $DSH $TARGET "dmesg" | dshbak -c >> $DMESGLOG
138     fi
139 }
140
141 send_report() {
142     . $LTESTDIR/acceptance/harness/config/common/buffalo.sh
143
144     if [ $NO_SHARED_FS ]; then
145         CONFIG="$PWD/config.xml"
146     else
147         CONFIG="${LUSTRE_SRC}/tests/${CONFIG_NAME}.xml"
148     fi    
149     CONFIGDESC=${CONFIGDESC:-"${TARGET}-${CONFIG_NAME}"}           
150
151     ### send buffalo reports
152     echo "Sending buffalo report..."
153     rm -fr $OUTPUT
154     buffalo_format_result > $OUTPUT
155     buffalo_format_config $CONFIG >> $OUTPUT
156     buffalo_format_log $LOG >> $OUTPUT
157     buffalo_format_dmesg $DMESGLOG >> $OUTPUT
158     buffalo_send_report $OUTPUT
159     rm -f $OUTPUT
160     rm -f $DMESGLOG
161     rm -f $LOG
162     echo "done."
163 }
164
165 do_cleanup() {
166     $DSH $TARGET "cd $LUSTRE_SRC/tests && NAME=$CONFIG_NAME sh llmountcleanup.sh 2>&1" | dshbak -c >> $LOG
167     if ! [ $? = 0  ] ; then
168         echo "failed to clean up lustre"
169     fi   
170 }
171
172 options=`getopt -o h --long extra-params:,target:,sender:,config:,test:,help -- "$@"`
173
174 if [ $? -ne 0 ] ; then
175     usage
176 fi
177 eval set -- "$options"
178 while true
179   do
180   case "$1" in
181       --config)
182           CONFIG_NAME=$2
183           shift 2         ;;
184       --sender)
185           SENDER=$2
186           shift 2         ;;
187       --target)
188           TARGET=$2
189           shift 2         ;; 
190       --extra-params)
191           EXTRA_PARAMS=$2
192           shift 2         ;;
193       --test)
194           TESTSCRIPT=$2    
195           shift 2         ;; 
196       --help)
197           usage -h        ;;
198       -h)
199           usage -h        ;;
200       --)
201           shift
202           break           ;;
203   esac
204 done
205
206 if [ ! -d ${LUSTRE_SRC} ]; then
207     echo "LUSTRE_SRC dir $LUSTRE_SRC doesn't exist"
208     exit 1
209 fi
210
211 if [ ! -d ${LTESTDIR} ]; then
212     echo "LTESTDIR dir $LTESTDIR doesn't exist"
213     exit 2
214 fi
215
216 # Gather some buffalo variable before we run the test.
217 export KERNEL=`$DSH $TARGET uname -r | sed "s/^.*\ //g"`
218 export LUSTRE_BUILD=`${LUSTRE_SRC}/utils/lctl lustre_build_version 2>/dev/null|grep "^lctl" | awk '/^lctl/ {print $3}'`
219
220 check_mail && check_config && check_test
221
222 do_prepare
223 run_test
224 do_eval $?
225 do_cleanup
226
227 send_report
228
229 exit 0    
230
231