From 1b18e6b4a6ba678f4f66813d134aff9921f7e8bc Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Mon, 2 Mar 2020 15:43:41 +0100 Subject: [PATCH] qa/tasks/vstart_runner: use io.BytesIO for py3 compat Use io.BytesIO instead of StringIO for py3 compatibility. Signed-off-by: Kefu Chai Signed-off-by: Kyr Shatskyy (cherry picked from commit 49592af4005808db4ed5301e9072525bd709f44a) Conflicts: qa/tasks/vstart_runner.py: trivial resolution --- qa/tasks/vstart_runner.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index 2ce697538fe51..d2be17ee831c1 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -30,7 +30,7 @@ Alternative usage: """ -from six import StringIO +from io import BytesIO from collections import defaultdict import getpass import signal @@ -47,6 +47,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 @@ -143,15 +144,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 @@ -172,8 +166,8 @@ class LocalRemoteProcess(object): 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) @@ -309,9 +303,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): @@ -336,9 +329,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: @@ -499,7 +492,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: @@ -603,7 +596,7 @@ class LocalCephManager(CephManager): if watch_channel is not None: args.append("--watch-channel") args.append(watch_channel) - proc = self.controller.run(args, wait=False, stdout=StringIO()) + proc = self.controller.run(args=args, wait=False, stdout=BytesIO()) return proc def raw_cluster_cmd(self, *args, **kwargs): @@ -611,8 +604,9 @@ class LocalCephManager(CephManager): args like ["osd", "dump"} return stdout string """ - proc = self.controller.run([os.path.join(BIN_PREFIX, "ceph")] + list(args), **kwargs) - return proc.stdout.getvalue() + proc = self.controller.run(args=[os.path.join(BIN_PREFIX, "ceph")] + \ + list(args), **kwargs) + return six.ensure_str(proc.stdout.getvalue()) def raw_cluster_cmd_result(self, *args, **kwargs): """ @@ -924,9 +918,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: -- 2.39.5