diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 2d12ff6a..8d887075 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -1910,8 +1910,8 @@ class Command(object): """ self.oem_init() mcinfo = self.xraw_command(netfn=6, command=1) - bmcver = '{0}.{1}'.format( - ord(mcinfo['data'][2]), hex(ord(mcinfo['data'][3]))[2:]) + major, minor = struct.unpack('BB', mcinfo['data'][2:4]) + bmcver = '{0}.{1}'.format(major, hex(minor)[2:]) return self._oem.get_oem_firmware(bmcver, components) def get_capping_enabled(self): diff --git a/pyghmi/ipmi/fru.py b/pyghmi/ipmi/fru.py index 6a158644..75a073be 100644 --- a/pyghmi/ipmi/fru.py +++ b/pyghmi/ipmi/fru.py @@ -227,7 +227,7 @@ class FRU(object): # to fru info, particularly the last values # Additionally 0xfe has been observed, which should be a thorn, but # again assuming termination of string is more likely than thorn. - retinfo = retinfo.rstrip('\xfe\xff\x10\x03\x00 ') + retinfo = retinfo.rstrip(b'\xfe\xff\x10\x03\x00 ') if lang in (0, 25): try: retinfo = retinfo.decode('iso-8859-1') @@ -242,7 +242,7 @@ class FRU(object): # removing trailing spaces and nulls like makes sense for text # and rely on vendors to workaround deviations in their OEM # module - retinfo = retinfo.rstrip('\x00 ') + #retinfo = retinfo.rstrip(b'\x00 ') return retinfo, newoffset elif currtype == 1: # BCD 'plus' retdata = '' diff --git a/pyghmi/ipmi/oem/lenovo/energy.py b/pyghmi/ipmi/oem/lenovo/energy.py index a86d1924..f7af5a7a 100644 --- a/pyghmi/ipmi/oem/lenovo/energy.py +++ b/pyghmi/ipmi/oem/lenovo/energy.py @@ -25,10 +25,10 @@ class EnergyManager(object): # the Lenovo, then fallback to IBM # We start with a 'find firmware instance' to test the water and # get the handle (which has always been the same, but just in case - self.iana = bytearray('\x66\x4a\x00') + self.iana = bytearray(b'\x66\x4a\x00') try: rsp = ipmicmd.xraw_command(netfn=0x2e, command=0x82, - data=self.iana + '\x00\x00\x01') + data=self.iana + b'\x00\x00\x01') except pygexc.IpmiException as ie: if ie.ipmicode == 193: # try again with IBM IANA self.iana = bytearray('\x4d\x4f\x00') diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 30031714..e3403640 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -16,6 +16,7 @@ # limitations under the License. import base64 +import binascii from datetime import datetime import errno import fnmatch @@ -77,7 +78,10 @@ def natural_sort(iterable): def fixup_uuid(uuidprop): baduuid = ''.join(uuidprop.split()) uuidprefix = (baduuid[:8], baduuid[8:12], baduuid[12:16]) - a = struct.pack('> 4) + 0x20) tstr += chr((data[2] >> 2) + 0x20) + if not isinstance(tstr, str): + tstr = tstr.decode('utf-8') return tstr elif ipmitype == 3: # ACSII+LATIN1 - return struct.pack("%dB" % len(data), *data) + ret = struct.pack("%dB" % len(data), *data) + if not isinstance(ret, str): + ret = ret.decode('utf-8') + return ret class SDR(object): diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 52c6cdf4..2925b51b 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -1,4 +1,4 @@ -# Copyright 2015-2017 Lenovo +# Copyright 2015-2019 Lenovo # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,11 +28,10 @@ import threading try: import Cookie import httplib - import StringIO except ImportError: import http.client as httplib import http.cookies as Cookie - import io as StringIO +import io __author__ = 'jjohnson2' @@ -140,8 +139,13 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): self.stdheaders[key] = value def set_basic_credentials(self, username, password): - self.stdheaders['Authorization'] = 'Basic {0}'.format( - base64.b64encode(':'.join((username, password)))) + authinfo = ':'.join((username, password)) + if not isinstance(authinfo, bytes): + authinfo = authinfo.encode('utf-8') + authinfo = base64.b64encode(authinfo) + if not isinstance(authinfo, str): + authinfo = authinfo.decode('utf-8') + self.stdheaders['Authorization'] = 'Basic {0}'.format(authinfo) def connect(self): addrinfo = socket.getaddrinfo(self.host, self.port)[0] @@ -203,7 +207,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): rsp = webclient.getresponse() body = rsp.read() if rsp.getheader('Content-Encoding', None) == 'gzip': - body = gzip.GzipFile(fileobj=StringIO.StringIO(body)).read() + body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() if rsp.status >= 200 and rsp.status < 300: return json.loads(body) if body else {}, rsp.status return body, rsp.status @@ -245,7 +249,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): """ if data is None: data = open(filename, 'rb') - self._upbuffer = StringIO.StringIO(get_upload_form(filename, data, + self._upbuffer = io.BytesIO(get_upload_form(filename, data, formname, otherfields)) ulheaders = self.stdheaders.copy() @@ -268,7 +272,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): rsp.read()) body = rsp.read() if rsp.getheader('Content-Encoding', None) == 'gzip': - body = gzip.GzipFile(fileobj=StringIO.StringIO(body)).read() + body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() return body def get_upload_progress(self):