From b2013e93c5cf92ba5ffea237e72f5eb5eafbdfd6 Mon Sep 17 00:00:00 2001
From: Jarrod Johnson <jjohnson2@lenovo.com>
Date: Wed, 12 Jun 2019 14:47:28 -0400
Subject: [PATCH] Mitigate performance impact of oem sensors

The sensormap was being regenerated each time a sensor
was asked for.  Make the sensor map
a more perisstent fixture.
---
 confluent_client/bin/nodelicense                      |  2 +-
 .../confluent/plugins/hardwaremanagement/ipmi.py      | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/confluent_client/bin/nodelicense b/confluent_client/bin/nodelicense
index 7ee8eaad..173e8149 100755
--- a/confluent_client/bin/nodelicense
+++ b/confluent_client/bin/nodelicense
@@ -59,7 +59,7 @@ def install_license(session, filename):
     instargs = {'filename': filename}
     for res in session.create(resource, instargs):
         pass # print(repr(res))
-    show_licenses()
+    show_licenses(session)
 
 def show_licenses(session):
     global exitcode
diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py
index 4ce08825..cc42590f 100644
--- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py
+++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py
@@ -171,6 +171,7 @@ class IpmiCommandWrapper(ipmicommand.Command):
     def __init__(self, node, cfm, **kwargs):
         self.cfm = cfm
         self.node = node
+        self.sensormap = {}
         self._inhealth = False
         self._lasthealth = None
         kwargs['keepalive'] = False
@@ -443,7 +444,6 @@ persistent_ipmicmds = {}
 class IpmiHandler(object):
     def __init__(self, operation, node, element, cfd, inputdata, cfg, output,
                  realop):
-        self.sensormap = {}
         self.invmap = {}
         self.output = output
         self.sensorcategory = None
@@ -800,7 +800,7 @@ class IpmiHandler(object):
             sensors = self.ipmicmd.get_sensor_descriptions()
         for sensor in sensors:
             resourcename = sensor['name']
-            self.sensormap[simplify_name(resourcename)] = resourcename
+            self.ipmicmd.sensormap[simplify_name(resourcename)] = resourcename
 
     def read_sensors(self, sensorname):
         if sensorname == 'all':
@@ -821,15 +821,16 @@ class IpmiHandler(object):
                 readings.append(reading)
             self.output.put(msg.SensorReadings(readings, name=self.node))
         else:
-            self.make_sensor_map()
-            if sensorname not in self.sensormap:
+            if sensorname not in self.ipmicmd.sensormap:
+                self.make_sensor_map()
+            if sensorname not in self.ipmicmd.sensormap:
                 self.output.put(
                     msg.ConfluentTargetNotFound(self.node,
                                                 'Sensor not found'))
                 return
             try:
                 reading = self.ipmicmd.get_sensor_reading(
-                    self.sensormap[sensorname])
+                    self.ipmicmd.sensormap[sensorname])
                 if hasattr(reading, 'health'):
                     reading.health = _str_health(reading.health)
                 self.output.put(