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