Skip to contentSkip to conversation

master - tests: add device holding function

PATCH Zdenek Kabelac 1 participant 1 message Dec 22, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e1943fc07f81e1c824757ccdac45c1e43a57af28
Commit:        e1943fc07f81e1c824757ccdac45c1e43a57af28
Parent:        1053d46aff11a8e592ca91ba56d6400f4693b9a5
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Thu Dec 22 22:21:09 2016 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Thu Dec 22 23:37:07 2016 +0100

tests: add device holding function

Hold device open with sleep and wait till sleep really opens given devices.

---
 test/lib/aux.sh |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
test/lib/aux.sh +21 -0
index a195883..174e05e 100644
@@ -1491,6 +1491,27 @@ wait_pvmove_lv_ready() {
 	fi
 }
 
+# Holds device open with sleep which automatically expires after given timeout
+# Prints  PID of running holding sleep process in background
+hold_device_open() {
+	local vgname=$1
+	local lvname=$2
+	local sec=${3:-20} # default 20sec
+
+	sleep $sec < "$DM_DEV_DIR/$vgname/$lvname" >/dev/null 2>&1 &
+	SLEEP_PID=$!
+	# wait till device is openned
+	for i in $(seq 1 50) ; do
+		if test "$(dmsetup info --noheadings -c -o open $vgname-$lvname)" -ne 0 ; then
+			echo "$SLEEP_PID"
+			return
+		fi
+		sleep .1
+	done
+
+	die "$vgname-$lvname expected to be openned, but it's not!"
+}
+
 # return total memory size in kB units
 total_mem() {
 	while IFS=":" read -r a b ; do