From a7f18e46b911d9047ebb3ac0f9de4d4c2e59c704 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 28 Jun 2020 19:43:09 +0800 Subject: [PATCH] qa/tasks/{ceph,ceph_manager}: drop py2 support Signed-off-by: Kefu Chai --- qa/tasks/ceph.py | 16 ++++++++-------- qa/tasks/ceph_manager.py | 40 ++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/qa/tasks/ceph.py b/qa/tasks/ceph.py index b83995acb40ad..71fc2eafae19a 100644 --- a/qa/tasks/ceph.py +++ b/qa/tasks/ceph.py @@ -4,6 +4,7 @@ Ceph cluster task. Handle the setup, starting, and clean-up of a Ceph cluster. """ from io import BytesIO +from io import StringIO import argparse import configobj @@ -15,7 +16,6 @@ import json import time import gevent import re -import six import socket from paramiko import SSHException @@ -192,12 +192,12 @@ def ceph_log(ctx, config): testdir = teuthology.get_testdir(ctx) remote_logrotate_conf = '%s/logrotate.ceph-test.conf' % testdir rotate_conf_path = os.path.join(os.path.dirname(__file__), 'logrotate.conf') - with open(rotate_conf_path, 'rb') as f: + with open(rotate_conf_path) as f: conf = "" for daemon, size in daemons.items(): log.info('writing logrotate stanza for {}'.format(daemon)) - conf += six.ensure_str(f.read()).format(daemon_type=daemon, - max_size=size) + conf += f.read().format(daemon_type=daemon, + max_size=size) f.seek(0, 0) for remote in ctx.cluster.remotes.keys(): @@ -320,14 +320,14 @@ def valgrind_post(ctx, config): "/dev/null | sort | uniq", wait=False, check_status=False, - stdout=BytesIO(), + stdout=StringIO(), ) lookup_procs.append((proc, remote)) valgrind_exception = None for (proc, remote) in lookup_procs: proc.wait() - out = six.ensure_str(proc.stdout.getvalue()) + out = proc.stdout.getvalue() for line in out.split('\n'): if line == '': continue @@ -1298,11 +1298,11 @@ def run_daemon(ctx, config, type_): if type_ == 'osd': datadir='/var/lib/ceph/osd/{cluster}-{id}'.format( cluster=cluster_name, id=id_) - osd_uuid = six.ensure_str(teuthology.get_file( + osd_uuid = teuthology.get_file( remote=remote, path=datadir + '/fsid', sudo=True, - )).strip() + ).decode().strip() osd_uuids[id_] = osd_uuid for osd_id in range(len(osd_uuids)): id_ = str(osd_id) diff --git a/qa/tasks/ceph_manager.py b/qa/tasks/ceph_manager.py index 1d304cbebfdc7..4f1cbca93c853 100644 --- a/qa/tasks/ceph_manager.py +++ b/qa/tasks/ceph_manager.py @@ -13,10 +13,8 @@ import logging import threading import traceback import os -import six -from io import BytesIO -from six import StringIO +from io import BytesIO, StringIO from teuthology import misc as teuthology from tasks.scrub import Scrubber from tasks.util.rados import cmd_erasure_code_profile @@ -312,7 +310,7 @@ class OSDThrasher(Thrasher): "exp list-pgs failure with status {ret}". format(ret=proc.exitstatus)) - pgs = six.ensure_str(proc.stdout.getvalue()).split('\n')[:-1] + pgs = proc.stdout.getvalue().split('\n')[:-1] if len(pgs) == 0: self.log("No PGs found for osd.{osd}".format(osd=exp_osd)) return @@ -377,7 +375,7 @@ class OSDThrasher(Thrasher): raise Exception("ceph-objectstore-tool: " "imp list-pgs failure with status {ret}". format(ret=proc.exitstatus)) - pgs = six.ensure_str(proc.stdout.getvalue()).split('\n')[:-1] + pgs = proc.stdout.getvalue().split('\n')[:-1] if pg not in pgs: self.log("Moving pg {pg} from osd.{fosd} to osd.{tosd}". format(pg=pg, fosd=exp_osd, tosd=imp_osd)) @@ -1266,22 +1264,20 @@ class ObjectStoreTool: lines.append(cmd) return "\n".join(lines) - def run(self, options, args, stdin=None, stdout=None): - if stdout is None: - stdout = BytesIO() + def run(self, options, args): self.manager.kill_osd(self.osd) - cmd = self.build_cmd(options, args, stdin) + cmd = self.build_cmd(options, args, None) self.manager.log(cmd) try: proc = self.remote.run(args=['bash', '-e', '-x', '-c', cmd], check_status=False, - stdout=stdout, + stdout=BytesIO(), stderr=BytesIO()) proc.wait() if proc.exitstatus != 0: self.manager.log("failed with " + str(proc.exitstatus)) - error = six.ensure_str(proc.stdout.getvalue()) + " " + \ - six.ensure_str(proc.stderr.getvalue()) + error = proc.stdout.getvalue().decode() + " " + \ + proc.stderr.getvalue().decode() raise Exception(error) finally: if self.do_revive: @@ -1899,7 +1895,7 @@ class CephManager: :param erasure_code_use_overwrites: if true, allow overwrites """ with self.lock: - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) assert isinstance(pg_num, int) assert pool_name not in self.pools self.log("creating pool_name %s" % (pool_name,)) @@ -1951,7 +1947,7 @@ class CephManager: :param pool_name: Pool to be removed """ with self.lock: - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) assert pool_name in self.pools self.log("removing pool_name %s" % (pool_name,)) del self.pools[pool_name] @@ -1971,7 +1967,7 @@ class CephManager: Return the number of pgs in the pool specified. """ with self.lock: - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) if pool_name in self.pools: return self.pools[pool_name] return 0 @@ -1983,8 +1979,8 @@ class CephManager: :returns: property as string """ with self.lock: - assert isinstance(pool_name, six.string_types) - assert isinstance(prop, six.string_types) + assert isinstance(pool_name, str) + assert isinstance(prop, str) output = self.raw_cluster_cmd( 'osd', 'pool', @@ -2005,8 +2001,8 @@ class CephManager: This routine retries if set operation fails. """ with self.lock: - assert isinstance(pool_name, six.string_types) - assert isinstance(prop, six.string_types) + assert isinstance(pool_name, str) + assert isinstance(prop, str) assert isinstance(val, int) tries = 0 while True: @@ -2033,7 +2029,7 @@ class CephManager: Increase the number of pgs in a pool """ with self.lock: - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) assert isinstance(by, int) assert pool_name in self.pools if self.get_num_creating() > 0: @@ -2053,7 +2049,7 @@ class CephManager: with self.lock: self.log('contract_pool %s by %s min %s' % ( pool_name, str(by), str(min_pgs))) - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) assert isinstance(by, int) assert pool_name in self.pools if self.get_num_creating() > 0: @@ -2093,7 +2089,7 @@ class CephManager: Set pgpnum property of pool_name pool. """ with self.lock: - assert isinstance(pool_name, six.string_types) + assert isinstance(pool_name, str) assert pool_name in self.pools if not force and self.get_num_creating() > 0: return False -- 2.39.5