]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc, repo_utils: drop six.ensure_str()
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jun 2020 10:11:00 +0000 (18:11 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 17 Jun 2020 14:19:20 +0000 (22:19 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
teuthology/misc.py
teuthology/repo_utils.py
teuthology/suite/test/test_util.py
teuthology/test/test_repo_utils.py

index f6a3dc753ef496286ae23f2e2b7ae7d12df75098..0ddd2e8368aa61ecd334329c2672bdc110ed54ae 100644 (file)
@@ -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:
index e9aaf636d795f029ca44aa7b8cd183b5a27884fb..be7ca22eb289e4f832d8e79b749ed88bb5d6aa8d 100644 (file)
@@ -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)
index ba7e139d320f628d11eb482fb2f6d92beeba0fd8..e4a811b6123fc68418ec4c70d0d1ef7293a6aca2 100644 (file)
@@ -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')
 
 
index 3e93980e2a6196bc88453be347e81bc0957b62a0..445a91d9f74a0253e5c3bdd8b978e4f9fe4a2aec 100644 (file)
@@ -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