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

Fix SR635/SR655 firmware updates in python3

Accomodate python 2 and 3 names for urlencode and
consistently use binary bytes in processing the hpm
contents.

Change-Id: Id733e09c317135a04526e307d850d7c6bc399955
This commit is contained in:
Jarrod Johnson 2019-10-11 15:17:20 -04:00
parent 87c7840c09
commit c4a61ca3c8

View File

@ -19,7 +19,10 @@ import pyghmi.exceptions as exc
import pyghmi.util.webclient as webclient
import struct
import time
import urllib
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
import weakref
hpm_by_filename = {}
@ -40,7 +43,7 @@ def read_hpm(filename):
hpmfile.seek(1, 1)
major, minor, pat = struct.unpack('<BBI', hpmfile.read(6))
currsec.comp_ver = '{0}.{1}.{2}'.format(major, minor, pat)
currsec.comp_name = hpmfile.read(21).rstrip('\x00')
currsec.comp_name = hpmfile.read(21).rstrip(b'\x00')
currlen = struct.unpack('<I', hpmfile.read(4))[0] - 16
oemstr = hpmfile.read(4)
if oemstr != b'OEM\x00':
@ -124,7 +127,7 @@ class TsmHandler(generic.OEMHandler):
'password': self.password,
}
wc = webclient.SecureHTTPConnection(self.tsm, 443, verifycallback=self._certverify, timeout=180)
rsp, status = wc.grab_json_response_with_status('/api/session', urllib.urlencode(authdata))
rsp, status = wc.grab_json_response_with_status('/api/session', urlencode(authdata))
if status < 200 or status >= 300:
raise Exception('Error establishing web session')
self.csrftok = rsp['CSRFToken']