]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0046-qemu-iotests-test-NBD-over-UNIX-domain-sockets-in-08.patch
4c4d6180802db69ee066ef2f40b61a4aa6b4caa7
[pve-qemu.git] / debian / patches / extra / 0046-qemu-iotests-test-NBD-over-UNIX-domain-sockets-in-08.patch
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
5
6 RH-Author: Eric Blake <eblake@redhat.com>
7 Message-id: <20170927175725.20023-7-eblake@redhat.com>
8 Patchwork-id: 76670
9 O-Subject: [RHEV-7.4.z qemu-kvm-rhev PATCH 6/7] qemu-iotests: test NBD over UNIX domain sockets in 083
10 Bugzilla: 1495474
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>
14
15 From: Stefan Hajnoczi <stefanha@redhat.com>
16
17 083 only tests TCP. Some failures might be specific to UNIX domain
18 sockets.
19
20 A few adjustments are necessary:
21
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
25 need netstat anymore.
26
27 2. The NBD filter does not work for the UNIX domain sockets URIs we
28 generate and must be extended.
29
30 3. Run all tests twice: once for TCP and once for UNIX domain sockets.
31
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>
38
39 Conflicts:
40 tests/qemu-iotests/083.out - error message improvements not backported
41
42 Signed-off-by: Eric Blake <eblake@redhat.com>
43 ---
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(-)
48
49 diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083
50 index bff9360048..0306f112da 100755
51 --- a/tests/qemu-iotests/083
52 +++ b/tests/qemu-iotests/083
53 @@ -27,6 +27,14 @@ echo "QA output created by $seq"
54 here=`pwd`
55 status=1 # failure is the default!
56
57 +_cleanup()
58 +{
59 + rm -f nbd.sock
60 + rm -f nbd-fault-injector.out
61 + rm -f nbd-fault-injector.conf
62 +}
63 +trap "_cleanup; exit \$status" 0 1 2 3 15
64 +
65 # get standard environment, filters and checks
66 . ./common.rc
67 . ./common.filter
68 @@ -35,81 +43,105 @@ _supported_fmt generic
69 _supported_proto nbd
70 _supported_os Linux
71
72 -# Pick a TCP port based on our pid. This way multiple instances of this test
73 -# can run in parallel without conflicting.
74 -choose_tcp_port() {
75 - echo $((($$ % 31744) + 1024)) # 1024 <= port < 32768
76 -}
77 -
78 -wait_for_tcp_port() {
79 - while ! (netstat --tcp --listening --numeric | \
80 - grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do
81 - sleep 0.1
82 +check_disconnect() {
83 + local event export_name=foo extra_args nbd_addr nbd_url proto when
84 +
85 + while true; do
86 + case $1 in
87 + --classic-negotiation)
88 + shift
89 + extra_args=--classic-negotiation
90 + export_name=
91 + ;;
92 + --tcp)
93 + shift
94 + proto=tcp
95 + ;;
96 + --unix)
97 + shift
98 + proto=unix
99 + ;;
100 + *)
101 + break
102 + ;;
103 + esac
104 done
105 -}
106
107 -check_disconnect() {
108 event=$1
109 when=$2
110 - negotiation=$3
111 echo "=== Check disconnect $when $event ==="
112 echo
113
114 - port=$(choose_tcp_port)
115 -
116 cat > "$TEST_DIR/nbd-fault-injector.conf" <<EOF
117 [inject-error]
118 event=$event
119 when=$when
120 EOF
121
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"
127 else
128 - nbd_url="nbd:127.0.0.1:$port:exportname=foo"
129 + nbd_addr="$TEST_DIR/nbd.sock"
130 + fi
131 +
132 + rm -f "$TEST_DIR/nbd.sock"
133 +
134 + $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
135 +
136 + # Wait for server to be ready
137 + while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do
138 + sleep 0.1
139 + done
140 +
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")
143 +
144 + if [ "$proto" = "tcp" ]; then
145 + nbd_url="nbd+tcp://$nbd_addr/$export_name"
146 + else
147 + nbd_url="nbd+unix:///$export_name?socket=$nbd_addr"
148 fi
149
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
153
154 echo
155 }
156
157 -for event in neg1 "export" neg2 request reply data; do
158 - for when in before after; do
159 - check_disconnect "$event" "$when"
160 - done
161 -
162 - # Also inject short replies from the NBD server
163 - case "$event" in
164 - neg1)
165 - for when in 8 16; do
166 - check_disconnect "$event" "$when"
167 - done
168 - ;;
169 - "export")
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"
176 done
177 - ;;
178 - neg2)
179 - for when in 8 10; do
180 - check_disconnect "$event" "$when"
181 - done
182 - ;;
183 - reply)
184 - for when in 4 8; do
185 - check_disconnect "$event" "$when"
186 - done
187 - ;;
188 - esac
189 -done
190
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
195 + case "$event" in
196 + neg1)
197 + for when in 8 16; do
198 + check_disconnect "--$proto" "$event" "$when"
199 + done
200 + ;;
201 + "export")
202 + for when in 4 12 16; do
203 + check_disconnect "--$proto" "$event" "$when"
204 + done
205 + ;;
206 + neg2)
207 + for when in 8 10; do
208 + check_disconnect "--$proto" "$event" "$when"
209 + done
210 + ;;
211 + reply)
212 + for when in 4 8; do
213 + check_disconnect "--$proto" "$event" "$when"
214 + done
215 + ;;
216 + esac
217 + done
218 +
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"
222 + done
223 done
224
225 # success, all done
226 diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out
227 index 0c13888ba1..7419722cd7 100644
228 --- a/tests/qemu-iotests/083.out
229 +++ b/tests/qemu-iotests/083.out
230 @@ -1,43 +1,43 @@
231 QA output created by 083
232 === Check disconnect before neg1 ===
233
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
236
237 === Check disconnect after neg1 ===
238
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
241
242 === Check disconnect 8 neg1 ===
243
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
246
247 === Check disconnect 16 neg1 ===
248
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
251
252 === Check disconnect before export ===
253
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
256
257 === Check disconnect after export ===
258
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
261
262 === Check disconnect 4 export ===
263
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
266
267 === Check disconnect 12 export ===
268
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
271
272 === Check disconnect 16 export ===
273
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
276
277 === Check disconnect before neg2 ===
278
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
281
282 === Check disconnect after neg2 ===
283
284 @@ -45,11 +45,11 @@ read failed: Input/output error
285
286 === Check disconnect 8 neg2 ===
287
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
290
291 === Check disconnect 10 neg2 ===
292
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
295
296 === Check disconnect before request ===
297
298 @@ -86,23 +86,132 @@ read 512/512 bytes at offset 0
299
300 === Check disconnect before neg-classic ===
301
302 -can't open device nbd:127.0.0.1:PORT
303 +can't open device nbd+tcp://127.0.0.1:PORT/
304
305 === Check disconnect 8 neg-classic ===
306
307 -can't open device nbd:127.0.0.1:PORT
308 +can't open device nbd+tcp://127.0.0.1:PORT/
309
310 === Check disconnect 16 neg-classic ===
311
312 -can't open device nbd:127.0.0.1:PORT
313 +can't open device nbd+tcp://127.0.0.1:PORT/
314
315 === Check disconnect 24 neg-classic ===
316
317 -can't open device nbd:127.0.0.1:PORT
318 +can't open device nbd+tcp://127.0.0.1:PORT/
319
320 === Check disconnect 28 neg-classic ===
321
322 -can't open device nbd:127.0.0.1:PORT
323 +can't open device nbd+tcp://127.0.0.1:PORT/
324 +
325 +=== Check disconnect after neg-classic ===
326 +
327 +read failed: Input/output error
328 +
329 +=== Check disconnect before neg1 ===
330 +
331 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
332 +
333 +=== Check disconnect after neg1 ===
334 +
335 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
336 +
337 +=== Check disconnect 8 neg1 ===
338 +
339 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
340 +
341 +=== Check disconnect 16 neg1 ===
342 +
343 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
344 +
345 +=== Check disconnect before export ===
346 +
347 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
348 +
349 +=== Check disconnect after export ===
350 +
351 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
352 +
353 +=== Check disconnect 4 export ===
354 +
355 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
356 +
357 +=== Check disconnect 12 export ===
358 +
359 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
360 +
361 +=== Check disconnect 16 export ===
362 +
363 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
364 +
365 +=== Check disconnect before neg2 ===
366 +
367 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
368 +
369 +=== Check disconnect after neg2 ===
370 +
371 +read failed: Input/output error
372 +
373 +=== Check disconnect 8 neg2 ===
374 +
375 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
376 +
377 +=== Check disconnect 10 neg2 ===
378 +
379 +can't open device nbd+unix:///foo?socket=TEST_DIR/nbd.sock
380 +
381 +=== Check disconnect before request ===
382 +
383 +read failed: Input/output error
384 +
385 +=== Check disconnect after request ===
386 +
387 +read failed: Input/output error
388 +
389 +=== Check disconnect before reply ===
390 +
391 +read failed: Input/output error
392 +
393 +=== Check disconnect after reply ===
394 +
395 +read failed: Input/output error
396 +
397 +=== Check disconnect 4 reply ===
398 +
399 +read failed: Input/output error
400 +
401 +=== Check disconnect 8 reply ===
402 +
403 +read failed: Input/output error
404 +
405 +=== Check disconnect before data ===
406 +
407 +read failed: Input/output error
408 +
409 +=== Check disconnect after data ===
410 +
411 +read 512/512 bytes at offset 0
412 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
413 +
414 +=== Check disconnect before neg-classic ===
415 +
416 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
417 +
418 +=== Check disconnect 8 neg-classic ===
419 +
420 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
421 +
422 +=== Check disconnect 16 neg-classic ===
423 +
424 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
425 +
426 +=== Check disconnect 24 neg-classic ===
427 +
428 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
429 +
430 +=== Check disconnect 28 neg-classic ===
431 +
432 +can't open device nbd+unix:///?socket=TEST_DIR/nbd.sock
433
434 === Check disconnect after neg-classic ===
435
436 diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
437 index 104001358b..65ec315f25 100644
438 --- a/tests/qemu-iotests/common.filter
439 +++ b/tests/qemu-iotests/common.filter
440 @@ -153,9 +153,9 @@ _filter_nbd()
441 #
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#'
449 }
450
451 # make sure this script returns success
452 --
453 2.11.0
454