From: Kefu Chai Date: Wed, 17 Jun 2020 10:11:00 +0000 (+0800) Subject: misc, repo_utils: drop six.ensure_str() X-Git-Tag: 1.1.0~86^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8975ecf4d9da57487907e95dd967ee738c38bb8f;p=teuthology.git misc, repo_utils: drop six.ensure_str() Signed-off-by: Kefu Chai --- diff --git a/teuthology/misc.py b/teuthology/misc.py index f6a3dc753..0ddd2e836 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -1146,12 +1146,13 @@ def _ssh_keyscan(hostname): stderr=subprocess.PIPE, ) p.wait() - for line in p.stderr.readlines(): - line = ensure_str(line.strip()) + for line in p.stderr: + line = line.decode() + line = line.strip() if line and not line.startswith('#'): log.error(line) - for line in p.stdout.readlines(): - host, key = ensure_str(line.strip()).split(' ', 1) + for line in p.stdout: + host, key = line.strip().decode().split(' ', 1) return key @@ -1320,8 +1321,8 @@ def sh(command, log_limit=1024, cwd=None, env=None): lines = [] truncated = False with proc.stdout: - for line in iter(proc.stdout.readline, b''): - line = ensure_str(line) + for line in proc.stdout: + line = line.decode() lines.append(line) line = line.strip() if len(line) > log_limit: diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index e9aaf636d..be7ca22eb 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -3,9 +3,6 @@ import os import re import shutil import subprocess - -from six import ensure_str - import time from teuthology import misc @@ -68,7 +65,7 @@ def ls_remote(url, ref): result = subprocess.check_output( cmd, shell=True).split() if result: - sha1 = ensure_str(result[0]) + sha1 = result[0].decode() log.debug("{} -> {}".format(cmd, sha1)) return sha1 @@ -132,7 +129,7 @@ def clone_repo(repo_url, dest_path, branch, shallow=True): stderr=subprocess.STDOUT) not_found_str = "Remote branch %s not found" % branch - out = ensure_str(proc.stdout.read()) + out = proc.stdout.read().decode() result = proc.wait() # Newer git versions will bail if the branch is not found, but older ones # will not. Fortunately they both output similar text. @@ -229,7 +226,7 @@ def fetch(repo_path): stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if proc.wait() != 0: - out = ensure_str(proc.stdout.read()) + out = proc.stdout.read().decode() log.error(out) raise GitError("git fetch failed!") @@ -257,7 +254,7 @@ def fetch_branch(repo_path, branch, shallow=True): stderr=subprocess.STDOUT) if proc.wait() != 0: not_found_str = "fatal: couldn't find remote ref %s" % branch - out = ensure_str(proc.stdout.read()) + out = proc.stdout.read().decode() log.error(out) if not_found_str in out.lower(): raise BranchNotFoundError(branch) diff --git a/teuthology/suite/test/test_util.py b/teuthology/suite/test/test_util.py index ba7e139d3..e4a811b61 100644 --- a/teuthology/suite/test/test_util.py +++ b/teuthology/suite/test/test_util.py @@ -22,7 +22,7 @@ def test_git_branch_exists(m_check_output, project_or_url): m_check_output.return_value = '' assert False == util.git_branch_exists( project_or_url, 'nobranchnowaycanthappen') - m_check_output.return_value = 'HHH branch' + m_check_output.return_value = b'HHH branch' assert True == util.git_branch_exists(project_or_url, 'master') diff --git a/teuthology/test/test_repo_utils.py b/teuthology/test/test_repo_utils.py index 3e93980e2..445a91d9f 100644 --- a/teuthology/test/test_repo_utils.py +++ b/teuthology/test/test_repo_utils.py @@ -106,7 +106,7 @@ class TestRepoUtils(object): process_mock = mock.Mock() attrs = { 'wait.return_value': 1, - 'stdout.read.return_value': "%s %s" % (git_str, branch_name), + 'stdout.read.return_value': f"{git_str} {branch_name}".encode(), } process_mock.configure_mock(**attrs) mock_popen.return_value = process_mock