Whamcloud - gitweb
b=5498
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 5769f4b..481022c 100644 (file)
@@ -10,6 +10,9 @@ export REFORMAT=${REFORMAT:-""}
 export VERBOSE=false
 export GMNALNID=${GMNALNID:-/usr/sbin/gmlndnid}
 export CATASTROPHE=${CATASTROPHE:-/proc/sys/lnet/catastrophe}
+export GSS=false
+export GSS_KRB5=false
+export GSS_PIPEFS=false
 #export PDSH="pdsh -S -Rssh -w"
 
 # eg, assert_env LUSTRE MDSNODES OSTNODES CLIENTS
@@ -38,21 +41,26 @@ init_test_env() {
 
     [ -d /r ] && export ROOT=${ROOT:-/r}
     export TMP=${TMP:-$ROOT/tmp}
+    export TESTSUITELOG=${TMP}/${TESTSUITE}.log
 
     export PATH=:$PATH:$LUSTRE/utils:$LUSTRE/utils/gss:$LUSTRE/tests
     export LCTL=${LCTL:-"$LUSTRE/utils/lctl"}
+    export LFS=${LFS:-"$LUSTRE/utils/lfs"}
     [ ! -f "$LCTL" ] && export LCTL=$(which lctl) 
+    export LFS=${LFS:-"$LUSTRE/utils/lfs"}
+    [ ! -f "$LFS" ] && export LFS=$(which lfs) 
     export MKFS=${MKFS:-"$LUSTRE/utils/mkfs.lustre"}
     [ ! -f "$MKFS" ] && export MKFS=$(which mkfs.lustre) 
     export TUNEFS=${TUNEFS:-"$LUSTRE/utils/tunefs.lustre"}
     [ ! -f "$TUNEFS" ] && export TUNEFS=$(which tunefs.lustre) 
-    export CHECKSTAT="${CHECKSTAT:-checkstat} "
+    export CHECKSTAT="${CHECKSTAT:-"checkstat -v"} "
     export FSYTPE=${FSTYPE:-"ldiskfs"}
     export NAME=${NAME:-local}
     export LPROC=/proc/fs/lustre
     export LGSSD=${LGSSD:-"$LUSTRE/utils/gss/lgssd"}
     export LSVCGSSD=${LSVCGSSD:-"$LUSTRE/utils/gss/lsvcgssd"}
     export KRB5DIR=${KRB5DIR:-"/usr/kerberos"}
+    export DIR2
 
     if [ "$ACCEPTOR_PORT" ]; then
         export PORT_OPT="--port $ACCEPTOR_PORT"
@@ -61,13 +69,15 @@ init_test_env() {
     case "x$SEC" in
         xkrb5*)
             echo "Using GSS/krb5 ptlrpc security flavor"
-            export USING_KRB5="y"
+            GSS=true
+            GSS_KRB5=true
             ;;
     esac
 
     # Paths on remote nodes, if different 
     export RLUSTRE=${RLUSTRE:-$LUSTRE}
     export RPWD=${RPWD:-$PWD}
+    export I_MOUNTED=${I_MOUNTED:-"no"}
 
     # command line
     
@@ -82,6 +92,9 @@ init_test_env() {
 
     shift $((OPTIND - 1))
     ONLY=${ONLY:-$*}
+
+    [ "$TESTSUITELOG" ] && rm -f $TESTSUITELOG || true
+
 }
 
 load_module() {
@@ -96,7 +109,7 @@ load_module() {
         # must be testing a "make install" or "rpm" installation
         # note failed to load ptlrpc_gss is considered not fatal
         if [ "$BASE" == "ptlrpc_gss" ]; then
-            modprobe $BASE $@ || echo "gss/krb5 is not supported"
+            modprobe $BASE $@ 2>/dev/null || echo "gss/krb5 is not supported"
         else
             modprobe $BASE $@
         fi
@@ -147,6 +160,7 @@ load_modules() {
     load_module ost/ost
     load_module obdfilter/obdfilter
     load_module llite/lustre
+    load_module llite/llite_lloop
     load_module mgc/mgc
     load_module mgs/mgs
     rm -f $TMP/ogdb-`hostname`
@@ -241,7 +255,9 @@ start_gss_daemons() {
     # starting on MDT
     for num in `seq $MDSCOUNT`; do
         do_facet mds$num "$LSVCGSSD -v"
-        do_facet mds$num "$LGSSD -v"
+        if $GSS_PIPEFS; then
+            do_facet mds$num "$LGSSD -v"
+        fi
     done
     # starting on OSTs
     for num in `seq $OSTCOUNT`; do
@@ -249,7 +265,9 @@ start_gss_daemons() {
     done
     # starting on client
     # FIXME: is "client" the right facet name?
-    do_facet client "$LGSSD -v"
+    if $GSS_PIPEFS; then
+        do_facet client "$LGSSD -v"
+    fi
 
     # wait daemons entering "stable" status
     sleep 5
@@ -259,12 +277,16 @@ start_gss_daemons() {
     #
     for num in `seq $MDSCOUNT`; do
         check_gss_daemon_facet mds$num lsvcgssd
-        check_gss_daemon_facet mds$num lgssd
+        if $GSS_PIPEFS; then
+            check_gss_daemon_facet mds$num lgssd
+        fi
     done
     for num in `seq $OSTCOUNT`; do
         check_gss_daemon_facet ost$num lsvcgssd
     done
-    check_gss_daemon_facet client lgssd
+    if $GSS_PIPEFS; then
+        check_gss_daemon_facet client lgssd
+    fi
 }
 
 stop_gss_daemons() {
@@ -283,13 +305,13 @@ init_krb5_env() {
         OST_MOUNT_OPTS=$OST_MOUNT_OPTS,sec=$SEC
     fi
 
-    if [ ! -z $USING_KRB5 ]; then
+    if $GSS; then
         start_gss_daemons
     fi
 }
 
 cleanup_krb5_env() {
-    if [ ! -z $USING_KRB5 ]; then
+    if $GSS; then
         stop_gss_daemons
         # maybe cleanup credential cache?
     fi
@@ -466,6 +488,24 @@ wait_for() {
     wait_for_host $HOST
 }
 
+wait_mds_recovery_done () {
+    local timeout=`do_facet mds cat /proc/sys/lustre/timeout`
+#define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 / 2)
+# as we are in process of changing obd_timeout in different ways
+# let's set MAX longer than that
+    MAX=$(( timeout * 4 ))
+    WAIT=0
+    while [ $WAIT -lt $MAX ]; do
+        STATUS=`do_facet mds grep status /proc/fs/lustre/mdt/*-MDT*/recovery_status`
+        echo $STATUS | grep COMPLETE && return 0
+        sleep 5
+        WAIT=$((WAIT + 5))
+        echo "Waiting $(($MAX - $WAIT)) secs for MDS recovery done"
+    done
+    echo "MDS recovery not done in $MAX sec"
+    return 1            
+}
+
 client_df() {
     # not every config has many clients
     if [ ! -z "$CLIENTS" ]; then
@@ -804,6 +844,44 @@ setupall() {
     sleep 5
 }
 
+mounted_lustre_filesystems() {
+       awk '($3 ~ "lustre" && $1 ~ ":") { print $2 }' /proc/mounts
+}
+
+check_and_setup_lustre() {
+    MOUNTED="`mounted_lustre_filesystems`"
+    if [ -z "$MOUNTED" ]; then
+        [ "$REFORMAT" ] && formatall
+        setupall
+        MOUNTED="`mounted_lustre_filesystems`"
+        [ -z "$MOUNTED" ] && error "NAME=$NAME not mounted"
+        export I_MOUNTED=yes
+    fi
+    if [ "$ONLY" == "setup" ]; then
+        exit 0
+    fi
+}
+
+cleanup_and_setup_lustre() {
+    if [ "$ONLY" == "cleanup" -o "`mount | grep $MOUNT`" ]; then
+        sysctl -w lnet.debug=0 || true
+        cleanupall
+        if [ "$ONLY" == "cleanup" ]; then 
+           exit 0
+        fi
+    fi
+    check_and_setup_lustre
+}
+
+check_and_cleanup_lustre() {
+    if [ "`mount | grep $MOUNT`" ]; then
+        rm -rf $DIR/[Rdfs][1-9]*
+    fi
+    if [ "$I_MOUNTED" = "yes" ]; then
+        cleanupall -f || error "cleanup failed"
+    fi
+    unset I_MOUNTED
+}
 
 ####### 
 # General functions
@@ -944,15 +1022,38 @@ pgcache_empty() {
     return 0
 }
 
+debugsave() {
+    DEBUGSAVE="$(sysctl -n lnet.debug)"
+}
+
+debugrestore() {
+    [ -n "$DEBUGSAVE" ] && sysctl -w lnet.debug="${DEBUGSAVE}"
+    DEBUGSAVE=""
+}
+
+FAIL_ON_ERROR=true
 ##################################
 # Test interface 
 error() {
+    local ERRLOG
     sysctl -w lustre.fail_loc=0 2> /dev/null || true
-    log "${TESTSUITE}: **** FAIL:" $@
-    $LCTL dk $TMP/lustre-log-$TESTNAME.log
-    log "FAIL: $TESTNAME $@"
-    $LCTL dk $TMP/lustrefail_${TESTSUITE}_${TESTNAME}.$(date +%s)
-    exit 1
+    log "${TESTSUITE} ${TESTNAME}: **** FAIL:" $@
+    ERRLOG=$TMP/lustre_${TESTSUITE}_${TESTNAME}.$(date +%s)
+    echo "Dumping lctl log to $ERRLOG"
+    # We need to dump the logs on all nodes
+    $LCTL dk $ERRLOG
+    [ ! "$mds_HOST" = "$(hostname)" ] && do_node $mds_HOST $LCTL dk $ERRLOG
+    [ ! "$ost_HOST" = "$(hostname)" -a ! "$ost_HOST" = "$mds_HOST" ] && do_node $ost_HOST $LCTL dk $ERRLOG
+    debugrestore
+    [ "$TESTSUITELOG" ] && echo "$0: FAIL: $TESTNAME $@" >> $TESTSUITELOG
+    if $FAIL_ON_ERROR; then
+       exit 1
+    fi
+}
+
+skip () {
+       log " SKIP: ${TESTSUITE} ${TESTNAME} $@"
+       [ "$TESTSUITELOG" ] && echo "${TESTSUITE}: SKIP: $TESTNAME $@" >> $TESTSUITELOG
 }
 
 build_test_filter() {
@@ -965,6 +1066,9 @@ build_test_filter() {
     for E in $EXCEPT $ALWAYS_EXCEPT; do
         eval EXCEPT_${E}=true
     done
+    for G in $GRANT_CHECK_LIST; do
+        eval GCHECK_ONLY_${G}=true
+       done
 }
 
 _basetest() {
@@ -993,12 +1097,12 @@ run_test() {
     fi
     testname=EXCEPT_$1
     if [ ${!testname}x != x ]; then
-        log "skipping excluded test $1"
+        TESTNAME=test_$1 skip "skipping excluded test $1"
         return 0
     fi
     testname=EXCEPT_$base
     if [ ${!testname}x != x ]; then
-        log "skipping excluded test $1 (base $base)"
+        TESTNAME=test_$1 skip "skipping excluded test $1 (base $base)"
         return 0
     fi
     run_one $1 "$2"
@@ -1021,6 +1125,14 @@ log() {
     $LCTL mark "$*" 2> /dev/null || true
 }
 
+trace() {
+       log "STARTING: $*"
+       strace -o $TMP/$1.strace -ttt $*
+       RC=$?
+       log "FINISHED: $*: rc $RC"
+       return 1
+}
+
 pass() {
     echo PASS $@
 }
@@ -1035,10 +1147,7 @@ run_one() {
     testnum=$1
     message=$2
     tfile=f${testnum}
-    tdir=d${base}
-
-    # Pretty tests run faster.
-    equals_msg $testnum: $message
+    export tdir=d${base}
 
     BEFORE=`date +%s`
     log "== test $testnum: $message ============ `date +%H:%M:%S` ($BEFORE)"
@@ -1046,16 +1155,69 @@ run_one() {
     export TESTNAME=test_$testnum
     test_${testnum} || error "test_$testnum failed with $?"
     #check_mds
+    check_grant ${testnum} || error "check_grant $testnum failed with $?"
     [ -f $CATASTROPHE ] && [ `cat $CATASTROPHE` -ne 0 ] && \
         error "LBUG/LASSERT detected"
     pass "($((`date +%s` - $BEFORE))s)"
     unset TESTNAME
+    unset tdir
+    cd $SAVE_PWD
+    $CLEANUP
 }
 
 canonical_path() {
     (cd `dirname $1`; echo $PWD/`basename $1`)
 }
 
+sync_clients() {
+    [ -d $DIR1 ] && cd $DIR1 && sync; sleep 1; sync 
+    [ -d $DIR2 ] && cd $DIR2 && sync; sleep 1; sync 
+       cd $SAVE_PWD
+}
+
+check_grant() {
+    export base=`basetest $1`
+    [ "$CHECK_GRANT" == "no" ] && return 0
+
+       testname=GCHECK_ONLY_${base}
+        [ ${!testname}x == x ] && return 0
+
+       echo -n "checking grant......"
+       cd $SAVE_PWD
+       # write some data to sync client lost_grant
+       rm -f $DIR1/${tfile}_check_grant_* 2>&1
+       for i in `seq $OSTCOUNT`; do
+               $LFS setstripe $DIR1/${tfile}_check_grant_$i 0 $(($i -1)) 1
+               dd if=/dev/zero of=$DIR1/${tfile}_check_grant_$i bs=4k \
+                                             count=1 > /dev/null 2>&1 
+       done
+       # sync all the data and make sure no pending data on server
+       sync_clients
+       
+       #get client grant and server grant 
+       client_grant=0
+    for d in ${LPROC}/osc/*/cur_grant_bytes; do 
+               client_grant=$((client_grant + `cat $d`))
+       done
+       server_grant=0
+       for d in ${LPROC}/obdfilter/*/tot_granted; do
+               server_grant=$((server_grant + `cat $d`))
+       done
+
+       # cleanup the check_grant file
+       for i in `seq $OSTCOUNT`; do
+               rm $DIR1/${tfile}_check_grant_$i
+       done
+
+       #check whether client grant == server grant 
+       if [ $client_grant != $server_grant ]; then
+               echo "failed: client:${client_grant} server: ${server_grant}"
+               return 1
+       else
+               echo "pass"
+       fi
+}
+
 ########################
 # helper functions
 
@@ -1068,3 +1230,18 @@ osc_to_ost()
     fi
     echo $ost
 }
+
+remote_mds ()
+{
+    [ ! -e /proc/fs/lustre/mdt/*MDT* ]
+}
+
+remote_ost ()
+{
+    [ $(grep -c obdfilter $LPROC/devices) -eq 0 ]
+}
+
+is_patchless ()
+{
+    grep -q patchless $LPROC/version
+}