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:23 +0200
4 Subject: [PATCH] qemu-iotests: improve nbd-fault-injector.py startup
7 RH-Author: Eric Blake <eblake@redhat.com>
8 Message-id: <20170927175725.20023-6-eblake@redhat.com>
10 O-Subject: [RHEV-7.4.z qemu-kvm-rhev PATCH 5/7] qemu-iotests: improve nbd-fault-injector.py startup protocol
12 RH-Acked-by: Max Reitz <mreitz@redhat.com>
13 RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
14 RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
16 From: Stefan Hajnoczi <stefanha@redhat.com>
18 Currently 083 waits for the nbd-fault-injector.py server to start up by
19 looping until netstat shows the TCP listen socket.
21 The startup protocol can be simplified by passing a 0 port number to
22 nbd-fault-injector.py. The kernel will allocate a port in bind(2) and
23 the final port number can be printed by nbd-fault-injector.py.
25 This should make it slightly nicer and less TCP-specific to wait for
26 server startup. This patch changes nbd-fault-injector.py, the next one
27 will rewrite server startup in 083.
29 Reviewed-by: Eric Blake <eblake@redhat.com>
30 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
31 Message-Id: <20170829122745.14309-3-stefanha@redhat.com>
32 Signed-off-by: Eric Blake <eblake@redhat.com>
33 (cherry picked from commit 6e592fc92234a58c7156c385840633c17dedd24f)
34 Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
36 tests/qemu-iotests/nbd-fault-injector.py | 4 ++++
37 1 file changed, 4 insertions(+)
39 diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/nbd-fault-injector.py
40 index 6c07191..1c10dcb 100755
41 --- a/tests/qemu-iotests/nbd-fault-injector.py
42 +++ b/tests/qemu-iotests/nbd-fault-injector.py
43 @@ -235,11 +235,15 @@ def open_socket(path):
44 sock = socket.socket()
45 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
46 sock.bind((host, int(port)))
48 + # If given port was 0 the final port number is now available
49 + path = '%s:%d' % sock.getsockname()
51 sock = socket.socket(socket.AF_UNIX)
54 print 'Listening on %s' % path
55 + sys.stdout.flush() # another process may be waiting, show message now