]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: count OSD ids in PGs {wait,get}_osd_id_used_by_pgs
authorLoic Dachary <ldachary@redhat.com>
Thu, 8 Jun 2017 16:57:20 +0000 (18:57 +0200)
committerLoic Dachary <ldachary@redhat.com>
Fri, 14 Jul 2017 17:47:00 +0000 (19:47 +0200)
Signed-off-by: Loic Dachary <loic@dachary.org>
qa/workunits/ceph-helpers.sh

index f293d7f043eaf7da688968a13689d6be58ce31a1..28165abe2590e3f9b9e55bfbbb78111dcf75b75d 100755 (executable)
@@ -1137,6 +1137,76 @@ function test_get_num_pgs() {
 
 #######################################################################
 
+##
+# Return the OSD ids in use by at least one PG in the cluster (either
+# in the up or the acting set), according to ceph pg dump pgs. Every
+# OSD id shows as many times as they are used in up and acting sets.
+# If an OSD id is in both the up and acting set of a given PG, it will
+# show twice.
+#
+# @param STDOUT a sorted list of OSD ids
+# @return 0 on success, 1 on error
+#
+function get_osd_id_used_by_pgs() {
+    ceph --format json pg dump pgs 2>/dev/null | jq '.[] | .up[], .acting[]' | sort
+}
+
+function test_get_osd_id_used_by_pgs() {
+    local dir=$1
+
+    setup $dir || return 1
+    run_mon $dir a --osd_pool_default_size=1 || return 1
+    run_mgr $dir x || return 1
+    run_osd $dir 0 || return 1
+    wait_for_clean || return 1
+    local osd_ids=$(get_osd_id_used_by_pgs | uniq)
+    test "$osd_ids" = "0" || return 1
+    teardown $dir || return 1
+}
+
+#######################################################################
+
+##
+# Wait until the OSD **id** shows **count** times in the
+# PGs (see get_osd_id_used_by_pgs for more information about
+# how OSD ids are counted).
+#
+# @param id the OSD id
+# @param count the number of time it must show in the PGs
+# @return 0 on success, 1 on error
+#
+function wait_osd_id_used_by_pgs() {
+    local id=$1
+    local count=$2
+
+    status=1
+    for ((i=0; i < $TIMEOUT / 5; i++)); do
+        echo $i
+        if ! test $(get_osd_id_used_by_pgs | grep -c $id) = $count ; then
+            sleep 5
+        else
+            status=0
+            break
+        fi
+    done
+    return $status
+}
+
+function test_wait_osd_id_used_by_pgs() {
+    local dir=$1
+
+    setup $dir || return 1
+    run_mon $dir a --osd_pool_default_size=1 || return 1
+    run_mgr $dir x || return 1
+    run_osd $dir 0 || return 1
+    wait_for_clean || return 1
+    wait_osd_id_used_by_pgs 0 8 || return 1
+    ! TIMEOUT=1 wait_osd_id_used_by_pgs 123 5 || return 1
+    teardown $dir || return 1
+}
+
+#######################################################################
+
 ##
 # Return the date and time of the last completed scrub for **pgid**,
 # as reported by ceph pg dump pgs. Note that a repair also sets this