Whamcloud - gitweb
LU-8055 ldev: File system label filtering
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index b143748..7efae3a 100755 (executable)
@@ -142,6 +142,7 @@ init_test_env() {
        export TEST_FAILED=false
        export FAIL_ON_SKIP_ENV=${FAIL_ON_SKIP_ENV:-false}
        export RPC_MODE=${RPC_MODE:-false}
+       export DO_CLEANUP=${DO_CLEANUP:-true}
 
     export MKE2FS=$MKE2FS
     if [ -z "$MKE2FS" ]; then
@@ -293,6 +294,8 @@ init_test_env() {
     export DIR2
     export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
     export AT_MAX_PATH
+    export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
+    [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
 
     if [ "$ACCEPTOR_PORT" ]; then
         export PORT_OPT="--port $ACCEPTOR_PORT"
@@ -401,9 +404,7 @@ export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
 lustre_build_version() {
        local facet=${1:-client}
 
-       # lustre: 2.6.52
-       # kernel: patchless_client
-       # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
+       # lustre: 2.8.52
        local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
                    awk '/lustre: / { print $2 }')
        # lctl 2.6.50
@@ -2426,16 +2427,17 @@ client_evicted() {
 }
 
 client_reconnect_try() {
-    uname -n >> $MOUNT/recon
-    if [ -z "$CLIENTS" ]; then
-        df $MOUNT; uname -n >> $MOUNT/recon
-    else
-        do_nodes $CLIENTS "df $MOUNT; uname -n >> $MOUNT/recon" > /dev/null
-    fi
-    echo Connected clients:
-    cat $MOUNT/recon
-    ls -l $MOUNT/recon > /dev/null
-    rm $MOUNT/recon
+       local f=$MOUNT/recon
+
+       uname -n >> $f
+       if [ -z "$CLIENTS" ]; then
+               $LFS df $MOUNT; uname -n >> $f
+       else
+               do_nodes $CLIENTS "$LFS df $MOUNT; uname -n >> $f" > /dev/null
+       fi
+       echo "Connected clients: $(cat $f)"
+       ls -l $f > /dev/null
+       rm $f
 }
 
 client_reconnect() {
@@ -2530,7 +2532,7 @@ obd_name() {
 replay_barrier() {
        local facet=$1
        do_facet $facet "sync; sync; sync"
-       df $MOUNT
+       $LFS df $MOUNT
 
        # make sure there will be no seq change
        local clients=${CLIENTS:-$HOSTNAME}
@@ -2556,8 +2558,8 @@ replay_barrier() {
        # inside fail() and fail_abort().
        #
        do_facet $facet $LCTL --device ${!svc} readonly
-       do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
-       $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 replay_barrier_nodf() {
@@ -2567,8 +2569,8 @@ replay_barrier_nodf() {
        echo Replay barrier on ${!svc}
        do_facet $facet $LCTL --device ${!svc} notransno
        do_facet $facet $LCTL --device ${!svc} readonly
-       do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
-       $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 replay_barrier_nosync() {
@@ -2577,8 +2579,8 @@ replay_barrier_nosync() {
        echo Replay barrier on ${!svc}
        do_facet $facet $LCTL --device ${!svc} notransno
        do_facet $facet $LCTL --device ${!svc} readonly
-       do_facet $facet $LCTL mark "$HOSTNAME: $facet REPLAY BARRIER on ${!svc}"
-       $LCTL mark "$HOSTNAME: local REPLAY BARRIER on ${!svc}"
+       do_facet $facet $LCTL mark "$facet REPLAY BARRIER on ${!svc}"
+       $LCTL mark "local REPLAY BARRIER on ${!svc}"
 }
 
 #
@@ -2615,7 +2617,7 @@ fail() {
 
        facet_failover $* || error "failover: $?"
        wait_clients_import_state "$clients" "$facets" FULL
-       clients_up || error "post-failover df: $?"
+       clients_up || error "post-failover stat: $?"
 }
 
 fail_nodf() {
@@ -2629,8 +2631,8 @@ fail_abort() {
        change_active $facet
        wait_for_facet $facet
        mount_facet $facet -o abort_recovery
-       clients_up || echo "first df failed: $?"
-       clients_up || error "post-failover df: $?"
+       clients_up || echo "first stat failed: $?"
+       clients_up || error "post-failover stat: $?"
 }
 
 do_lmc() {
@@ -2893,26 +2895,26 @@ change_active() {
 }
 
 do_node() {
-       local verbose=false
-       # do not stripe off hostname if verbose, bug 19215
-       if [ x$1 = x--verbose ]; then
-               shift
-               verbose=true
-       fi
+    local verbose=false
+    # do not stripe off hostname if verbose, bug 19215
+    if [ x$1 = x--verbose ]; then
+        shift
+        verbose=true
+    fi
 
-       local HOST=$1
-       shift
-       local myPDSH=$PDSH
-       if [ "$HOST" = "$HOSTNAME" ]; then
-               myPDSH="no_dsh"
-       elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
-               echo "cannot run remote command on $HOST with $myPDSH"
-               return 128
-       fi
-       if $VERBOSE; then
-               echo "CMD: $HOST $@" >&2
-               $myPDSH $HOST "$LCTL mark \"$HOSTNAME: $@\"" &>/dev/null || :
-       fi
+    local HOST=$1
+    shift
+    local myPDSH=$PDSH
+    if [ "$HOST" = "$HOSTNAME" ]; then
+        myPDSH="no_dsh"
+    elif [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" ]; then
+        echo "cannot run remote command on $HOST with $myPDSH"
+        return 128
+    fi
+    if $VERBOSE; then
+        echo "CMD: $HOST $@" >&2
+        $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
+    fi
 
     if [ "$myPDSH" = "rsh" ]; then
 # we need this because rsh does not return exit code of an executed command
@@ -3008,18 +3010,17 @@ do_nodes() {
         return $?
     fi
 
-       # This is part from do_node
-       local myPDSH=$PDSH
+    # This is part from do_node
+    local myPDSH=$PDSH
 
-       [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] &&
-               echo "cannot run remote command on $rnodes with $myPDSH" &&
-               return 128
+    [ -z "$myPDSH" -o "$myPDSH" = "no_dsh" -o "$myPDSH" = "rsh" ] && \
+        echo "cannot run remote command on $rnodes with $myPDSH" && return 128
 
-       export FANOUT=$(get_node_count "${rnodes//,/ }")
-       if $VERBOSE; then
-               echo "CMD: $rnodes $@" >&2
-               $myPDSH $rnodes "$LCTL mark \"$HOSTNAME: $@\"" &>/dev/null || :
-       fi
+    export FANOUT=$(get_node_count "${rnodes//,/ }")
+    if $VERBOSE; then
+        echo "CMD: $rnodes $@" >&2
+        $myPDSH $rnodes "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
+    fi
 
     # do not replace anything from pdsh output if -N is used
     # -N     Disable hostname: prefix on lines of output.
@@ -3849,7 +3850,7 @@ set_conf_param_and_check() {
        do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" ||
                error "conf_param $PARAM failed"
 
-       wait_update $(facet_host $myfacet) "$TEST" "$FINAL" ||
+       wait_update_facet $myfacet "$TEST" "$FINAL" ||
                error "check $PARAM failed!"
 }
 
@@ -4309,8 +4310,12 @@ check_and_cleanup_lustre() {
        fi
 
        if is_mounted $MOUNT; then
-               [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
-                       error "remove sub-test dirs failed"
+               if $DO_CLEANUP; then
+                       [ -n "$DIR" ] && rm -rf $DIR/[Rdfs][0-9]* ||
+                               error "remove sub-test dirs failed"
+               else
+                       echo "skip cleanup"
+               fi
                [ "$ENABLE_QUOTA" ] && restore_quota || true
        fi
 
@@ -4633,14 +4638,15 @@ clear_failloc() {
 }
 
 set_nodes_failloc () {
-       do_nodes $(comma_list $1)  lctl set_param fail_val=0 fail_loc=$2
+       local fv=${3:-0}
+       do_nodes $(comma_list $1)  lctl set_param fail_val=$fv fail_loc=$2
 }
 
 cancel_lru_locks() {
-       #$LCTL mark "$HOSTNAME: cancel_lru_locks $1 start"
+       #$LCTL mark "cancel_lru_locks $1 start"
        $LCTL set_param -n ldlm.namespaces.*$1*.lru_size=clear
        $LCTL get_param ldlm.namespaces.*$1*.lock_unused_count | grep -v '=0'
-       #$LCTL mark "$HOSTNAME: cancel_lru_locks $1 stop"
+       #$LCTL mark "cancel_lru_locks $1 stop"
 }
 
 default_lru_size()
@@ -4938,18 +4944,17 @@ log() {
        echo "$*" >&2
        load_module ../libcfs/libcfs/libcfs
 
-       local MSG="$HOSTNAME: $*"
-       # Get rid of '
-       MSG=${MSG//\'/\\\'}
-       MSG=${MSG//\(/\\\(}
-       MSG=${MSG//\)/\\\)}
-       MSG=${MSG//\;/\\\;}
-       MSG=${MSG//\|/\\\|}
-       MSG=${MSG//\>/\\\>}
-       MSG=${MSG//\</\\\<}
-       MSG=${MSG//\//\\\/}
-       do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null ||
-               true
+    local MSG="$*"
+    # Get rid of '
+    MSG=${MSG//\'/\\\'}
+    MSG=${MSG//\(/\\\(}
+    MSG=${MSG//\)/\\\)}
+    MSG=${MSG//\;/\\\;}
+    MSG=${MSG//\|/\\\|}
+    MSG=${MSG//\>/\\\>}
+    MSG=${MSG//\</\\\<}
+    MSG=${MSG//\//\\\/}
+    do_nodes $(comma_list $(nodes_list)) $LCTL mark "$MSG" 2> /dev/null || true
 }
 
 trace() {
@@ -6666,29 +6671,36 @@ check_write_access() {
 }
 
 init_logging() {
-    if [[ -n $YAML_LOG ]]; then
-        return
-    fi
-    local SAVE_UMASK=`umask`
-    umask 0000
-
-    export YAML_LOG=${LOGDIR}/results.yml
-    mkdir -p $LOGDIR
-    init_clients_lists
-
-    if [ ! -f $YAML_LOG ]; then       # If the yaml log already exists then we will just append to it
-      if check_shared_dir $LOGDIR; then
-          touch $LOGDIR/shared
-          echo "Logging to shared log directory: $LOGDIR"
-      else
-          echo "Logging to local directory: $LOGDIR"
-      fi
+       [[ -n $YAML_LOG ]] && return
+       local save_umask=$(umask)
+       umask 0000
 
-      yml_nodes_file $LOGDIR >> $YAML_LOG
-      yml_results_file >> $YAML_LOG
-    fi
+       export YAML_LOG=${LOGDIR}/results.yml
+       mkdir -p $LOGDIR
+       init_clients_lists
+
+       # If the yaml log already exists then we will just append to it
+       if [ ! -f $YAML_LOG ]; then
+               if check_shared_dir $LOGDIR; then
+                       touch $LOGDIR/shared
+                       echo "Logging to shared log directory: $LOGDIR"
+               else
+                       echo "Logging to local directory: $LOGDIR"
+               fi
+
+               yml_nodes_file $LOGDIR >> $YAML_LOG
+               yml_results_file >> $YAML_LOG
+       fi
+
+       umask $save_umask
 
-    umask $SAVE_UMASK
+       # If modules are not yet loaded then older "lctl lustre_build_version"
+       # will fail.  Use lctl build version instead.
+       log "Client: $($LCTL lustre_build_version)"
+       log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
+                   do_facet $SINGLEMDS $LCTL --version)"
+       log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
+                   do_facet ost1 $LCTL --version)"
 }
 
 log_test() {