summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Brassow <jbrassow@redhat.com>2012-07-24 14:17:54 -0500
committerJonathan Brassow <jbrassow@redhat.com>2012-07-24 14:17:54 -0500
commit753cb9204d24ceb4d9f8184ceb4c0262b9aacb42 (patch)
treeaabe9e88061923044db84ba6c5845daa0111a739
parent5e36b86c46f04eddae2d4b1f826e1f24995b3636 (diff)
downloadlvm2-753cb9204d24ceb4d9f8184ceb4c0262b9aacb42.tar.gz
lvm2-753cb9204d24ceb4d9f8184ceb4c0262b9aacb42.tar.xz
lvm2-753cb9204d24ceb4d9f8184ceb4c0262b9aacb42.zip
TEST: Add library functions for checking and waiting for sync
Add 'in_sync' and 'wait_for_sync' to test and wait for synchronization of a mirror or RAID logical volume.
-rw-r--r--test/lib/aux.sh12
-rw-r--r--test/lib/check.sh45
2 files changed, 57 insertions, 0 deletions
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 91f54c9a..4128f301 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -479,6 +479,18 @@ udev_wait() {
fi
}
+# wait_for_sync <VG/LV>
+wait_for_sync() {
+ local i
+ for i in {1..500} ; do
+ check in_sync $1 $2 && return
+ sleep .2
+ done
+
+ echo "Sync is taking too long - assume stuck"
+ return 1
+}
+
#
# Check wheter kernel [dm module] target exist
# at least in expected version
diff --git a/test/lib/check.sh b/test/lib/check.sh
index 9c787285..95bba4bf 100644
--- a/test/lib/check.sh
+++ b/test/lib/check.sh
@@ -151,6 +151,51 @@ linear() {
$(lvl $lv -o+devices)
}
+# in_sync <VG> <LV>
+# Works for "mirror" and "raid*"
+in_sync() {
+ local a
+ local b
+ local idx
+ local type
+ local lvm_name="$1/$2"
+ local dm_name=$(echo $lvm_name | sed s:-:--: | sed s:/:-:)
+
+ if ! a=(`dmsetup status $dm_name`); then
+ die "Unable to get sync status of $1"
+ elif [ ${a[2]} = "snapshot-origin" ]; then
+ if ! a=(`dmsetup status ${dm_name}-real`); then
+ die "Unable to get sync status of $1"
+ fi
+ fi
+
+ if [ ${a[2]} = "raid" ]; then
+ # Last argument is the sync ratio for RAID
+ idx=$((${#a[@]} - 1))
+ type=${a[3]}
+ elif [ ${a[2]} = "mirror" ]; then
+ # 4th Arg tells us how far to the sync ratio
+ idx=$((${a[3]} + 4))
+ type=${a[2]}
+ else
+ die "Unable to get sync ratio for target type '${a[2]}'"
+ fi
+
+ b=( $(echo ${a[$idx]} | sed s:/:' ':) )
+
+ if [ ${b[0]} != ${b[1]} ]; then
+ echo "$lvm_name ($type) is not in-sync"
+ return 1
+ fi
+
+ if [[ ${a[$(($idx - 1))]} =~ a ]]; then
+ die "$lvm_name in-sync, but 'a' characters in health status"
+ fi
+
+ echo "$lvm_name ($type) is in-sync"
+ return 0
+}
+
active() {
local lv=$1/$2
(get lv_field $lv attr | grep "^....a...$" >/dev/null) || \