1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Eric Blake <eblake@redhat.com>
3 Date: Wed, 27 Sep 2017 17:57:24 +0200
4 Subject: [PATCH] qemu-iotests: test NBD over UNIX domain sockets in 083
6 RH-Author: Eric Blake <eblake@redhat.com>
7 Message-id: <20170927175725.20023-7-eblake@redhat.com>
9 O-Subject: [RHEV-7.4.z qemu-kvm-rhev PATCH 6/7] qemu-iotests: test NBD over UNIX domain sockets in 083
11 RH-Acked-by: Max Reitz <mreitz@redhat.com>
12 RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
13 RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
15 From: Stefan Hajnoczi <stefanha@redhat.com>
17 083 only tests TCP. Some failures might be specific to UNIX domain
20 A few adjustments are necessary:
22 1. Generating a port number and waiting for server startup is
23 TCP-specific. Use the new nbd-fault-injector.py startup protocol to
24 fetch the address. This is a little more elegant because we don't
27 2. The NBD filter does not work for the UNIX domain sockets URIs we
28 generate and must be extended.
30 3. Run all tests twice: once for TCP and once for UNIX domain sockets.
32 Reviewed-by: Eric Blake <eblake@redhat.com>
33 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34 Message-Id: <20170829122745.14309-4-stefanha@redhat.com>
35 Signed-off-by: Eric Blake <eblake@redhat.com>
36 (cherry picked from commit 02d2d860d25e439f0e88658c701668ab684568fb)
37 Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
40 tests/qemu-iotests/083.out - error message improvements not backported
42 Signed-off-by: Eric Blake <eblake@redhat.com>
44 tests/qemu-iotests/083 | 136 +++++++++++++++++++++++--------------
45 tests/qemu-iotests/083.out | 143 ++++++++++++++++++++++++++++++++++-----
46 tests/qemu-iotests/common.filter | 4 +-
47 3 files changed, 212 insertions(+), 71 deletions(-)
49 diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083
50 index bff9360..0306f11 100755
51 --- a/tests/qemu-iotests/083
52 +++ b/tests/qemu-iotests/083
53 @@ -27,6 +27,14 @@ echo "QA output created by $seq"
55 status=1 # failure is the default!
60 + rm -f nbd-fault-injector.out
61 + rm -f nbd-fault-injector.conf
63 +trap "_cleanup; exit \$status" 0 1 2 3 15
65 # get standard environment, filters and checks
68 @@ -35,81 +43,105 @@ _supported_fmt generic
72 -# Pick a TCP port based on our pid. This way multiple instances of this test
73 -# can run in parallel without conflicting.
75 - echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
78 -wait_for_tcp_port() {
79 - while ! (netstat --tcp --listening --numeric | \
80 - grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
83 + local event export_name=foo extra_args nbd_addr nbd_url proto when
87 + --classic-negotiation)
89 + extra_args=--classic-negotiation
107 -check_disconnect() {
111 echo "=== Check disconnect $when $event ==="
114 - port=$(choose_tcp_port)
116 cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
122 - if [ "$negotiation" = "--classic-negotiation" ]; then
123 - extra_args=--classic-negotiation
124 - nbd_url="nbd:127.0.0.1:$port"
125 + if [ "$proto" = "tcp" ]; then
126 + nbd_addr="127.0.0.1:0"
128 - nbd_url="nbd:127.0.0.1:$port:exportname=foo"
129 + nbd_addr="$TEST_DIR/nbd.sock"
132 + rm -f "$TEST_DIR/nbd.sock"
134 + $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
136 + # Wait for server to be ready
137 + while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do
141 + # Extract the final address (port number has now been assigned in tcp case)
142 + nbd_addr=$(sed 's/Listening on \(.*\)$/\1/' "$TEST_DIR/nbd-fault-injector.out")
144 + if [ "$proto" = "tcp" ]; then
145 + nbd_url="nbd+tcp://$nbd_addr/$export_name"
147 + nbd_url="nbd+unix:///$export_name?socket=$nbd_addr"
150 - $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nbd-fault-injector.conf" >/dev/null 2>&1 &
151 - wait_for_tcp_port "127\\.0\\.0\\.1:$port"
152 $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd
157 -for event in neg1 "export" neg2 request reply data; do
158 - for when in before after; do
159 - check_disconnect "$event" "$when"
162 - # Also inject short replies from the NBD server
165 - for when in 8 16; do
166 - check_disconnect "$event" "$when"
170 - for when in 4 12 16; do
171 - check_disconnect "$event" "$when"
172 +for proto in tcp unix; do
173 + for event in neg1 "export" neg2 request reply data; do
174 + for when in before after; do
175 + check_disconnect "--$proto" "$event" "$when"
179 - for when in 8 10; do
180 - check_disconnect "$event" "$when"
184 - for when in 4 8; do
185 - check_disconnect "$event" "$when"
191 -# Also check classic negotiation without export information
192 -for when in before 8 16 24 28 after; do
193 - check_disconnect "neg-classic" "$when" --classic-negotiation
194 + # Also inject short replies from the NBD server
197 + for when in 8 16; do
198 + check_disconnect "--$proto" "$event" "$when"
202 + for when in 4 12 16; do
203 + check_disconnect "--$proto" "$event" "$when"
207 + for when in 8 10; do
208 + check_disconnect "--$proto" "$event" "$when"
212 + for when in 4 8; do
213 + check_disconnect "--$proto" "$event" "$when"
219 + # Also check classic negotiation without export information
220 + for when in before 8 16 24 28 after; do
221 + check_disconnect "--$proto" --classic-negotiation "neg-classic" "$when"
226 diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out
227 index 0c13888..7419722 100644
228 --- a/tests/qemu-iotests/083.out
229 +++ b/tests/qemu-iotests/083.out
231 QA output created by 083
232 === Check disconnect before neg1 ===
234 -can't open device nbd:127.0.0.1:PORT:exportname=foo
235 +can't open device nbd+tcp://127.0.0.1:PORT/foo
237 === Check disconnect after neg1 ===
239 -can't open device nbd:127.0.0.1:PORT:exportname=foo
240 +can't open device nbd+tcp://127.0.0.1:PORT/foo
242 === Check disconnect 8 neg1 ===
244 -can't open device nbd:127.0.0.1:PORT:exportname=foo
245 +can't open device nbd+tcp://127.0.0.1:PORT/foo
247 === Check disconnect 16 neg1 ===
249 -can't open device nbd:127.0.0.1:PORT:exportname=foo
250 +can't open device nbd+tcp://127.0.0.1:PORT/foo
252 === Check disconnect before export ===
254 -can't open device nbd:127.0.0.1:PORT:exportname=foo
255 +can't open device nbd+tcp://127.0.0.1:PORT/foo
257 === Check disconnect after export ===
259 -can't open device nbd:127.0.0.1:PORT:exportname=foo
260 +can't open device nbd+tcp://127.0.0.1:PORT/foo
262 === Check disconnect 4 export ===
264 -can't open device nbd:127.0.0.1:PORT:exportname=foo
265 +can't open device nbd+tcp://127.0.0.1:PORT/foo
267 === Check disconnect 12 export ===
269 -can't open device nbd:127.0.0.1:PORT:exportname=foo
270 +can't open device nbd+tcp://127.0.0.1:PORT/foo
272 === Check disconnect 16 export ===
274 -can't open device nbd:127.0.0.1:PORT:exportname=foo
275 +can't open device nbd+tcp://127.0.0.1:PORT/foo
277 === Check disconnect before neg2 ===
279 -can't open device nbd:127.0.0.1:PORT:exportname=foo
280 +can't open device nbd+tcp://127.0.0.1:PORT/foo
282 === Check disconnect after neg2 ===
284 @@ -45,11 +45,11 @@ read failed: Input/output error
286 === Check disconnect 8 neg2 ===
288 -can't open device nbd:127.0.0.1:PORT:exportname=foo
289 +can't open device nbd+tcp://127.0.0.1:PORT/foo
291 === Check disconnect 10 neg2 ===
293 -can't open device nbd:127.0.0.1:PORT:exportname=foo
294 +can't open device nbd+tcp://127.0.0.1:PORT/foo
296 === Check disconnect before request ===
298 @@ -86,23 +86,132 @@ read 512/512 bytes at offset 0
300 === Check disconnect before neg-classic ===
302 -can't open device nbd:127.0.0.1:PORT
303 +can't open device nbd+tcp://127.0.0.1:PORT/
305 === Check disconnect 8 neg-classic ===
307 -can't open device nbd:127.0.0.1:PORT
308 +can't open device nbd+tcp://127.0.0.1:PORT/
310 === Check disconnect 16 neg-classic ===
312 -can't open device nbd:127.0.0.1:PORT
313 +can't open device nbd+tcp://127.0.0.1:PORT/
315 === Check disconnect 24 neg-classic ===
317 -can't open device nbd:127.0.0.1:PORT
318 +can't open device nbd+tcp://127.0.0.1:PORT/
320 === Check disconnect 28 neg-classic ===
322 -can't open device nbd:127.0.0.1:PORT
323 +can't open device nbd+tcp://127.0.0.1:PORT/
325 +=== Check disconnect after neg-classic ===
327 +read failed: Input/output error
329 +=== Check disconnect before neg1 ===
331 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
333 +=== Check disconnect after neg1 ===
335 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
337 +=== Check disconnect 8 neg1 ===
339 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
341 +=== Check disconnect 16 neg1 ===
343 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
345 +=== Check disconnect before export ===
347 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
349 +=== Check disconnect after export ===
351 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
353 +=== Check disconnect 4 export ===
355 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
357 +=== Check disconnect 12 export ===
359 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
361 +=== Check disconnect 16 export ===
363 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
365 +=== Check disconnect before neg2 ===
367 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
369 +=== Check disconnect after neg2 ===
371 +read failed: Input/output error
373 +=== Check disconnect 8 neg2 ===
375 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
377 +=== Check disconnect 10 neg2 ===
379 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
381 +=== Check disconnect before request ===
383 +read failed: Input/output error
385 +=== Check disconnect after request ===
387 +read failed: Input/output error
389 +=== Check disconnect before reply ===
391 +read failed: Input/output error
393 +=== Check disconnect after reply ===
395 +read failed: Input/output error
397 +=== Check disconnect 4 reply ===
399 +read failed: Input/output error
401 +=== Check disconnect 8 reply ===
403 +read failed: Input/output error
405 +=== Check disconnect before data ===
407 +read failed: Input/output error
409 +=== Check disconnect after data ===
411 +read 512/512 bytes at offset 0
412 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
414 +=== Check disconnect before neg-classic ===
416 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
418 +=== Check disconnect 8 neg-classic ===
420 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
422 +=== Check disconnect 16 neg-classic ===
424 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
426 +=== Check disconnect 24 neg-classic ===
428 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
430 +=== Check disconnect 28 neg-classic ===
432 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
434 === Check disconnect after neg-classic ===
436 diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
437 index c9a2d5c..f06d4dc 100644
438 --- a/tests/qemu-iotests/common.filter
439 +++ b/tests/qemu-iotests/common.filter
440 @@ -154,9 +154,9 @@ _filter_nbd()
442 # Filter out the TCP port number since this changes between runs.
443 sed -e '/nbd\/.*\.c:/d' \
444 - -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \
445 + -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \
446 -e "s#?socket=$TEST_DIR#?socket=TEST_DIR#g" \
447 - -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#'
448 + -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#'
451 # make sure this script returns success