From a3d4c42c5d5b8629268ef7e64e108fdb3aebe677 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 11 Apr 2014 16:42:25 -0400 Subject: [PATCH] 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 --- pyghmi/ipmi/sdr.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pyghmi/ipmi/sdr.py b/pyghmi/ipmi/sdr.py index 0f30fbf3..8dffe5d9 100644 --- a/pyghmi/ipmi/sdr.py +++ b/pyghmi/ipmi/sdr.py @@ -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)