]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: ceph-disk: use communicate() instead of wait() for output
authorKefu Chai <kchai@redhat.com>
Fri, 14 Jul 2017 16:07:03 +0000 (00:07 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 15 Jul 2017 03:27:02 +0000 (11:27 +0800)
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 <kchai@redhat.com>
qa/workunits/ceph-disk/ceph-disk-test.py

index b80e1da897128e1e5628dd822030f1a79faa9287..6c476ead9e6ec0bf9459a7dc828acc9b47b5ff3b 100644 (file)
@@ -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.'):