]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_objectstore_tool: fix check_output on python2.6 3627/head
authorKefu Chai <kchai@redhat.com>
Thu, 5 Feb 2015 08:33:08 +0000 (16:33 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 6 Feb 2015 17:23:02 +0000 (01:23 +0800)
* backported the subprocess.check_output from python2.7

Fixes: #10756
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/ceph_objectstore_tool.py

index 600a386aa192646466cd1875ecbcb718268e6d90..52ae51ce0257a94d4c63493dc2d45ad729147e32 100755 (executable)
@@ -1,7 +1,25 @@
 #!/usr/bin/env python
 
 from subprocess import call
-from subprocess import check_output
+try:
+    from subprocess import check_output
+except ImportError:
+    def check_output(*popenargs, **kwargs):
+        import subprocess
+        # backported from python 2.7 stdlib
+        process = subprocess.Popen(
+           stdout=subprocess.PIPE, *popenargs, **kwargs)
+        output, unused_err = process.communicate()
+        retcode = process.poll()
+        if retcode:
+            cmd = kwargs.get("args")
+            if cmd is None:
+                cmd = popenargs[0]
+            error = subprocess.CalledProcessError(retcode, cmd)
+            error.output = output
+            raise error
+        return output
+
 import subprocess
 import os
 import time