]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/workunits/ceph-helpers: add wait_for_quorum()
authorJoao Eduardo Luis <joao@suse.de>
Tue, 21 Feb 2017 01:27:54 +0000 (01:27 +0000)
committerJoao Eduardo Luis <joao@suse.de>
Thu, 2 Mar 2017 17:32:34 +0000 (17:32 +0000)
Takes optional timeout and desired quorum size

Signed-off-by: Joao Eduardo Luis <joao@suse.de>
qa/workunits/ceph-helpers.sh

index 049baf74a34d59da6b92793d33415490e77490c8..efaff9cbfbd1963d1abd28d5049b5301c4ee0d68 100755 (executable)
@@ -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.