From f9d784f41777ad65d0cc87f5f56cdcae44bd27ff Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 30 Aug 2018 09:46:12 -0400 Subject: [PATCH] Provide feedback if the clear system config attempt fails Also extend webclient to generically hold on to last error. Change-Id: Ied9452927260e22708faf4105a2ed3cafe1a6f46 --- pyghmi/ipmi/oem/lenovo/imm.py | 16 ++++++++++------ pyghmi/util/webclient.py | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 90d1b16f..bb0d6b14 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -687,12 +687,16 @@ class XCCClient(IMMClient): return {'height': int(dsc['u-height']), 'slot': int(dsc['slot'])} def clear_system_configuration(self): - self.wc.grab_json_response( - '/redfish/v1/Systems/1/Bios/Actions/Bios.ResetBios', - {'Action': 'Bios.ResetBios'}, - headers={'Authorization': 'Basic ' + base64.b64encode( - self.username + ':' + self.password), - 'Content-Type': 'application/json'}) + res = self.wc.grab_json_response( + '/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: + raise Exception( + 'Unexpected response to clear configuration: {0}'.format( + self.wc.lastjsonerror)) def get_webclient(self, login=True): cv = self.ipmicmd.certverify diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 18ddb83b..d833fca7 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -100,6 +100,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): **kwargs): if 'timeout' not in kwargs: kwargs['timeout'] = 60 + self.lastjsonerror = None self.broken = False self.thehost = host self.theport = port @@ -152,6 +153,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): return rsp def grab_json_response(self, url, data=None, referer=None, headers=None): + self.lastjsonerror = None webclient = self.dupe() if isinstance(data, dict): data = json.dumps(data) @@ -163,7 +165,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): rsp = webclient.getresponse() if rsp.status == 200: return json.loads(rsp.read()) - rsp.read() + self.lastjsonerror = rsp.read() return {} def download(self, url, file):