From: Kefu Chai Date: Fri, 14 Jul 2017 16:07:03 +0000 (+0800) Subject: tests: ceph-disk: use communicate() instead of wait() for output X-Git-Tag: v12.1.1~16^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=73c0740b0822becc77ae25e8d6410ca8a1530832;p=ceph.git 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 --- diff --git a/qa/workunits/ceph-disk/ceph-disk-test.py b/qa/workunits/ceph-disk/ceph-disk-test.py index b80e1da89712..6c476ead9e6e 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.'):