From b8cb131a13b5ea53fa50f52bf25c1cca94b82e05 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 12 Aug 2021 11:25:14 -0400 Subject: [PATCH] Compatible with python3 In test, we found these codes can't be compatible with python3, so change them for supporting both python2.7 and python3. Change-Id: Id4b2b4ed6b41f9b9cb8569771f4ab587d5fba0f1 --- pyghmi/ipmi/oem/lenovo/config.py | 12 ++++++++---- pyghmi/ipmi/oem/lenovo/handler.py | 9 ++++++--- pyghmi/ipmi/oem/lenovo/inventory.py | 4 ++-- pyghmi/ipmi/private/spd.py | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/config.py b/pyghmi/ipmi/oem/lenovo/config.py index f51eae45..1badb6d5 100644 --- a/pyghmi/ipmi/oem/lenovo/config.py +++ b/pyghmi/ipmi/oem/lenovo/config.py @@ -305,6 +305,10 @@ class LenovoFirmwareConfig(object): readonly = setting.get('gray-if') if readonly: readonly = _convert_syntax(readonly) + else: + access = setting.get('access') + if access == 'readonly': + readonly = 'true' possible = [] current = None default = None @@ -485,10 +489,6 @@ class LenovoFirmwareConfig(object): for option in options.keys(): if options[option]['new_value'] is None: continue - if options[option]['current'] == options[option]['new_value']: - continue - if options[option]['pending'] == options[option]['new_value']: - continue if options[option]['readonly']: errstr = '{0} is read only'.format(option) if options[option]['readonly_why']: @@ -496,6 +496,10 @@ class LenovoFirmwareConfig(object): ','.join(sorted(options[option]['readonly_why']))) errstr += ea raise pygexc.InvalidParameterValue(errstr) + if options[option]['current'] == options[option]['new_value']: + continue + if options[option]['pending'] == options[option]['new_value']: + continue if isinstance(options[option]['new_value'], six.string_types): # Coerce a simple string parameter to the expected list format options[option]['new_value'] = [options[option]['new_value']] diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index 79291130..480b8c26 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -528,7 +528,7 @@ class OEMHandler(generic.OEMHandler): data=(id_,)) except pygexc.IpmiException: continue # Ignore LEDs we can't retrieve - status = led_status.get(ord(rsp['data'][0]), + status = led_status.get(bytearray(rsp['data'][:])[0], led_status_default) yield (name, {'status': status}) @@ -821,9 +821,12 @@ class OEMHandler(generic.OEMHandler): data=(0x01, 0xc5, 0x00, 0x00))["data"][1:] if not ipv6_addr: return - ipv6_prefix = ord(self.ipmicmd.xraw_command( + rspdata = self.ipmicmd.xraw_command( netfn=0xc, command=0x02, - data=(0x1, 0xc6, 0, 0))['data'][1]) + data=(0x1, 0xc6, 0, 0))['data'] + ipv6_prefix_ba = bytearray(rspdata) + ipv6_prefix = ipv6_prefix_ba[1] + if hasattr(socket, 'inet_ntop'): ipv6str = socket.inet_ntop(socket.AF_INET6, ipv6_addr) else: diff --git a/pyghmi/ipmi/oem/lenovo/inventory.py b/pyghmi/ipmi/oem/lenovo/inventory.py index 6f246e85..248b0e60 100755 --- a/pyghmi/ipmi/oem/lenovo/inventory.py +++ b/pyghmi/ipmi/oem/lenovo/inventory.py @@ -68,7 +68,7 @@ def parse_inventory_category(name, info, countable=True): cur = 0 if countable: - count = struct.unpack("B", raw[cur])[0] + count = bytearray(raw)[cur] cur += 1 else: count = 0 @@ -127,7 +127,7 @@ def parse_inventory_category_entry(raw, fields): continue if (field.fmt[-1] == "s"): - value = value.rstrip("\x00") + value = value.rstrip(b'\x00') if (field.mapper and value in field.mapper): value = field.mapper[value] if (field.valuefunc): diff --git a/pyghmi/ipmi/private/spd.py b/pyghmi/ipmi/private/spd.py index 5acf45a4..c00de3f2 100644 --- a/pyghmi/ipmi/private/spd.py +++ b/pyghmi/ipmi/private/spd.py @@ -736,7 +736,7 @@ class SPD(object): self.info['serial'] = hex(struct.unpack( '>I', struct.pack('4B', *spd[122:126]))[0])[2:].rjust(8, '0') self.info['model'] = struct.pack('18B', *spd[128:146]).strip( - '\x00\xff ') + b'\x00\xff ') def _decode_ddr4(self): spd = self.rawdata