Blame SOURCES/kvm-qemu-iotests-test-NBD-over-UNIX-domain-sockets-in-08.patch

9bac43
From 91394fd12be59351787e34e0f18de8b2ff06441f Mon Sep 17 00:00:00 2001
9bac43
From: Eric Blake <eblake@redhat.com>
9bac43
Date: Fri, 6 Oct 2017 19:24:08 +0200
9bac43
Subject: [PATCH 16/34] qemu-iotests: test NBD over UNIX domain sockets in 083
9bac43
9bac43
RH-Author: Eric Blake <eblake@redhat.com>
9bac43
Message-id: <20171006192409.29915-4-eblake@redhat.com>
9bac43
Patchwork-id: 76910
9bac43
O-Subject: [RHEV-7.5 qemu-kvm-rhev PATCH 3/4] qemu-iotests: test NBD over UNIX domain sockets in 083
9bac43
Bugzilla: 1482478
9bac43
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
9bac43
From: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
9bac43
083 only tests TCP.  Some failures might be specific to UNIX domain
9bac43
sockets.
9bac43
9bac43
A few adjustments are necessary:
9bac43
9bac43
1. Generating a port number and waiting for server startup is
9bac43
   TCP-specific.  Use the new nbd-fault-injector.py startup protocol to
9bac43
   fetch the address.  This is a little more elegant because we don't
9bac43
   need netstat anymore.
9bac43
9bac43
2. The NBD filter does not work for the UNIX domain sockets URIs we
9bac43
   generate and must be extended.
9bac43
9bac43
3. Run all tests twice: once for TCP and once for UNIX domain sockets.
9bac43
9bac43
Reviewed-by: Eric Blake <eblake@redhat.com>
9bac43
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Message-Id: <20170829122745.14309-4-stefanha@redhat.com>
9bac43
Signed-off-by: Eric Blake <eblake@redhat.com>
9bac43
(cherry picked from commit 02d2d860d25e439f0e88658c701668ab684568fb)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 tests/qemu-iotests/083           | 136 ++++++++++++++++++++++--------------
9bac43
 tests/qemu-iotests/083.out       | 145 ++++++++++++++++++++++++++++++++++-----
9bac43
 tests/qemu-iotests/common.filter |   4 +-
9bac43
 3 files changed, 214 insertions(+), 71 deletions(-)
9bac43
9bac43
diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083
9bac43
index bff9360..0306f11 100755
9bac43
--- a/tests/qemu-iotests/083
9bac43
+++ b/tests/qemu-iotests/083
9bac43
@@ -27,6 +27,14 @@ echo "QA output created by $seq"
9bac43
 here=`pwd`
9bac43
 status=1	# failure is the default!
9bac43
 
9bac43
+_cleanup()
9bac43
+{
9bac43
+	rm -f nbd.sock
9bac43
+	rm -f nbd-fault-injector.out
9bac43
+	rm -f nbd-fault-injector.conf
9bac43
+}
9bac43
+trap "_cleanup; exit \$status" 0 1 2 3 15
9bac43
+
9bac43
 # get standard environment, filters and checks
9bac43
 . ./common.rc
9bac43
 . ./common.filter
9bac43
@@ -35,81 +43,105 @@ _supported_fmt generic
9bac43
 _supported_proto nbd
9bac43
 _supported_os Linux
9bac43
 
9bac43
-# Pick a TCP port based on our pid.  This way multiple instances of this test
9bac43
-# can run in parallel without conflicting.
9bac43
-choose_tcp_port() {
9bac43
-	echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
9bac43
-}
9bac43
-
9bac43
-wait_for_tcp_port() {
9bac43
-	while ! (netstat --tcp --listening --numeric | \
9bac43
-		 grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
9bac43
-		sleep 0.1
9bac43
+check_disconnect() {
9bac43
+	local event export_name=foo extra_args nbd_addr nbd_url proto when
9bac43
+
9bac43
+	while true; do
9bac43
+		case $1 in
9bac43
+		--classic-negotiation)
9bac43
+			shift
9bac43
+			extra_args=--classic-negotiation
9bac43
+			export_name=
9bac43
+			;;
9bac43
+		--tcp)
9bac43
+			shift
9bac43
+			proto=tcp
9bac43
+			;;
9bac43
+		--unix)
9bac43
+			shift
9bac43
+			proto=unix
9bac43
+			;;
9bac43
+		*)
9bac43
+			break
9bac43
+			;;
9bac43
+		esac
9bac43
 	done
9bac43
-}
9bac43
 
9bac43
-check_disconnect() {
9bac43
 	event=$1
9bac43
 	when=$2
9bac43
-	negotiation=$3
9bac43
 	echo "=== Check disconnect $when $event ==="
9bac43
 	echo
9bac43
 
9bac43
-	port=$(choose_tcp_port)
9bac43
-
9bac43
 	cat > "$TEST_DIR/nbd-fault-injector.conf" <
9bac43
 [inject-error]
9bac43
 event=$event
9bac43
 when=$when
9bac43
 EOF
9bac43
 
9bac43
-	if [ "$negotiation" = "--classic-negotiation" ]; then
9bac43
-		extra_args=--classic-negotiation
9bac43
-		nbd_url="nbd:127.0.0.1:$port"
9bac43
+	if [ "$proto" = "tcp" ]; then
9bac43
+		nbd_addr="127.0.0.1:0"
9bac43
 	else
9bac43
-		nbd_url="nbd:127.0.0.1:$port:exportname=foo"
9bac43
+		nbd_addr="$TEST_DIR/nbd.sock"
9bac43
+	fi
9bac43
+
9bac43
+	rm -f "$TEST_DIR/nbd.sock"
9bac43
+
9bac43
+	$PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
9bac43
+
9bac43
+	# Wait for server to be ready
9bac43
+	while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do
9bac43
+		sleep 0.1
9bac43
+	done
9bac43
+
9bac43
+	# Extract the final address (port number has now been assigned in tcp case)
9bac43
+	nbd_addr=$(sed 's/Listening on \(.*\)$/\1/' "$TEST_DIR/nbd-fault-injector.out")
9bac43
+
9bac43
+	if [ "$proto" = "tcp" ]; then
9bac43
+		nbd_url="nbd+tcp://$nbd_addr/$export_name"
9bac43
+	else
9bac43
+		nbd_url="nbd+unix:///$export_name?socket=$nbd_addr"
9bac43
 	fi
9bac43
 
9bac43
-	$PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" >/dev/null 2>&1 &
9bac43
-	wait_for_tcp_port "127\\.0\\.0\\.1:$port"
9bac43
 	$QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
9bac43
 
9bac43
 	echo
9bac43
 }
9bac43
 
9bac43
-for event in neg1 "export" neg2 request reply data; do
9bac43
-	for when in before after; do
9bac43
-		check_disconnect "$event" "$when"
9bac43
-	done
9bac43
-
9bac43
-	# Also inject short replies from the NBD server
9bac43
-	case "$event" in
9bac43
-	neg1)
9bac43
-		for when in 8 16; do
9bac43
-			check_disconnect "$event" "$when"
9bac43
-		done
9bac43
-		;;
9bac43
-	"export")
9bac43
-		for when in 4 12 16; do
9bac43
-			check_disconnect "$event" "$when"
9bac43
+for proto in tcp unix; do
9bac43
+	for event in neg1 "export" neg2 request reply data; do
9bac43
+		for when in before after; do
9bac43
+			check_disconnect "--$proto" "$event" "$when"
9bac43
 		done
9bac43
-		;;
9bac43
-	neg2)
9bac43
-		for when in 8 10; do
9bac43
-			check_disconnect "$event" "$when"
9bac43
-		done
9bac43
-		;;
9bac43
-	reply)
9bac43
-		for when in 4 8; do
9bac43
-			check_disconnect "$event" "$when"
9bac43
-		done
9bac43
-		;;
9bac43
-	esac
9bac43
-done
9bac43
 
9bac43
-# Also check classic negotiation without export information
9bac43
-for when in before 8 16 24 28 after; do
9bac43
-	check_disconnect "neg-classic" "$when" --classic-negotiation
9bac43
+		# Also inject short replies from the NBD server
9bac43
+		case "$event" in
9bac43
+		neg1)
9bac43
+			for when in 8 16; do
9bac43
+				check_disconnect "--$proto" "$event" "$when"
9bac43
+			done
9bac43
+			;;
9bac43
+		"export")
9bac43
+			for when in 4 12 16; do
9bac43
+				check_disconnect "--$proto" "$event" "$when"
9bac43
+			done
9bac43
+			;;
9bac43
+		neg2)
9bac43
+			for when in 8 10; do
9bac43
+				check_disconnect "--$proto" "$event" "$when"
9bac43
+			done
9bac43
+			;;
9bac43
+		reply)
9bac43
+			for when in 4 8; do
9bac43
+				check_disconnect "--$proto" "$event" "$when"
9bac43
+			done
9bac43
+			;;
9bac43
+		esac
9bac43
+	done
9bac43
+
9bac43
+	# Also check classic negotiation without export information
9bac43
+	for when in before 8 16 24 28 after; do
9bac43
+		check_disconnect "--$proto" --classic-negotiation "neg-classic" "$when"
9bac43
+	done
9bac43
 done
9bac43
 
9bac43
 # success, all done
9bac43
diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out
9bac43
index a24c6bf..a7fb081 100644
9bac43
--- a/tests/qemu-iotests/083.out
9bac43
+++ b/tests/qemu-iotests/083.out
9bac43
@@ -1,43 +1,43 @@
9bac43
 QA output created by 083
9bac43
 === Check disconnect before neg1 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect after neg1 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 8 neg1 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 16 neg1 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect before export ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect after export ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 4 export ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 12 export ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 16 export ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect before neg2 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect after neg2 ===
9bac43
 
9bac43
@@ -45,11 +45,11 @@ read failed: Input/output error
9bac43
 
9bac43
 === Check disconnect 8 neg2 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect 10 neg2 ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT:exportname=foo
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/foo
9bac43
 
9bac43
 === Check disconnect before request ===
9bac43
 
9bac43
@@ -88,23 +88,134 @@ read 512/512 bytes at offset 0
9bac43
 
9bac43
 === Check disconnect before neg-classic ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/
9bac43
 
9bac43
 === Check disconnect 8 neg-classic ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/
9bac43
 
9bac43
 === Check disconnect 16 neg-classic ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/
9bac43
 
9bac43
 === Check disconnect 24 neg-classic ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/
9bac43
 
9bac43
 === Check disconnect 28 neg-classic ===
9bac43
 
9bac43
-can't open device nbd:127.0.0.1:PORT
9bac43
+can't open device nbd+tcp://127.0.0.1:PORT/
9bac43
+
9bac43
+=== Check disconnect after neg-classic ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect before neg1 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect after neg1 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 8 neg1 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 16 neg1 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect before export ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect after export ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 4 export ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 12 export ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 16 export ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect before neg2 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect after neg2 ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect 8 neg2 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 10 neg2 ===
9bac43
+
9bac43
+can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect before request ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect after request ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect before reply ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect after reply ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect 4 reply ===
9bac43
+
9bac43
+read failed
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect 8 reply ===
9bac43
+
9bac43
+read failed
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect before data ===
9bac43
+
9bac43
+read failed: Input/output error
9bac43
+
9bac43
+=== Check disconnect after data ===
9bac43
+
9bac43
+read 512/512 bytes at offset 0
9bac43
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9bac43
+
9bac43
+=== Check disconnect before neg-classic ===
9bac43
+
9bac43
+can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 8 neg-classic ===
9bac43
+
9bac43
+can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 16 neg-classic ===
9bac43
+
9bac43
+can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 24 neg-classic ===
9bac43
+
9bac43
+can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
9bac43
+
9bac43
+=== Check disconnect 28 neg-classic ===
9bac43
+
9bac43
+can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
9bac43
 
9bac43
 === Check disconnect after neg-classic ===
9bac43
 
9bac43
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
9bac43
index 7a58e57..9d5442e 100644
9bac43
--- a/tests/qemu-iotests/common.filter
9bac43
+++ b/tests/qemu-iotests/common.filter
9bac43
@@ -170,9 +170,9 @@ _filter_nbd()
9bac43
     #
9bac43
     # Filter out the TCP port number since this changes between runs.
9bac43
     sed -e '/nbd\/.*\.c:/d' \
9bac43
-        -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \
9bac43
+        -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \
9bac43
         -e "s#?socket=$TEST_DIR#?socket=TEST_DIR#g" \
9bac43
-        -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#'
9bac43
+        -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#'
9bac43
 }
9bac43
 
9bac43
 # make sure this script returns success
9bac43
-- 
9bac43
1.8.3.1
9bac43