From: Loic Dachary Date: Sat, 16 May 2015 09:12:16 +0000 (+0200) Subject: tests: ceph-helpers.sh implement wait_for_osd X-Git-Tag: v9.0.2~146^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de20f61529ce08d2c8e71638c7a5f7b5760ceee2;p=ceph.git tests: ceph-helpers.sh implement wait_for_osd 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 --- diff --git a/src/test/ceph-helpers.sh b/src/test/ceph-helpers.sh index bb4eecbfafed..c39a56fdc141 100755 --- a/src/test/ceph-helpers.sh +++ b/src/test/ceph-helpers.sh @@ -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.