From: Joao Eduardo Luis Date: Tue, 21 Feb 2017 01:27:54 +0000 (+0000) Subject: qa/workunits/ceph-helpers: add wait_for_quorum() X-Git-Tag: v12.0.1~170^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3cabcb7d5176fa9f85344e611f992be092550a03;p=ceph-ci.git qa/workunits/ceph-helpers: add wait_for_quorum() Takes optional timeout and desired quorum size Signed-off-by: Joao Eduardo Luis --- diff --git a/qa/workunits/ceph-helpers.sh b/qa/workunits/ceph-helpers.sh index 049baf74a34..efaff9cbfbd 100755 --- a/qa/workunits/ceph-helpers.sh +++ b/qa/workunits/ceph-helpers.sh @@ -710,6 +710,42 @@ function test_get_osds() { ####################################################################### +## +# Wait for the monitor to form quorum (optionally, of size N) +# +# @param timeout duration (lower-bound) to wait for quorum to be formed +# @param quorumsize size of quorum to wait for +# @return 0 on success, 1 on error +# +function wait_for_quorum() { + local timeout=$1 + local quorumsize=$2 + + if [[ -z "$timeout" ]]; then + timeout=300 + fi + + if [[ -z "$quorumsize" ]]; then + timeout $timeout ceph mon_status --format=json >&/dev/null || return 1 + return 0 + fi + + no_quorum=1 + wait_until=$((`date +%s` + $timeout)) + while [[ $(date +%s) -lt $wait_until ]]; do + jqfilter='.quorum | length == '$quorumsize + jqinput="$(timeout $timeout ceph mon_status --format=json 2>/dev/null)" + res=$(echo $jqinput | jq "$jqfilter") + if [[ "$res" == "true" ]]; then + no_quorum=0 + break + fi + done + return $no_quorum +} + +####################################################################### + ## # Return the PG of supporting the **objectname** stored in # **poolname**, as reported by ceph osd map.