Agent can send PT notification with timestamp set to epoch, even if NOS clock is set. Detect this and set to current time

Change-Id: Ia4adda59e09c4913b2870eb611219a52360d2082
This commit is contained in:
Vitaliy Kharechko 2016-09-22 14:59:24 +03:00
parent a72b75082e
commit c8bb88056b
1 changed files with 9 additions and 1 deletions

View File

@ -221,9 +221,17 @@ class PTParser():
if ret:
self.__asicId = data["asic-id"]
if "time-stamp" in data:
epoch = time.gmtime(0)
x = data["time-stamp"].strip()
try:
self.__timestamp = time.strptime(x, "%Y-%m-%d - %H:%M:%S")
ts = time.strptime(x, "%Y-%m-%d - %H:%M:%S")
# bug: agent can send epoch here, so try and detect
# sending epoch causes issues for ceilometer and maybe
# others. It's enough that the years match on this
if ts.tm_year == epoch.tm_year:
self.__timestamp = time.localtime()
else:
self.__timestamp = ts
except:
ret = False