2
0
mirror of https://opendev.org/x/pyghmi synced 2025-02-20 12:30:48 +00:00

Gracefully flag unrecognized discrete sensor states

Previously, pyghmi would incur a KeyError in the event of
something like sensor specific event not in the lookup tables.
Fix this by catching the error and putting in generic description
of state and flagging as 'warning'.  This sort of warning suggests
a bug in pyghmi that pyghmi needs to have its event descriptions
updated.

Change-Id: Ia5f4645e30a341a93456dae2b8d75d9fda542e1b
This commit is contained in:
Jarrod Johnson 2014-04-11 16:42:25 -04:00
parent 09f2b13793
commit a3d4c42c5d

View File

@ -368,15 +368,20 @@ class SDREntry(object):
def _decode_state(self, state):
mapping = ipmiconst.discrete_type_offsets
if self.reading_type in mapping:
desc = mapping[self.reading_type][state]['desc']
health = mapping[self.reading_type][state]['severity']
elif self.reading_type == 0x6f:
mapping = ipmiconst.sensor_type_offsets
desc = mapping[self.sensor_type_number][state]['desc']
health = mapping[self.sensor_type_number][state]['severity']
else:
desc = "Unknown state %d" % state
try:
if self.reading_type in mapping:
desc = mapping[self.reading_type][state]['desc']
health = mapping[self.reading_type][state]['severity']
elif self.reading_type == 0x6f:
mapping = ipmiconst.sensor_type_offsets
desc = mapping[self.sensor_type_number][state]['desc']
health = mapping[self.sensor_type_number][state]['severity']
else:
desc = "Unknown state %d" % state
health = const.Health.Warning
except KeyError:
desc = "Unknown state %d for reading type %d/sensor type %d" % (
state, self.reading_type, self.sensor_type_number)
health = const.Health.Warning
return (desc, health)