Whamcloud - gitweb
b=22455 fix the problem in get_param with option "-N"
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index be08a46..900f93f 100644 (file)
@@ -1,11 +1,11 @@
 #!/bin/bash
 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
 
-trap 'print_summary && echo "test-framework exiting on error"' ERR
+trap 'print_summary && touch $TF_FAIL && \
+    echo "test-framework exiting on error"' ERR
 set -e
 #set -x
 
-
 export REFORMAT=${REFORMAT:-""}
 export WRITECONF=${WRITECONF:-""}
 export VERBOSE=false
@@ -248,6 +248,8 @@ load_module() {
     shift
     BASE=`basename $module $EXT`
 
+    module_loaded ${BASE} && return
+
     # If no module arguments were passed, get them from $MODOPTS_<MODULE>, else from
     # modprobe.conf
     if [ $# -eq 0 ]; then
@@ -262,7 +264,7 @@ load_module() {
            (($# > 0)) && shift 2
 
             # Ensure we have accept=all for lnet
-            if [ $module = lnet ]; then
+            if [ $(basename $module) = lnet ]; then
                 # OK, this is a bit wordy...
                 local arg accept_all_present=false
                 for arg in "$@"; do
@@ -275,8 +277,6 @@ load_module() {
 
     [ $# -gt 0 ] && echo "${module} options: '$*'"
 
-    module_loaded ${BASE} && return
-
     # Note that insmod will ignore anything in modprobe.conf, which is why we're
     # passing options on the command-line.
     if [ "$BASE" == "lnet_selftest" ] && \
@@ -301,12 +301,6 @@ load_modules_local() {
         echo "Using modprobe to load modules"
         return 0
     fi
-    if [ "$HAVE_MODULES" = true ]; then
-        # we already loaded
-        echo "Modules already loaded"
-        return 0
-    fi
-    HAVE_MODULES=true
 
     echo Loading modules from $LUSTRE
     load_module ../libcfs/libcfs/libcfs
@@ -392,8 +386,6 @@ unload_modules() {
         fi
     fi
 
-    HAVE_MODULES=false
-
     check_mem_leak || return 254
 
     echo "modules unloaded."
@@ -886,6 +878,13 @@ shutdown_facet() {
     fi
 }
 
+remount_facet() {
+    local facet=$1
+
+    stop $facet
+    mount_facet $facet
+}
+
 reboot_facet() {
     facet=$1
     if [ "$FAILURE_MODE" = HARD ]; then
@@ -1137,10 +1136,7 @@ wait_recovery_complete () {
     local facet=$1
 
     # Use default policy if $2 is not passed by caller.
-    #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
-    local MAX=${2:-$(( TIMEOUT * 4 ))}
+    local MAX=${2:-$(max_recovery_time)}
 
     local var_svc=${facet}_svc
     local procfile="*.${!var_svc}.recovery_status"
@@ -1754,7 +1750,7 @@ switch_identity() {
         do_facet mds$num "lctl set_param -n mdt.$MDT.identity_upcall \"NONE\""
     fi
 
-    do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush \"-1\""
+    do_facet mds$num "lctl set_param -n mdt/$MDT/identity_flush=-1"
 
     if [ $old = "NONE" ]; then
         return 1
@@ -2046,6 +2042,7 @@ check_timeout () {
 
 is_mounted () {
     local mntpt=$1
+    [ -z $mntpt ] && return 1
     local mounted=$(mounted_lustre_filesystems)
 
     echo $mounted' ' | grep -w -q $mntpt' '
@@ -2716,6 +2713,7 @@ run_one_logged() {
     rm -rf $LOGDIR/err
 
     echo
+    log_sub_test_begin test_${1}
     (run_one $1 "$2") 2>&1 | tee $test_log
     local RC=${PIPESTATUS[0]}
 
@@ -2725,7 +2723,7 @@ run_one_logged() {
     duration=$((`date +%s` - $BEFORE))
     pass "(${duration}s)"
     [ -f $LOGDIR/err ] && TEST_ERROR=$(cat $LOGDIR/err)
-    log_sub_test test_${1} $TEST_STATUS $duration "$RC" "$TEST_ERROR"
+    log_sub_test_end $TEST_STATUS $duration "$RC" "$TEST_ERROR"
 
     if [ -f $LOGDIR/err ]; then
         $FAIL_ON_ERROR && exit $RC
@@ -3303,13 +3301,12 @@ get_osc_import_name() {
 }
 
 wait_import_state () {
-    local facet=$1
-    local expected=$2
-    local CONN_PROC=$3
+    local expected=$1
+    local CONN_PROC=$2
     local CONN_STATE
     local i=0
 
-    CONN_STATE=$(do_facet $facet $LCTL get_param -n $CONN_PROC | awk '/state/ {print $2}')
+    CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
     while [ "${CONN_STATE}" != "${expected}" ]; do
         if [ "${expected}" == "DISCONN" ]; then
             # for disconn we can check after proc entry is removed
@@ -3322,7 +3319,7 @@ wait_import_state () {
         [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
             error "can't put import for $CONN_PROC into ${expected} state" && return 1
         sleep 1
-        CONN_STATE=$(do_facet $facet $LCTL get_param -n $CONN_PROC | awk '/state/ {print $2}')
+        CONN_STATE=$($LCTL get_param -n $CONN_PROC 2>/dev/null | cut -f2)
         i=$(($i + 1))
     done
 
@@ -3335,26 +3332,33 @@ wait_osc_import_state() {
     local ost_facet=$2
     local expected=$3
     local ost=$(get_osc_import_name $facet $ost_facet)
-    local CONN_PROC="osc.${ost}.import"
+    local CONN_PROC
+    local CONN_STATE
+    local i=0
+
+    CONN_PROC="osc.${ost}.ost_server_uuid"
+    CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
+    while [ "${CONN_STATE}" != "${expected}" ]; do
+        if [ "${expected}" == "DISCONN" ]; then 
+            # for disconn we can check after proc entry is removed
+            [ "x${CONN_STATE}" == "x" ] && return 0
+            #  with AT we can have connect request timeout ~ reconnect timeout
+            # and test can't see real disconnect
+            [ "${CONN_STATE}" == "CONNECTING" ] && return 0
+        fi
+        # disconnect rpc should be wait not more obd_timeout
+        [ $i -ge $(($TIMEOUT * 3 / 2)) ] && \
+            error "can't put import for ${ost}(${ost_facet}) into ${expected} state" && return 1
+        sleep 1
+        CONN_STATE=$(do_facet $facet lctl get_param -n $CONN_PROC 2>/dev/null | cut -f2)
+        i=$(($i + 1))
+    done
 
-    wait_import_state $facet $expected $CONN_PROC || return 1
+    log "${ost_facet} now in ${CONN_STATE} state"
     return 0
 }
-
 get_clientmdc_proc_path() {
-    local mdc=$(convert_facet2label $1)
-
-    echo "${mdc}-mdc-*"
-}
-
-wait_mdc_import_state() {
-    local facet=$1
-    local expected=$2
-    local mdc=$(get_clientmdc_proc_path $facet)
-    local CONN_PROC="mdc.${mdc}.import"
-
-    wait_import_state client $expected $CONN_PROC || return 1
-    return 0
+    echo "${1}-mdc-*"
 }
 
 do_rpc_nodes () {
@@ -3366,29 +3370,24 @@ do_rpc_nodes () {
     do_nodesv $list "PATH=$RPATH sh rpc.sh $@ "
 }
 
-wait_client_import_state () {
-    local facet=$1
-    local expected=$2
+wait_clients_import_state () {
+    local list=$1
+    local facet=$2
+    local expected=$3
     shift
 
+    local label=$(convert_facet2label $facet)
+    local proc_path
     case $facet in
-        ost* ) wait_osc_import_state client $facet $expected || return 1;;
-        mds* ) wait_mdc_import_state $facet $expected || return 1 ;;
-           * ) error "unknown facet!"
-               return 1 ;;
+        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
-    return 0
-}
-
-wait_clients_import_state () {
-    local list=$1
-    shift
 
-    if ! do_rpc_nodes $list wait_client_import_state "$@"; then
-        error "import is not in expected state"
+    if ! do_rpc_nodes $list wait_import_state $expected $proc_path; then
+        error "import is not in ${expected} state"
         return 1
     fi
-    return 0
 }
 
 oos_full() {
@@ -3571,6 +3570,24 @@ do_ls () {
     return $rc
 }
 
+# target_start_and_reset_recovery_timer()
+#        service_time = at_est2timeout(service_time);
+#        service_time += 2 * (CONNECTION_SWITCH_MAX + CONNECTION_SWITCH_INC +
+#                             INITIAL_CONNECT_TIMEOUT);
+# CONNECTION_SWITCH_MAX : min(25U, max(CONNECTION_SWITCH_MIN,obd_timeout))
+#define CONNECTION_SWITCH_INC 1
+#define INITIAL_CONNECT_TIMEOUT max(CONNECTION_SWITCH_MIN,obd_timeout/20)
+#define CONNECTION_SWITCH_MIN 5U
+
+max_recovery_time () {
+    local init_connect_timeout=$(( TIMEOUT / 20 ))
+    [[ $init_connect_timeout > 5 ]] || init_connect_timeout=5 
+
+    local service_time=$(( $(at_max_get client) + $(( 2 * $(( 25 + 1  + init_connect_timeout)) )) ))
+
+    echo $service_time 
+}
+
 get_clients_mount_count () {
     local clients=${CLIENTS:-`hostname`}
 
@@ -3912,8 +3929,16 @@ log_test() {
     yml_log_test $1 >> $YAML_LOG
 }
 
-log_sub_test() {
-    yml_log_sub_test $@ >> $YAML_LOG
+log_test_status() {
+     yml_log_test_status $@ >> $YAML_LOG
+}
+
+log_sub_test_begin() {
+    yml_log_sub_test_begin $@ >> $YAML_LOG
+}
+
+log_sub_test_end() {
+    yml_log_sub_test_end $@ >> $YAML_LOG
 }
 
 run_llverdev()
@@ -3921,6 +3946,9 @@ run_llverdev()
         local dev=$1
         local devname=$(basename $1)
         local size=$(grep "$devname"$ /proc/partitions | awk '{print $3}')
+       # loop devices aren't in /proc/partitions
+       [ "x$size" == "x" ] && local size=$(ls -l $dev | awk '{print $5}')
+
         size=$(($size / 1024 / 1024)) # Gb
 
         local partial_arg=""