From 8bfe977854686149c74de3ebaed7b571d43404dd Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 5 Apr 2020 18:35:42 +0800 Subject: [PATCH] qa/tasks: use StringIO for capturing string output see d8d44ed1566b19eec055e07da2a0fed88fed4152 Signed-off-by: Kefu Chai --- qa/tasks/ceph_manager.py | 9 +++++---- qa/tasks/cephadm.py | 16 ++++++++-------- qa/tasks/watch_notify_same_primary.py | 6 +++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index 1ec5840d77bbb..9ba9725932fc2 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -16,6 +16,7 @@ import os import six from io import BytesIO +from six import StringIO from teuthology import misc as teuthology from tasks.scrub import Scrubber from tasks.util.rados import cmd_erasure_code_profile @@ -1409,7 +1410,7 @@ class CephManager: if watch_channel is not None: args.append("--watch-channel") args.append(watch_channel) - return self.controller.run(args=args, wait=False, stdout=BytesIO(), stdin=run.PIPE) + return self.controller.run(args=args, wait=False, stdout=StringIO(), stdin=run.PIPE) def get_mon_socks(self): """ @@ -1592,7 +1593,7 @@ class CephManager: def osd_admin_socket(self, osd_id, command, check_status=True, timeout=0, stdout=None): if stdout is None: - stdout = BytesIO() + stdout = StringIO() return self.admin_socket('osd', osd_id, command, check_status, timeout, stdout) def find_remote(self, service_type, service_id): @@ -1616,7 +1617,7 @@ class CephManager: to the admin socket """ if stdout is None: - stdout = BytesIO() + stdout = StringIO() remote = self.find_remote(service_type, service_id) @@ -1745,7 +1746,7 @@ class CephManager: five seconds and try again. """ if stdout is None: - stdout = BytesIO() + stdout = StringIO() tries = 0 while True: proc = self.admin_socket(service_type, service_id, diff --git a/qa/tasks/cephadm.py b/qa/tasks/cephadm.py index 046cda1f0d38c..5703c7ad27227 100644 --- a/qa/tasks/cephadm.py +++ b/qa/tasks/cephadm.py @@ -1,8 +1,6 @@ """ Ceph cluster task, deployed via cephadm orchestrator """ -from io import BytesIO - import argparse import configobj import contextlib @@ -12,6 +10,8 @@ import json import re import uuid +from io import BytesIO +from six import StringIO from tarfile import ReadError from tasks.ceph_manager import CephManager from teuthology import misc as teuthology @@ -189,7 +189,7 @@ def ceph_log(ctx, config): run.Raw('|'), 'head', '-n', '1', ]) r = ctx.ceph[cluster_name].bootstrap_remote.run( - stdout=BytesIO(), + stdout=StringIO(), args=args, ) stdout = r.stdout.getvalue() @@ -312,7 +312,7 @@ def ceph_bootstrap(ctx, config): remote=bootstrap_remote, path='{}/seed.{}.conf'.format(testdir, cluster_name), data=conf_fp.getvalue()) - log.debug('Final config:\n' + conf_fp.getvalue()) + log.debug('Final config:\n' + conf_fp.getvalue().decode()) ctx.ceph[cluster_name].conf = seed_config # register initial daemons @@ -429,7 +429,7 @@ def ceph_bootstrap(ctx, config): ]) r = _shell(ctx, cluster_name, remote, ['ceph', 'orch', 'host', 'ls', '--format=json'], - stdout=BytesIO()) + stdout=StringIO()) hosts = [node['hostname'] for node in json.loads(r.stdout.getvalue())] assert remote.shortname in hosts @@ -501,7 +501,7 @@ def ceph_mons(ctx, config): args=[ 'ceph', 'mon', 'dump', '-f', 'json', ], - stdout=BytesIO(), + stdout=StringIO(), ) j = json.loads(r.stdout.getvalue()) if len(j['mons']) == num_mons: @@ -516,7 +516,7 @@ def ceph_mons(ctx, config): args=[ 'ceph', 'config', 'generate-minimal-conf', ], - stdout=BytesIO(), + stdout=StringIO(), ) ctx.ceph[cluster_name].config_file = r.stdout.getvalue() @@ -756,7 +756,7 @@ def ceph_clients(ctx, config): 'mds', 'allow *', 'mgr', 'allow *', ], - stdout=BytesIO(), + stdout=StringIO(), ) keyring = r.stdout.getvalue() teuthology.sudo_write_file( diff --git a/qa/tasks/watch_notify_same_primary.py b/qa/tasks/watch_notify_same_primary.py index 7160979119b38..7c034961c3824 100644 --- a/qa/tasks/watch_notify_same_primary.py +++ b/qa/tasks/watch_notify_same_primary.py @@ -2,7 +2,7 @@ """ watch_notify_same_primary task """ -from io import BytesIO +from six import StringIO import contextlib import logging @@ -68,8 +68,8 @@ def task(ctx, config): "watch", obj(n)], stdin=run.PIPE, - stdout=BytesIO(), - stderr=BytesIO(), + stdout=StringIO(), + stderr=StringIO(), wait=False) return proc -- 2.39.5