Commit 6177b584 authored by Max Reitz's avatar Max Reitz Committed by Eric Blake
Browse files

iotests.py: Add qemu_nbd_early_pipe()



qemu_nbd_pipe() currently unconditionally reads qemu-nbd's output.  That
is not ideal because qemu-nbd may keep stderr open after the parent
process has exited.

Currently, the only user of qemu_nbd_pipe() is 147, which discards the
whole output if the parent process returned success and only evaluates
it on error.  Therefore, we can replace qemu_nbd_pipe() by
qemu_nbd_early_pipe() that does the same: Discard the output on success,
and return it on error.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <20190508211820.17851-3-mreitz@redhat.com>
Signed-off-by: default avatarEric Blake <eblake@redhat.com>
parent 637bc5a5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import socket
import stat
import time
import iotests
from iotests import cachemode, imgfmt, qemu_img, qemu_nbd, qemu_nbd_pipe
from iotests import cachemode, imgfmt, qemu_img, qemu_nbd, qemu_nbd_early_pipe

NBD_PORT_START      = 32768
NBD_PORT_END        = NBD_PORT_START + 1024
@@ -93,7 +93,7 @@ class QemuNBD(NBDBlockdevAddBase):
            pass

    def _try_server_up(self, *args):
        status, msg = qemu_nbd_pipe('-f', imgfmt, test_img, *args)
        status, msg = qemu_nbd_early_pipe('-f', imgfmt, test_img, *args)
        if status == 0:
            return True
        if 'Address already in use' in msg:
+6 −3
Original line number Diff line number Diff line
@@ -209,9 +209,9 @@ def qemu_nbd(*args):
    '''Run qemu-nbd in daemon mode and return the parent's exit code'''
    return subprocess.call(qemu_nbd_args + ['--fork'] + list(args))

def qemu_nbd_pipe(*args):
def qemu_nbd_early_pipe(*args):
    '''Run qemu-nbd in daemon mode and return both the parent's exit code
       and its output'''
       and its output in case of an error'''
    subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
@@ -221,6 +221,9 @@ def qemu_nbd_pipe(*args):
        sys.stderr.write('qemu-nbd received signal %i: %s\n' %
                         (-exitcode,
                          ' '.join(qemu_nbd_args + ['--fork'] + list(args))))
    if exitcode == 0:
        return exitcode, ''
    else:
        return exitcode, subp.communicate()[0]

def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):