]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/vstart_runner: use io.BytesIO for py3 compat
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 2 Mar 2020 14:43:41 +0000 (15:43 +0100)
committerKefu Chai <kchai@redhat.com>
Wed, 4 Mar 2020 05:09:17 +0000 (13:09 +0800)
Use io.BytesIO instead of StringIO for py3 compatibility.

Signed-off-by: Kefu Chai <kchai@redhat.com>
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
qa/tasks/vstart_runner.py

index 02f2da7cf96ee27bcd4e503837b8196ab0164d64..ccc706b922b64f8a8ac0ae7a86d79f21fc8af804 100644 (file)
@@ -30,7 +30,7 @@ Alternative usage:
 
 """
 
-from six import StringIO
+from io import BytesIO
 from collections import defaultdict
 import getpass
 import signal
@@ -46,6 +46,7 @@ import errno
 from unittest import suite, loader
 import unittest
 import platform
+from teuthology import misc
 from teuthology.orchestra.run import Raw, quote
 from teuthology.orchestra.daemon import DaemonGroup
 from teuthology.config import config as teuth_config
@@ -153,15 +154,8 @@ class LocalRemoteProcess(object):
     def __init__(self, args, subproc, check_status, stdout, stderr):
         self.args = args
         self.subproc = subproc
-        if stdout is None:
-            self.stdout = StringIO()
-        else:
-            self.stdout = stdout
-
-        if stderr is None:
-            self.stderr = StringIO()
-        else:
-            self.stderr = stderr
+        self.stdout = stdout or BytesIO()
+        self.stderr = stderr or BytesIO()
 
         self.check_status = check_status
         self.exitstatus = self.returncode = None
@@ -176,15 +170,14 @@ class LocalRemoteProcess(object):
                 return
 
         out, err = self.subproc.communicate()
-        out, err = out.decode(), err.decode()
         self.stdout.write(out)
         self.stderr.write(err)
 
         self.exitstatus = self.returncode = self.subproc.returncode
 
         if self.exitstatus != 0:
-            sys.stderr.write(out)
-            sys.stderr.write(err)
+            sys.stderr.write(six.ensure_str(out))
+            sys.stderr.write(six.ensure_str(err))
 
         if self.check_status and self.exitstatus != 0:
             raise CommandFailedError(self.args, self.exitstatus)
@@ -397,9 +390,8 @@ class LocalRemote(object):
         return proc
 
     def sh(self, command, log_limit=1024, cwd=None, env=None):
-        from teuthology.misc import sh as teuth_sh
 
-        return teuth_sh(command=command, log_limit=log_limit, cwd=cwd,
+        return misc.sh(command=command, log_limit=log_limit, cwd=cwd,
                         env=env)
 
 class LocalDaemon(object):
@@ -424,9 +416,9 @@ class LocalDaemon(object):
         """
         Return PID as an integer or None if not found
         """
-        ps_txt = self.controller.run(
+        ps_txt = six.ensure_str(self.controller.run(
             args=["ps", "ww", "-u"+str(os.getuid())]
-        ).stdout.getvalue().strip()
+        ).stdout.getvalue()).strip()
         lines = ps_txt.split("\n")[1:]
 
         for line in lines:
@@ -835,7 +827,7 @@ class LocalFuseMount(FuseMount):
                 log.warn("ls conns failed with {0}, assuming none".format(p.exitstatus))
                 return []
 
-            ls_str = p.stdout.getvalue().strip()
+            ls_str = six.ensure_str(p.stdout.getvalue().strip())
             if ls_str:
                 return [int(n) for n in ls_str.split("\n")]
             else:
@@ -943,7 +935,7 @@ class LocalCephManager(CephManager):
         if watch_channel is not None:
             args.append("--watch-channel")
             args.append(watch_channel)
-        proc = self.controller.run(args=args, wait=False, stdout=StringIO())
+        proc = self.controller.run(args=args, wait=False, stdout=BytesIO())
         return proc
 
     def raw_cluster_cmd(self, *args, **kwargs):
@@ -953,7 +945,7 @@ class LocalCephManager(CephManager):
         """
         proc = self.controller.run(args=[os.path.join(BIN_PREFIX, "ceph")] + \
                                         list(args), **kwargs)
-        return proc.stdout.getvalue()
+        return six.ensure_str(proc.stdout.getvalue())
 
     def raw_cluster_cmd_result(self, *args, **kwargs):
         """
@@ -1347,9 +1339,9 @@ def exec_test():
     remote = LocalRemote()
 
     # Tolerate no MDSs or clients running at start
-    ps_txt = remote.run(
+    ps_txt = six.ensure_str(remote.run(
         args=["ps", "-u"+str(os.getuid())]
-    ).stdout.getvalue().strip()
+    ).stdout.getvalue().strip())
     lines = ps_txt.split("\n")[1:]
     for line in lines:
         if 'ceph-fuse' in line or 'ceph-mds' in line: