From d026898b2f35c508988a61740bb222d46e8c661e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 29 Mar 2018 09:06:47 -0400 Subject: [PATCH] Improve performance of get_health for XCC Provide a quicker health assessment for XCC. Generally provide a way for OEMs to replace or augment or conditionally replace the generic behavior. Change-Id: I54c9b9a91aabd6025d17d65846be164b87694019 --- pyghmi/exceptions.py | 6 ++++++ pyghmi/ipmi/command.py | 13 +++++++++---- pyghmi/ipmi/oem/generic.py | 13 +++++++++++++ pyghmi/ipmi/oem/lenovo/handler.py | 5 +++++ pyghmi/ipmi/oem/lenovo/imm.py | 12 +++++++++++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/pyghmi/exceptions.py b/pyghmi/exceptions.py index 8de693f5..2818b6a9 100644 --- a/pyghmi/exceptions.py +++ b/pyghmi/exceptions.py @@ -54,3 +54,9 @@ class UnsupportedFunctionality(PyghmiException): # Indicates when functionality is requested that is not supported by # current endpoint pass + + +class BypassGenericBehavior(PyghmiException): + # Indicates that an OEM handler wants to abort any standards based + # follow up + pass diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 0c897c67..ffc25c72 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -657,10 +657,15 @@ class Command(object): warning, critical, or failed assessments. """ summary = {'badreadings': [], 'health': const.Health.Ok} - for reading in self.get_sensor_data(): - if reading.health != const.Health.Ok: - summary['health'] |= reading.health - summary['badreadings'].append(reading) + try: + self.oem_init() + self._oem.get_health(summary) + for reading in self.get_sensor_data(): + if reading.health != const.Health.Ok: + summary['health'] |= reading.health + summary['badreadings'].append(reading) + except exc.BypassGenericBehavior: + pass return summary def get_sensor_reading(self, sensorname): diff --git a/pyghmi/ipmi/oem/generic.py b/pyghmi/ipmi/oem/generic.py index cbdbde16..b0fea2fc 100644 --- a/pyghmi/ipmi/oem/generic.py +++ b/pyghmi/ipmi/oem/generic.py @@ -265,6 +265,19 @@ class OEMHandler(object): """ raise exc.UnsupportedFunctionality() + def get_health(self, summary): + """Provide an alternative or augmented health assessment + + An OEM handler can preprocess the summary and extend it with OEM + specific data, and then return to let generic processing occur. + It can also raise the pyghmi exception BypassGenericBehavior to + suppress the standards based routine, for enhanced performance. + + :param summary: The health summary as prepared by the generic function + :return: Nothing, modifies the summary object + """ + return + def set_alert_ipv6_destination(self, ip, destination, channel): """Set an IPv6 alert destination diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index bc28f900..6e853215 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -923,3 +923,8 @@ class OEMHandler(generic.OEMHandler): if self.has_xcc: return self.immhandler.list_media() return super(OEMHandler, self).list_media() + + def get_health(self, summary): + if self.has_xcc: + return self.immhandler.get_health(summary) + return super(OEMHandler, self).get_health(summary) diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index 93787b0c..a654b367 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -569,7 +569,7 @@ class XCCClient(IMMClient): super(XCCClient, self).__init__(ipmicmd) self.adp_referer = None - def get_webclient(self): + def get_webclient(self, login=True): cv = self.ipmicmd.certverify wc = webclient.SecureHTTPConnection(self.imm, 443, verifycallback=cv) try: @@ -578,6 +578,8 @@ class XCCClient(IMMClient): if se.errno != errno.ECONNREFUSED: raise return None + if not login: + return wc adata = json.dumps({'username': self.username, 'password': self.password }) @@ -1251,3 +1253,11 @@ class XCCClient(IMMClient): if bank == 'backup': return 'complete' return 'pending' + + def get_health(self, summary): + wc = self.get_webclient(False) + rsp = wc.grab_json_response('/api/providers/imm_active_events') + if 'items' in rsp and len(rsp['items']) == 0: + # The XCC reports healthy, no need to interrogate + raise pygexc.BypassGenericBehavior() + # Will use the generic handling for unhealthy systems