2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-27 19:37:44 +00:00

Fix python3 for ipmi set user

First normalize to bytes and then use byte to null
pad and finally use bytearray to normalize the
2 and 3 to behave the same on indexing and use that
for extending the command.

Change-Id: I9e3e89f5f8ac411c770f1a6371f9b365868e8c87
This commit is contained in:
Jarrod Johnson 2019-10-11 09:29:51 -04:00
parent 8fe5049005
commit 87c7840c09

View File

@ -1674,10 +1674,13 @@ class Command(object):
:param name: username (limit of 16bytes)
"""
data = [uid]
if not isinstance(name, bytes):
name = name.encode('utf-8')
if len(name) > 16:
raise Exception('name must be less than or = 16 chars')
name = name.ljust(16, "\x00")
data.extend([ord(x) for x in name])
name = name.ljust(16, b'\x00')
name = bytearray(name)
data.extend(name)
self.xraw_command(netfn=0x06, command=0x45, data=data)
return True