]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: refactor 'ceph -w' magic in test_mon_misc by introducing helper
authorMykola Golub <mgolub@mirantis.com>
Tue, 30 Dec 2014 09:59:31 +0000 (11:59 +0200)
committerMykola Golub <mgolub@mirantis.com>
Mon, 5 Jan 2015 10:01:15 +0000 (12:01 +0200)
functions ceph_watch_start and ceph_watch_wait so they can be reused
in other tests.

Signed-off-by: Mykola Golub <mgolub@mirantis.com>
qa/workunits/cephtool/test.sh

index 0aad890b8443e8cf4998385697388f21dc07cda7..7b9f756fbdc0ad59fd80f127a7ed171b2f456fc9 100755 (executable)
@@ -155,6 +155,37 @@ function expect_config_value()
   fi
 }
 
+function ceph_watch_start()
+{
+    local whatch_opt=--watch
+
+    if [ -n "$1" ]; then
+       whatch_opt=--watch-$1
+    fi
+
+    CEPH_WATCH_FILE=${TMPDIR}/CEPH_WATCH_$$
+    ceph $whatch_opt > $CEPH_WATCH_FILE &
+    CEPH_WATCH_PID=$!
+}
+
+function ceph_watch_wait()
+{
+    local regexp=$1
+    local timeout=30
+
+    if [ -n "$2" ]; then
+       timeout=$2
+    fi
+
+    for i in `seq ${timeout}`; do
+       sleep 1
+       grep -q "$regexp" $CEPH_WATCH_FILE && break
+    done
+
+    kill $CEPH_WATCH_PID
+    grep "$regexp" $CEPH_WATCH_FILE
+}
+
 function test_mon_injectargs()
 {
   CEPH_ARGS='--mon_debug_dump_location the.dump' ceph tell osd.0 injectargs --no-osd_debug_op_order >& $TMPFILE || return 1
@@ -495,20 +526,12 @@ function test_mon_misc()
   ceph health --format json-pretty
   ceph health detail --format xml-pretty
 
-  ceph -w > $TMPDIR/$$ &
-  wpid="$!"
+  ceph_watch_start
   mymsg="this is a test log message $$.$(date)"
   ceph log "$mymsg"
-  sleep 3
-  if ! grep "$mymsg" $TMPDIR/$$; then
-    # in case it is very slow (mon thrashing or something)
-    sleep 30
-    grep "$mymsg" $TMPDIR/$$
-  fi
-  kill $wpid
+  ceph_watch_wait "$mymsg"
 }
 
-
 function check_mds_active()
 {
     ceph mds dump | grep active