From deb2c6af471f433dfb2779682d01e1518c754bdd Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 26 Mar 2021 08:31:04 -0400 Subject: [PATCH] Tolerate spec deviations There are some popular Redfish implementations that violate the standard. More gracefully tolerate the violations. Change-Id: I52d1bb21a812c8c721a6ee0888dd92b80944fd65 --- pyghmi/redfish/command.py | 2 +- pyghmi/redfish/oem/generic.py | 5 +++-- pyghmi/util/webclient.py | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index 23e49b1c..ff1c46ba 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -1456,7 +1456,7 @@ class Command(object): return for vmurl in vmurls: vminfo = self._do_web_request(vmurl, cache=False) - if vminfo['ConnectedVia'] != 'NotConnected': + if vminfo.get('ConnectedVia', None) != 'NotConnected': continue self._do_web_request(vmurl, {'Image': url, 'Inserted': True}, 'PATCH') diff --git a/pyghmi/redfish/oem/generic.py b/pyghmi/redfish/oem/generic.py index 8a3ab72d..480d8615 100644 --- a/pyghmi/redfish/oem/generic.py +++ b/pyghmi/redfish/oem/generic.py @@ -73,11 +73,12 @@ class OEMHandler(object): vmurls = [x['@odata.id'] for x in vmlist.get('Members', [])] for vminfo in fishclient._do_bulk_requests(vmurls): vminfo = vminfo[0] - if vminfo['Image']: + if vminfo.get('Image', None): imageurl = vminfo['Image'].replace( '/' + vminfo['ImageName'], '') yield media.Media(vminfo['ImageName'], imageurl) - elif vminfo['Inserted'] and vminfo['ImageName']: + elif vminfo.get('Inserted', None) and vminfo.get( + 'ImageName', None): yield media.Media(vminfo['ImageName']) def get_inventory_descriptions(self, withids=False): diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 7994a467..2629dc52 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -239,7 +239,12 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): raise body = rsp.read() if rsp.getheader('Content-Encoding', None) == 'gzip': - body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() + try: + body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() + except IOError: + # some implementations will send non-gzipped and claim it as + # gzip + pass if rsp.status >= 200 and rsp.status < 300: if body and not isinstance(body, str): body = body.decode('utf8') @@ -307,7 +312,12 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): % rsp.read()) body = rsp.read() if rsp.getheader('Content-Encoding', None) == 'gzip': - body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() + try: + body = gzip.GzipFile(fileobj=io.BytesIO(body)).read() + except IOError: + # In case the implementation lied, let the body return + # unprocessed + pass return body def get_upload_progress(self):