Whamcloud - gitweb
LU-10670 test: make sanity-flr test_43 more reliable
[fs/lustre-release.git] / lustre / tests / lustre-rsync-test.sh
index b091763..a67447e 100644 (file)
@@ -38,6 +38,13 @@ check_and_setup_lustre
 DIR=${DIR:-$MOUNT}
 assert_DIR
 
+if getent group nobody; then
+       GROUP=nobody
+elif getent group nogroup; then
+       GROUP=nogroup
+else
+       error "No generic nobody group"
+fi
 
 build_test_filter
 
@@ -121,6 +128,38 @@ check_diff() {
        fi
 }
 
+procs_are_stopped() {
+       local pids="$*"
+       local state
+
+       for state in $(ps -p "$pids" -o state=); do
+               if [[ "$state" != T ]]; then
+                       return 1
+               fi
+       done
+
+       return 0
+}
+
+# Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
+# stopped process state.
+stop_procs() {
+       local pids="$*"
+       local end
+
+       $KILL -SIGSTOP $pids
+       end=$((SECONDS + 60))
+       while ((SECONDS < end)); do
+               if procs_are_stopped $pids; then
+                       return 0
+               fi
+
+               sleep 1
+       done
+
+       return 1
+}
+
 # Test 1 - test basic operations
 test_1() {
     init_src
@@ -164,7 +203,7 @@ test_1() {
 
     # Set attributes
     chmod 000 $DIR/$tdir/d2/file3
-    chown nobody:nobody $DIR/$tdir/d2/file3
+    chown nobody:$GROUP $DIR/$tdir/d2/file3
 
     # Set xattrs
     if [[ "$xattr" != "no" ]]; then
@@ -211,6 +250,7 @@ run_test 1 "Simple Replication"
 test_1a() { # LU-5005
        rm -rf $TGT/root-* 2> /dev/null
        rm -rf $DIR/root-* 2> /dev/null
+       init_src
        init_changelog
 
        # Directory create
@@ -243,6 +283,7 @@ test_1a() { # LU-5005
        stat $TGT/root-dir1 && error "Dir delete not replicated"
        stat $TGT/root-file4 && error "File delete not replicated"
 
+       cleanup_src_tgt
        fini_changelog
        rm -fr $TGT/root-*
        rm -fr $DIR/root-*
@@ -289,7 +330,7 @@ test_2b() {
 
        echo PIDs: $child_pid
        echo Stopping dbench
-       $KILL -SIGSTOP $child_pid
+       stop_procs $child_pid
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        echo Starting replication
@@ -302,7 +343,7 @@ test_2b() {
     sleep 10
 
     echo Stopping dbench
-    $KILL -SIGSTOP $child_pid
+       stop_procs $child_pid
 
        echo Starting replication
        $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
@@ -442,7 +483,7 @@ test_4() {
         MOUNT=${DIR}/$tdir run_iozone.sh &
     sleep 30
     child_pid=$(pgrep iozone)
-    $KILL -SIGSTOP $child_pid
+       stop_procs $child_pid
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -534,17 +575,18 @@ run_test 5b "Kill / restart lustre_rsync"
 
 # Test 6 - lustre_rsync large no of hard links
 test_6() {
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    local NUMLINKS=128
-    touch $DIR/$tdir/link0
-    local i=1
-    while [ $i -lt $NUMLINKS ];
-    do
-      ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
-      i=$(expr $i + 1)
-    done
+       local num_links=128
+       local i
+
+       touch $DIR/$tdir/link0
+       for ((i = 1; i < num_links - 1; i++)); do
+               ln $DIR/$tdir/link0 $DIR/$tdir/link$i
+       done
+       # create an extra hard link of src name ending with dest name
+       ln $DIR/$tdir/link0 $DIR/$tdir/ink0
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -553,15 +595,16 @@ test_6() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
-    local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
-    if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
-       ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
-       error "Incorrect no of hard links found $count1, $count2"
-    fi
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       local count1=$(stat --format=%h $TGT/$tdir/link0)
+       local count2=$(stat --format=%h $TGT2/$tdir/link0)
+       if ((count1 != num_links || count2 != num_links)); then
+               ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
+               error "Incorrect no of hard links found $count1, $count2"
+       fi
+
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 6 "lustre_rsync large no of hard links"