Whamcloud - gitweb
LU-6124 test: skip tests require remote server with nodsh set
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 381bacf..fdfa7b0 100755 (executable)
@@ -71,6 +71,7 @@ usage() {
 
 print_summary () {
     trap 0
+       [ -z "$DEFAULT_SUITES"] && return 0
     [ "$TESTSUITE" == "lfsck" ] && return 0
     [ -n "$ONLY" ] && echo "WARNING: ONLY is set to $(echo $ONLY)"
     local details
@@ -338,6 +339,8 @@ init_test_env() {
        if ! $RPC_MODE; then
                rm -f $TMP/*active
        fi
+
+       export TF_FAIL=${TF_FAIL:-$TMP/tf.fail}
 }
 
 check_cpt_number() {
@@ -354,18 +357,57 @@ check_cpt_number() {
        fi
 }
 
+# Return a numeric version code based on a version string.  The version
+# 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", "wc3"
-    eval set -- $(tr "[:punct:]" " " <<< $*)
+       # split arguments like "1.8.6-wc3" into "1", "8", "6", "wc3"
+       eval set -- $(tr "[:punct:]" " " <<< $*)
 
-    echo -n "$((($1 << 16) | ($2 << 8) | $3))"
+       echo -n "$((($1 << 16) | ($2 << 8) | $3))"
 }
 
 export LINUX_VERSION=$(uname -r | sed -e "s/\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/")
 export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
 
+# Report the Lustre build version string (e.g. 1.8.7.3 or 2.4.1).
+#
+# usage: lustre_build_version
+#
+# All Lustre versions support "lctl get_param" to report the version of the
+# code running in the kernel (what our tests are interested in), but it
+# doesn't work without modules loaded.  If that fails, use "lctl version"
+# instead, which is easy to parse and works without the kernel modules,
+# but was only added in 2.6.50.  If that also fails, fall back to calling
+# "lctl lustre_build_version" which prints either (or both) the userspace
+# and kernel build versions, but is deprecated and should eventually be
+# removed.
+#
+# output: prints version string to stdout in dotted-decimal format
+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
+       local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
+                   awk '/lustre: / { print $2 }')
+       # lctl 2.6.50
+       [ -z "$VER" ] && VER=$(do_facet $facet $LCTL --version 2>/dev/null |
+                              awk '{ print $2 }')
+       # Lustre version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
+       # lctl   version: 2.5.3-gfcfd782-CHANGED-2.6.32.26-175.fc12.x86_64
+       [ -z "$VER" ] && VER=$(do_facet $facet $LCTL lustre_build_version |
+                              awk '/version:/ { print $3; exit; }')
+       sed -e 's/^v//' -e 's/-.*//' -e 's/_/./g' <<<$VER
+}
+
+# Report the Lustre numeric build version code for the supplied facet.
+lustre_version_code() {
+       version_code $(lustre_build_version $1)
+}
+
 module_loaded () {
-   /sbin/lsmod | grep -q "^\<$1\>"
+       /sbin/lsmod | grep -q "^\<$1\>"
 }
 
 # Load a module on the system where this is running.
@@ -381,12 +423,12 @@ load_module() {
     EXT=".ko"
     module=$1
     shift
-    BASE=`basename $module $EXT`
+    BASE=$(basename $module $EXT)
 
     module_loaded ${BASE} && return
 
-    # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
-    # modprobe.conf
+    # If no module arguments were passed, get them from $MODOPTS_<MODULE>,
+    # else from modprobe.conf
     if [ $# -eq 0 ]; then
         # $MODOPTS_<MODULE>; we could use associative arrays, but that's not in
         # Bash until 4.x, so we resort to eval.
@@ -492,6 +534,13 @@ load_modules_local() {
     [ "$PTLDEBUG" ] && lctl set_param debug="$PTLDEBUG"
     [ "$SUBSYSTEM" ] && lctl set_param subsystem_debug="${SUBSYSTEM# }"
     load_module ../lnet/lnet/lnet
+       case $NETTYPE in
+       o2ib)
+               LNETLND="o2iblnd/ko2iblnd"
+               ;;
+       *)
+               ;;
+       esac
     LNETLND=${LNETLND:-"socklnd/ksocklnd"}
     load_module ../lnet/klnds/$LNETLND
     load_module obdclass/obdclass
@@ -2755,13 +2804,7 @@ facet_active() {
 }
 
 facet_active_host() {
-    local facet=$1
-    local active=`facet_active $facet`
-    if [ "$facet" == client ]; then
-        echo $HOSTNAME
-    else
-        echo `facet_host $active`
-    fi
+       facet_host $(facet_active $1)
 }
 
 # Get the passive failover partner host of facet.
@@ -2891,6 +2934,12 @@ get_env_vars() {
        if [ -n "$FSTYPE" ]; then
                echo -n " FSTYPE=$FSTYPE"
        fi
+
+       for var in LNETLND NETTYPE; do
+               if [ -n "${!var}" ]; then
+                       echo -n " $var=${!var}"
+               fi
+       done
 }
 
 do_nodes() {
@@ -2935,12 +2984,19 @@ do_nodes() {
     return ${PIPESTATUS[0]}
 }
 
+##
+# Execute commands on a single service's host
+#
+# The \a facet (service) may be on a local or remote node, which is
+# determined at the time the command is run.
+#
+# usage: do_facet $facet command [arg ...]
 do_facet() {
-    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 facet=$1
+       shift
+       local HOST=$(facet_active_host $facet)
+       [ -z $HOST ] && echo "No host defined for facet ${facet}" && exit 1
+       do_node $HOST "$@"
 }
 
 # Function: do_facet_random_file $FACET $FILE $SIZE
@@ -4451,7 +4507,7 @@ drop_reint_reply() {
 }
 
 drop_update_reply() {
-# OBD_FAIL_UPDATE_OBJ_NET_REP
+# OBD_FAIL_OUT_UPDATE_NET_REP
        local index=$1
        shift 1
        RC=0
@@ -4863,7 +4919,7 @@ run_test() {
 
 log() {
        echo "$*" >&2
-    module_loaded lnet || load_modules
+       load_module ../libcfs/libcfs/libcfs
 
     local MSG="$*"
     # Get rid of '
@@ -5194,6 +5250,7 @@ require_dsh_ost()
 
 remote_mgs_nodsh()
 {
+       [ "$CLIENTONLY" ] && return 0 || true
     local MGS 
     MGS=$(facet_host mgs)
     remote_node $MGS && [ "$PDSH" = "no_dsh" -o -z "$PDSH" -o -z "$ost_HOST" ]
@@ -5700,17 +5757,7 @@ convert_facet2label() {
 }
 
 get_clientosc_proc_path() {
-    echo "${1}-osc-*"
-}
-
-get_lustre_version () {
-    local facet=${1:-"$SINGLEMDS"}    
-    do_facet $facet $LCTL get_param -n version | awk '/^lustre:/ {print $2}'
-}
-
-lustre_version_code() {
-    local facet=${1:-"$SINGLEMDS"}
-    version_code $(get_lustre_version $1)
+       echo "${1}-osc-*"
 }
 
 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
@@ -5902,6 +5949,10 @@ get_clientmdc_proc_path() {
     echo "${1}-mdc-*"
 }
 
+get_clientmgc_proc_path() {
+    echo "*"
+}
+
 do_rpc_nodes () {
        local list=$1
        shift
@@ -5916,28 +5967,34 @@ do_rpc_nodes () {
 }
 
 wait_clients_import_state () {
-    local list=$1
-    local facet=$2
-    local expected=$3
+       local list=$1
+       local facet=$2
+       local expected=$3
 
-    local facets=$facet
+       local facets=$facet
 
-    if [ "$FAILURE_MODE" = HARD ]; then
-        facets=$(facets_on_host $(facet_active_host $facet))
-    fi
+       if [ "$FAILURE_MODE" = HARD ]; then
+               facets=$(facets_on_host $(facet_active_host $facet))
+       fi
 
-    for facet in ${facets//,/ }; do
-    local label=$(convert_facet2label $facet)
-    local proc_path
-    case $facet in
-        ost* ) proc_path="osc.$(get_clientosc_proc_path $label).ost_server_uuid" ;;
-        mds* ) proc_path="mdc.$(get_clientmdc_proc_path $label).mds_server_uuid" ;;
-        *) error "unknown facet!" ;;
-    esac
-    local params=$(expand_list $params $proc_path)
-    done
+       for facet in ${facets//,/ }; do
+               local label=$(convert_facet2label $facet)
+               local proc_path
+               case $facet in
+               ost* ) proc_path="osc.$(get_clientosc_proc_path \
+                                 $label).ost_server_uuid" ;;
+               mds* ) proc_path="mdc.$(get_clientmdc_proc_path \
+                                 $label).mds_server_uuid" ;;
+               mgs* ) proc_path="mgc.$(get_clientmgc_proc_path \
+                                 $label).mgs_server_uuid" ;;
+               *) error "unknown facet!" ;;
+               esac
 
-       if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params; then
+               local params=$(expand_list $params $proc_path)
+       done
+
+       if ! do_rpc_nodes "$list" wait_import_state_mount $expected $params;
+       then
                error "import is not in ${expected} state"
                return 1
        fi