From bb9436aa2e7120767cfba12665083597092bf7f1 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 29 Feb 2016 12:51:48 -0500 Subject: [PATCH] Fix 'uptime' time correction attempt When doing the attempt to correct time, the sense of comparison was incorrect and the timestamp field was neglected. Correct this mistake and oversight. Change-Id: Ia3ff187d0eaedcfea9f3b7d2c8f292162bb3bb50 --- pyghmi/ipmi/events.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyghmi/ipmi/events.py b/pyghmi/ipmi/events.py index ed8f7002..1bf7e793 100644 --- a/pyghmi/ipmi/events.py +++ b/pyghmi/ipmi/events.py @@ -297,7 +297,7 @@ def _fix_sel_time(records, ipmicmd): correctearly = False inpreinit = False newtimestamp = 0 - lasttimestamp = 0 + lasttimestamp = None trimindexes = [] for index in reversed(xrange(len(records))): record = records[index] @@ -323,7 +323,8 @@ def _fix_sel_time(records, ipmicmd): if not correctearly: correctednowtime = nowtime continue - if record['timecode'] < lasttimestamp: + if (lasttimestamp is not None and + record['timecode'] > lasttimestamp): # Time has gone backwards in pre-init, no hope for # accurate time correctearly = False @@ -331,6 +332,9 @@ def _fix_sel_time(records, ipmicmd): continue inpreinit = True lasttimestamp = record['timecode'] + age = correctednowtime - record['timecode'] + record['timestamp'] = time.strftime( + '%Y-%m-%dT%H:%M:%S', time.localtime(time.time() - age)) else: # We are in 'normal' time, assume we cannot go to # pre-init time and do corrections unless time sync events @@ -464,7 +468,7 @@ class EventHandler(object): def _decode_standard_event(self, eventdata, event): # Ignore the generator id for now.. - if eventdata[2] != 4: + if eventdata[2] not in (3, 4): raise pygexc.PyghmiException( 'Unrecognized Event message version {0}'.format(eventdata[2])) sensor_type = eventdata[3]