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

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

@ -740,16 +740,16 @@ class XCCClient(IMMClient):
return {'height': int(dsc['u-height']), 'slot': int(dsc['slot'])}
def clear_system_configuration(self):
res = self.wc.grab_json_response(
res = self.wc.grab_json_response_with_status(
'/redfish/v1/Systems/1/Bios/Actions/Bios.ResetBios',
{'Action': 'Bios.ResetBios'},
headers={'Authorization': 'Basic ' + base64.b64encode(
self.username + ':' + self.password),
'Content-Type': 'application/json'})
if not res:
if res[1] < 200 or res[1] >= 300:
raise Exception(
'Unexpected response to clear configuration: {0}'.format(
self.wc.lastjsonerror))
res[0]))
def get_webclient(self, login=True):
cv = self.ipmicmd.certverify

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