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

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