Support empty successful scenario

redfish has a concept of 'no news is good news', and firmware is
changing to use that.  Support both old and new behavior.

Change-Id: I1b85359ee1236c7ad5f26b67640415839ad1073b
This commit is contained in:
Jarrod Johnson
2018-12-10 13:32:37 -05:00
parent 58108b2e5d
commit 1dc3844ea8
2 changed files with 14 additions and 7 deletions

View File

@@ -162,6 +162,13 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
def grab_json_response(self, url, data=None, referer=None, headers=None):
self.lastjsonerror = None
body, status = self.grab_json_response_with_status(self, url, data, referer, headers)
if status == 200:
return body
self.lastjsonerror = body
return {}
def grab_json_response_with_status(self, url, data=None, referer=None, headers=None):
webclient = self.dupe()
if isinstance(data, dict):
data = json.dumps(data)
@@ -171,10 +178,10 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
else:
webclient.request('GET', url, referer=referer, headers=headers)
rsp = webclient.getresponse()
if rsp.status == 200:
return json.loads(rsp.read())
self.lastjsonerror = rsp.read()
return {}
body = rsp.read()
if rsp.status >= 200 and rsp.status < 300:
return json.loads(body) if body else {}, rsp.status
return body, rsp.status
def download(self, url, file):
"""Download a file to filename or file object