]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: ceph-helpers.sh implement wait_for_osd
authorLoic Dachary <ldachary@redhat.com>
Sat, 16 May 2015 09:12:16 +0000 (11:12 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sun, 17 May 2015 10:10:47 +0000 (12:10 +0200)
The wait_for_osd to wait for an osd to go up and down is needed
internally, after running an osd. Move the inline snippet from run_osd
into a function so that it can be used by scripts as well.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/test/ceph-helpers.sh

index bb4eecbfafeda49c803039331582e3bf5ef5fd16..c39a56fdc141c0d2144be0ba3ac1adbc591c6594 100755 (executable)
@@ -222,7 +222,6 @@ function test_kill_daemons() {
     setup $dir || return 1
     run_mon $dir a --osd_pool_default_size=1 || return 1
     run_osd $dir 0 || return 1
-    ceph osd dump | grep "osd.0 up" || return 1
     # sending signal 0 won't kill the daemon
     # waiting just for one second instead of the default schedule
     # allows us to quickly verify what happens when kill fails 
@@ -499,17 +498,7 @@ function activate_osd() {
 
     ceph osd crush create-or-move "$id" 1 root=default host=localhost
 
-    status=1
-    for ((i=0; i < $TIMEOUT; i++)); do
-        if ! ceph osd dump | grep "osd.$id up"; then
-            sleep 1
-        else
-            status=0
-            break
-        fi
-    done
-
-    return $status
+    wait_for_osd up $id || return 1
 }
 
 function test_activate_osd() {
@@ -536,6 +525,44 @@ function test_activate_osd() {
 
 #######################################################################
 
+##
+# Wait until the OSD **id** is either up or down, as specified by
+# **state**. It fails after $TIMEOUT seconds.
+#
+# @param state either up or down
+# @param id osd identifier
+# @return 0 on success, 1 on error
+#
+function wait_for_osd() {
+    local state=$1
+    local id=$2
+
+    status=1
+    for ((i=0; i < $TIMEOUT; i++)); do
+        if ! ceph osd dump | grep "osd.$id $state"; then
+            sleep 1
+        else
+            status=0
+            break
+        fi
+    done
+    return $status
+}
+
+function test_wait_for_osd() {
+    local dir=$1
+    setup $dir || return 1
+    run_mon $dir a --osd_pool_default_size=1 || return 1
+    run_osd $dir 0 || return 1
+    wait_for_osd up 0 || return 1
+    kill_daemons $dir TERM osd || return 1
+    wait_for_osd down 0 || return 1
+    ( TIMEOUT=1 ; ! wait_for_osd up 0 ) || return 1
+    teardown $dir || return 1
+}
+
+#######################################################################
+
 ##
 # Display the list of OSD ids supporting the **objectname** stored in
 # **poolname**, as reported by ceph osd map.