From 73c0740b0822becc77ae25e8d6410ca8a1530832 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 15 Jul 2017 00:07:03 +0800 Subject: [PATCH] tests: ceph-disk: use communicate() instead of wait() for output to avoid possible deadlock. quote from doc of Popen.wait() > This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. and print out the stdout and stderr using LOG.warn() if the command fails. Signed-off-by: Kefu Chai --- qa/workunits/ceph-disk/ceph-disk-test.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/qa/workunits/ceph-disk/ceph-disk-test.py b/qa/workunits/ceph-disk/ceph-disk-test.py index b80e1da8971..6c476ead9e6 100644 --- a/qa/workunits/ceph-disk/ceph-disk-test.py +++ b/qa/workunits/ceph-disk/ceph-disk-test.py @@ -80,20 +80,21 @@ class CephDisk: stderr=subprocess.STDOUT, shell=True, bufsize=1) - lines = [] - with proc.stdout: - for line in iter(proc.stdout.readline, b''): - line = line.decode('utf-8') - if 'dangerous and experimental' in line: - LOG.debug('SKIP dangerous and experimental') - continue - lines.append(line) - LOG.debug(line.strip().encode('ascii', 'ignore')) - if proc.wait() != 0: + output, _ = proc.communicate() + if proc.poll(): + LOG.warning(output.decode('utf-8')) raise subprocess.CalledProcessError( returncode=proc.returncode, - cmd=command + cmd=command, + output=output, ) + lines = [] + for line in output.decode('utf-8').split('\n'): + if 'dangerous and experimental' in line: + LOG.debug('SKIP dangerous and experimental') + continue + lines.append(line) + LOG.debug(line.strip().encode('ascii', 'ignore')) return "".join(lines) def unused_disks(self, pattern='[vs]d.'): -- 2.39.5