From 9d5e570f0e22675ef30368a3de58533c57ee5026 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 22 Nov 2019 08:45:26 -0500 Subject: [PATCH] Check HTTP viability before use If the session is dead, have the wc property function discard and re-establish the connection, rather than passing the useless stale session to the caller. Change-Id: I701c396ac9eedc1749b13c196e19fb1c4e996001 --- pyghmi/redfish/oem/lenovo/tsma.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyghmi/redfish/oem/lenovo/tsma.py b/pyghmi/redfish/oem/lenovo/tsma.py index 37285d49..ecbabb79 100644 --- a/pyghmi/redfish/oem/lenovo/tsma.py +++ b/pyghmi/redfish/oem/lenovo/tsma.py @@ -77,7 +77,6 @@ class TsmHandler(generic.OEMHandler): self._wc = None self.username = None self.password = None - self._wc = None self.csrftok = None self.fish = fish super(TsmHandler, self).__init__(sysinfo, sysurl, webclient, cache) @@ -132,7 +131,9 @@ class TsmHandler(generic.OEMHandler): def wc(self): self.fwid = None if self._wc: - return self._wc + rsp, status = self._wc.grab_json_response_with_status('/api/chassis-status') + if status == 200: + return self._wc authdata = { 'username': self.username, 'password': self.password, @@ -342,4 +343,5 @@ class TsmHandler(generic.OEMHandler): hdrs = wc.stdheaders.copy() hdrs['Content-Length'] = 0 rsp = wc.grab_json_response_with_status('/api/maintenance/reset', method='POST', headers=hdrs) + self._wc = None return 'complete'