2
0
mirror of https://opendev.org/x/pyghmi synced 2026-03-31 23:33:34 +00:00

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
This commit is contained in:
Jarrod Johnson
2021-08-12 11:25:14 -04:00
committed by luyf5
parent 1cd47f71b2
commit b8cb131a13
4 changed files with 17 additions and 10 deletions

View File

@@ -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']]

View File

@@ -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:

View File

@@ -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):

View File

@@ -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