From c8bb88056b47630b778b596b8c91a62fe610e1e7 Mon Sep 17 00:00:00 2001 From: Vitaliy Kharechko Date: Thu, 22 Sep 2016 14:59:24 +0300 Subject: [PATCH] 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 --- broadview_lib/pt/pt_parser.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/broadview_lib/pt/pt_parser.py b/broadview_lib/pt/pt_parser.py index ceeb75d..1b2371b 100644 --- a/broadview_lib/pt/pt_parser.py +++ b/broadview_lib/pt/pt_parser.py @@ -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