Whamcloud - gitweb
LU-15931 tests: Escape * in log()
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 9406876..7c25003 100755 (executable)
@@ -156,14 +156,15 @@ print_summary () {
 # output: No return values, environment variables are exported
 
 get_lustre_env() {
+       if ! $RPC_MODE; then
+               export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
+               export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
 
-       export mds1_FSTYPE=${mds1_FSTYPE:-$(facet_fstype mds1)}
-       export ost1_FSTYPE=${ost1_FSTYPE:-$(facet_fstype ost1)}
-
-       export MGS_VERSION=$(lustre_version_code mgs)
-       export MDS1_VERSION=$(lustre_version_code mds1)
-       export OST1_VERSION=$(lustre_version_code ost1)
-       export CLIENT_VERSION=$(lustre_version_code client)
+               export MGS_VERSION=$(lustre_version_code mgs)
+               export MDS1_VERSION=$(lustre_version_code mds1)
+               export OST1_VERSION=$(lustre_version_code ost1)
+               export CLIENT_VERSION=$(lustre_version_code client)
+       fi
 
        # Prefer using "mds1" directly instead of SINGLEMDS.
        # Keep this for compat until it is removed from scripts.
@@ -467,7 +468,7 @@ check_cpt_number() {
 # code is useful for comparison two version strings to see which is newer.
 version_code() {
        # split arguments like "1.8.6-wc3" into "1", "8", "6", "3"
-       eval set -- $(tr "[:punct:][a-z]" " " <<< $*)
+       eval set -- $(tr "[:punct:][a-zA-Z]" " " <<< $*)
 
        echo -n $(((${1:-0}<<24) | (${2:-0}<<16) | (${3:-0}<<8) | (${4:-0})))
 }
@@ -4099,9 +4100,8 @@ facet_failover_host() {
        fi
 
        if combined_mgs_mds && [ $facet == "mgs" ] &&
-               [ -z $mds1failover_HOST ]; then
-               temp=mds1failover_HOST
-               echo ${!temp}
+               [ -n "$mds1failover_HOST" ]; then
+               echo $mds1failover_HOST
                return
        fi
 
@@ -4242,6 +4242,36 @@ do_node() {
        return ${PIPESTATUS[0]}
 }
 
+##
+# Execute exact command line on host
+#
+# The \a host may be on a local or remote node, which is determined at
+# the time the command is run. Does careful argument quotation to
+# ensure that the exact command line is executed without any globbing,
+# substitution, or shell interpretation on the remote side. Does not
+# support --verbose or --quiet. Does not include "$host: " prefixes on
+# output. See also do_facet_vp().
+#
+# usage: do_node_vp "$host" "$command" "$arg"...
+do_node_vp() {
+       local host="$1"
+       shift
+
+       if [[ "$host" == "$HOSTNAME" ]]; then
+               sh -c "$(printf -- ' %q' "$@")"
+               return $?
+       fi
+
+       if [[ "${PDSH}" != *pdsh* || "${PDSH}" != *-S* ]]; then
+               echo "cannot run '$*' on host '${host}' with PDSH='${PDSH}'" >&2
+               return 128
+       fi
+
+       # -N Disable hostname: prefix on lines of output.
+
+       $PDSH "${host}" -N "cd $RPWD; PATH=\$PATH:$RLUSTRE/utils:$RLUSTRE/tests:/sbin:/usr/sbin; export LUSTRE=$RLUSTRE; $(printf -- ' %q' "$@")"
+}
+
 single_local_node () {
        [ "$1" = "$HOSTNAME" ]
 }
@@ -4349,6 +4379,30 @@ do_facet() {
        do_node $verbose $quiet $host "$@"
 }
 
+##
+# Execute exact command line on the host of a facet
+#
+# The \a facet (service) may be on a local or remote node, which is
+# determined at the time the command is run. Does careful argument
+# quotation to ensure that the exact command line is executed without
+# any globbing, substitution, or shell interpretation on the remote
+# side. Does not support --verbose or --quiet. Does not include
+# "$host: " prefixes on output.
+#
+# usage: do_facet_vp "$facet" "$command" "$arg"...
+do_facet_vp() {
+       local facet="$1"
+       local host=$(facet_active_host "$facet")
+       shift
+
+       if [[ -z "$host" ]]; then
+               echo "no host defined for facet ${facet}" >&2
+               exit 1
+       fi
+
+       do_node_vp "$host" "$@"
+}
+
 # Function: do_facet_random_file $FACET $FILE $SIZE
 # Creates FILE with random content on the given FACET of given SIZE
 
@@ -4664,6 +4718,7 @@ stopall() {
        # The add fn does rm ${facet}active file, this would be enough
        # if we use do_facet <facet> only after the facet added, but
        # currently we use do_facet mds in local.sh
+       local num
        for num in `seq $MDSCOUNT`; do
                stop mds$num -f
                rm -f ${TMP}/mds${num}active
@@ -6699,6 +6754,7 @@ log() {
     local MSG="$*"
     # Get rid of '
     MSG=${MSG//\'/\\\'}
+    MSG=${MSG//\*/\\\*}
     MSG=${MSG//\(/\\\(}
     MSG=${MSG//\)/\\\)}
     MSG=${MSG//\;/\\\;}
@@ -7602,7 +7658,7 @@ check_node_health() {
        # 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
+               for node in ${nodes//,/ }; do
                        check_network $node 5
                done
        fi
@@ -9018,6 +9074,9 @@ test_mkdir() {
        local dirstripe_index=${DIRSTRIPE_INDEX:-$((base % $MDSCOUNT))}
        local OPTIND=1
 
+       (( $MDS1_VERSION > $(version_code 2.15.0) )) &&
+               hash_name+=("crush2")
+
        while getopts "c:H:i:p" opt; do
                case $opt in
                        c) dirstripe_count=$OPTARG;;