diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index e9018bf6..43af277c 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -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 diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index a1893a81..a6c32a35 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -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