Fix initrdinject and urltests with py3

A few random issues scattered about
This commit is contained in:
Cole Robinson 2018-01-27 15:23:22 -05:00
parent b8e2952a9c
commit e47b34c05a
3 changed files with 8 additions and 6 deletions

View File

@ -29,7 +29,8 @@ def _rhel4_initrd_inject(initrd, injections):
file_proc = subprocess.Popen(["file", "-z", initrd],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if "ext2 filesystem" not in file_proc.communicate()[0]:
s = bytes("ext2 filesystem", "ascii")
if s not in file_proc.communicate()[0]:
return False
except Exception:
logging.exception("Failed to file command for rhel4 initrd detection")
@ -45,7 +46,7 @@ def _rhel4_initrd_inject(initrd, injections):
gzip_proc.wait()
newinitrd.close()
debugfserr = ""
debugfserr = bytes()
for filename in injections:
# We have an ext2 filesystem, use debugfs to inject files
cmd = ["debugfs", "-w", "-R",
@ -57,7 +58,7 @@ def _rhel4_initrd_inject(initrd, injections):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
debugfs_proc.wait()
debugfserr += debugfs_proc.stderr.read() or ""
debugfserr += debugfs_proc.stderr.read() or bytes()
gziperr = gzip_proc.stderr.read()
if gziperr:

View File

@ -473,6 +473,7 @@ def format_number(number, SI=0, space=' '):
thresh = 999
depth = 0
max_depth = len(symbols) - 1
number = number or 0
# we want numbers between 0 and thresh, but don't exceed the length
# of our list. In that event, the formatting will be screwed up,

View File

@ -170,7 +170,7 @@ class _URLFetcher(object):
"""
fileobj = io.BytesIO()
self._grabURL(filename, fileobj)
return fileobj.getvalue()
return fileobj.getvalue().decode("utf-8")
class _HTTPURLFetcher(_URLFetcher):
@ -221,7 +221,7 @@ class _FTPURLFetcher(_URLFetcher):
try:
parsed = urllib.parse.urlparse(self.location)
self._ftp = ftplib.FTP()
self._ftp.connect(parsed.hostname, parsed.port)
self._ftp.connect(parsed.hostname, parsed.port or 0)
self._ftp.login()
# Force binary mode
self._ftp.voidcmd("TYPE I")
@ -359,7 +359,7 @@ class _ISOURLFetcher(_URLFetcher):
self._cache_file_list = output.splitlines(False)
return url in self._cache_file_list
return url.encode("ascii") in self._cache_file_list
def fetcherForURI(uri, *args, **kwargs):