Whamcloud - gitweb
LU-14711 tests: Ensure there's no eviction with long cache discard
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 1dea3f5..f10815b 100755 (executable)
@@ -3001,15 +3001,21 @@ stop_client_loads() {
 # If --verbose is passed as the first argument, the result is printed on each
 # value change, otherwise it is only printed after every 10s interval.
 #
+# If --quiet is passed as the first/second argument, the do_node() command
+# will not print the remote command before executing it each time.
+#
 # Using wait_update_cond() or related helper function is preferable to adding
 # a "long enough" wait for some state to change in the background, since
 # "long enough" may be too short due to tunables, system config, or running in
 # a VM, and must by necessity wait too long for most cases or risk failure.
 #
-# usage: wait_update_cond [--verbose] node check cond expect [max_wait]
+# usage: wait_update_cond [--verbose] [--quiet] node check cond expect [max_wait]
 wait_update_cond() {
-       local verbose=false
-       [[ "$1" == "--verbose" ]] && verbose=true && shift
+       local verbose
+       local quiet
+
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
 
        local node=$1
        local check="$2"
@@ -3024,7 +3030,7 @@ wait_update_cond() {
        local print=10
 
        while (( $waited <= $max_wait )); do
-               result=$(do_node $node "$check")
+               result=$(do_node $quiet $node "$check")
 
                eval [[ "'$result'" $cond "'$expect'" ]]
                if [[ $? == 0 ]]; then
@@ -3032,7 +3038,7 @@ wait_update_cond() {
                                echo "Updated after ${waited}s: want '$expect' got '$result'"
                        return 0
                fi
-               if $verbose && [[ "$result" != "$prev_result" ]]; then
+               if [[ -n "$verbose" && "$result" != "$prev_result" ]]; then
                        [[ -n "$prev_result" ]] &&
                                echo "Changed after ${waited}s: from '$prev_result' to '$result'"
                        prev_result="$result"
@@ -3046,23 +3052,29 @@ wait_update_cond() {
        return 3
 }
 
-# usage: wait_update [--verbose] node check expect [max_wait]
+# usage: wait_update [--verbose] [--quiet] node check expect [max_wait]
 wait_update() {
-       local verbose=
-       [ "$1" = "--verbose" ] && verbose="$1" && shift
+       local verbose
+       local quiet
+
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
 
        local node="$1"
        local check="$2"
        local expect="$3"
        local max_wait=$4
 
-       wait_update_cond $verbose $node "$check" "==" "$expect" $max_wait
+       wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
 }
 
 # usage: wait_update_facet_cond [--verbose] facet check cond expect [max_wait]
 wait_update_facet_cond() {
-       local verbose=
-       [ "$1" = "--verbose" ] && verbose="$1" && shift
+       local verbose
+       local quiet
+
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
 
        local node=$(facet_active_host $1)
        local check="$2"
@@ -3070,20 +3082,23 @@ wait_update_facet_cond() {
        local expect="$4"
        local max_wait=$5
 
-       wait_update_cond $verbose $node "$check" "$cond" "$expect" $max_wait
+       wait_update_cond $verbose $quiet $node "$check" "$cond" "$expect" $max_wait
 }
 
 # usage: wait_update_facet [--verbose] facet check expect [max_wait]
 wait_update_facet() {
-       local verbose=
-       [ "$1" = "--verbose" ] && verbose="$1" && shift
+       local verbose
+       local quiet
+
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
 
        local node=$(facet_active_host $1)
        local check="$2"
        local expect="$3"
        local max_wait=$4
 
-       wait_update_cond $verbose $node "$check" "==" "$expect" $max_wait
+       wait_update_cond $verbose $quiet $node "$check" "==" "$expect" $max_wait
 }
 
 sync_all_data() {
@@ -3423,7 +3438,7 @@ wait_destroy_complete () {
        # MAX value shouldn't be big as this mean server responsiveness
        # never increase this just to make test pass but investigate
        # why it takes so long time
-       local MAX=5
+       local MAX=${1:-5}
        local WAIT=0
        local list=$(comma_list $(mdts_nodes))
        while [ $WAIT -lt $MAX ]; do
@@ -4010,26 +4025,27 @@ 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
+       local quiet
 
-    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
+       # do not strip off hostname if verbose, b=19215
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
+
+       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 && [[ -z "$quiet" ]]; then
+               echo "CMD: $HOST $@" >&2
+               $myPDSH $HOST "$LCTL mark \"$@\"" > /dev/null 2>&1 || :
+       fi
 
        if [[ "$myPDSH" == "rsh" ]] ||
           [[ "$myPDSH" == *pdsh* && "$myPDSH" != *-S* ]]; then
@@ -4046,7 +4062,7 @@ do_node() {
                        return 0
        fi
 
-    if $verbose ; then
+    if [[ -n "$verbose" ]]; then
         # print HOSTNAME for myPDSH="no_dsh"
         if [[ $myPDSH = no_dsh ]]; then
             $myPDSH $HOST "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" sh -c \"$@\")" | sed -e "s/^/${HOSTNAME}: /"
@@ -4059,12 +4075,8 @@ do_node() {
     return ${PIPESTATUS[0]}
 }
 
-do_nodev() {
-    do_node --verbose "$@"
-}
-
 single_local_node () {
-   [ "$1" = "$HOSTNAME" ]
+       [ "$1" = "$HOSTNAME" ]
 }
 
 # Outputs environment variable assignments that should be passed to remote nodes
@@ -4110,45 +4122,42 @@ get_env_vars() {
 }
 
 do_nodes() {
-    local verbose=false
-    # do not stripe off hostname if verbose, bug 19215
-    if [ x$1 = x--verbose ]; then
-        shift
-        verbose=true
-    fi
+       local verbose
+       local quiet
 
-    local rnodes=$1
-    shift
+       # do not strip off hostname if verbose, b=19215
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
 
-    if single_local_node $rnodes; then
-        if $verbose; then
-           do_nodev $rnodes "$@"
-        else
-           do_node $rnodes "$@"
-        fi
-        return $?
-    fi
+       local rnodes=$1
+       shift
+
+       if single_local_node $rnodes; then
+               do_node $verbose $quiet $rnodes "$@"
+               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 \"$@\"" > /dev/null 2>&1 || :
-    fi
+       export FANOUT=$(get_node_count "${rnodes//,/ }")
+       if $VERBOSE && [[ -z "$quiet" ]]; 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.
-    if $verbose || [[ $myPDSH = *-N* ]]; then
-        $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
-    else
-        $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
-    fi
-    return ${PIPESTATUS[0]}
+       # do not replace anything from pdsh output if -N is used
+       # -N     Disable hostname: prefix on lines of output.
+       if [[ -n "$verbose" || $myPDSH = *-N* ]]; then
+               $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")"
+       else
+               $myPDSH $rnodes "(PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; cd $RPWD; LUSTRE=\"$RLUSTRE\" $(get_env_vars) sh -c \"$@\")" | sed -re "s/^[^:]*: //g"
+       fi
+       return ${PIPESTATUS[0]}
 }
 
 ##
@@ -4159,11 +4168,18 @@ do_nodes() {
 #
 # usage: do_facet $facet command [arg ...]
 do_facet() {
+       local verbose
+       local quiet
+
+       [[ "$1" == "--verbose" ]] && verbose="$1" && shift
+       [[ "$1" == "--quiet" || "$1" == "-q" ]] && quiet="$1" && shift
+
        local facet=$1
        shift
-       local HOST=$(facet_active_host $facet)
-       [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
-       do_node $HOST "$@"
+       local host=$(facet_active_host $facet)
+
+       [ -z "$host" ] && echo "No host defined for facet ${facet}" && exit 1
+       do_node $verbose $quiet $host "$@"
 }
 
 # Function: do_facet_random_file $FACET $FILE $SIZE
@@ -4186,7 +4202,7 @@ do_facet_create_file() {
 }
 
 do_nodesv() {
-    do_nodes --verbose "$@"
+       do_nodes --verbose "$@"
 }
 
 add() {
@@ -5434,6 +5450,65 @@ create_pools () {
        done
 }
 
+set_pools_quota () {
+       local u
+       local o
+       local p
+       local i
+       local j
+
+       [[ $ENABLE_QUOTA ]] || error "Required Pool Quotas: \
+               $POOLS_QUOTA_USERS_SET, but ENABLE_QUOTA not set!"
+
+       # POOLS_QUOTA_USERS_SET=
+       #              "quota15_1:20M          -- for all of the found pools
+       #               quota15_2:1G:gpool0
+       #               quota15_3              -- for global limit only
+       #               quota15_4:200M:gpool0
+       #               quota15_4:200M:gpool1"
+
+       declare -a pq_userset=(${POOLS_QUOTA_USERS_SET="mpiuser"})
+       declare -a pq_users
+       declare -A pq_limits
+
+       for ((i=0; i<${#pq_userset[@]}; i++)); do
+               u=${pq_userset[i]%%:*}
+               o=""
+               # user gets no pool limits if
+               # POOLS_QUOTA_USERS_SET does not specify it
+               [[ ${pq_userset[i]} =~ : ]] && o=${pq_userset[i]##$u:}
+               pq_limits[$u]+=" $o"
+       done
+       pq_users=(${!pq_limits[@]})
+
+       declare -a opts
+       local pool
+
+       for ((i=0; i<${#pq_users[@]}; i++)); do
+               u=${pq_users[i]}
+               # set to max limit (_u64)
+               $LFS setquota -u $u -B $((2**24 - 1))T $DIR
+               opts=(${pq_limits[$u]})
+               for ((j=0; j<${#opts[@]}; j++)); do
+                       p=${opts[j]##*:}
+                       o=${opts[j]%%:*}
+                       # Set limit for all existing pools if
+                       # no pool specified
+                       if [ $p == $o ];  then
+                               p=$(list_pool $FSNAME | sed "s/$FSNAME.//")
+                               echo "No pool specified for $u,
+                                       set limit $o for all existing pools"
+                       fi
+                       for pool in $p; do
+                               $LFS setquota -u $u -B $o --pool $pool $DIR ||
+                                        error "setquota -u $u -B $o \
+                                               --pool $pool failed"
+                       done
+               done
+               $LFS quota -uv $u --pool  $DIR
+       done
+}
+
 check_and_setup_lustre() {
        sanitize_parameters
        nfs_client_mode && return
@@ -5526,6 +5601,9 @@ check_and_setup_lustre() {
                create_pools $FS_POOL $FS_POOL_NOSTS
        fi
 
+       if [[ -n "$POOLS_QUOTA_USERS_SET" ]]; then
+               set_pools_quota
+       fi
        if [ "$ONLY" == "setup" ]; then
                exit 0
        fi
@@ -6470,10 +6548,10 @@ check_mds() {
 }
 
 reset_fail_loc () {
-       echo -n "Resetting fail_loc on all nodes..."
-       do_nodes $(comma_list $(nodes_list)) "lctl set_param -n fail_loc=0 \
-           fail_val=0 2>/dev/null" || true
-       echo done.
+       #echo -n "Resetting fail_loc on all nodes..."
+       do_nodes --quiet $(comma_list $(nodes_list)) \
+               "lctl set_param -n fail_loc=0 fail_val=0 2>/dev/null" || true
+       #echo done.
 }
 
 
@@ -6482,7 +6560,8 @@ reset_fail_loc () {
 # Also appends a timestamp and prepends the testsuite name.
 #
 
-EQUALS="===================================================================================================="
+# ======================================================== 15:06:12 (1624050372)
+EQUALS="========================================================"
 banner() {
     msg="== ${TESTSUITE} $*"
     last=${msg: -1:1}
@@ -6498,7 +6577,7 @@ check_dmesg_for_errors() {
 ldiskfs_check_descriptors: Checksum for group 0 failed\|\
 group descriptors corrupted"
 
-       res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
+       res=$(do_nodes -q $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
        [ -z "$res" ] && return 0
        echo "Kernel error detected: $res"
        return 1
@@ -7264,15 +7343,18 @@ restore_lustre_params() {
 
 check_node_health() {
        local nodes=${1:-$(comma_list $(nodes_list))}
-
-       for node in ${nodes//,/ }; do
-               check_network "$node" 5
-               if [ $? -eq 0 ]; then
-                       do_node $node "$LCTL get_param catastrophe 2>&1" |
-                               grep -q "catastrophe=1" &&
-                               error "$node:LBUG/LASSERT detected" || true
-               fi
-       done
+       local health=$TMP/node_health.$$
+
+       do_nodes -q $nodes "$LCTL get_param catastrophe 2>&1" | tee $health |
+               grep "catastrophe=1" && error "LBUG/LASSERT detected"
+       # Only check/report network health if get_param isn't reported, since
+       # *clearly* the network is working if get_param returned something.
+       if (( $(grep -c catastro $health) != $(wc -w <<< ${nodes//,/ }) )); then
+               for node in ${nodes//,/}; do
+                       check_network $node 5
+               done
+       fi
+       rm -f $health
 }
 
 mdsrate_cleanup () {