From: Sage Weil Date: Tue, 30 Apr 2019 14:06:21 +0000 (-0500) Subject: mgr/crash: parse both old and new timestamp formats X-Git-Tag: v15.1.0~2616^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b02318f6b9d39251090414fa658bb798032f1d9;p=ceph.git mgr/crash: parse both old and new timestamp formats Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/crash/module.py b/src/pybind/mgr/crash/module.py index 18aed3fba628..cfaf1cc2a176 100644 --- a/src/pybind/mgr/crash/module.py +++ b/src/pybind/mgr/crash/module.py @@ -6,7 +6,8 @@ import six from collections import defaultdict -DATEFMT = '%Y-%m-%d %H:%M:%S.%f' +DATEFMT = '%Y-%m-%dT%H:%M:%S.%f' +OLD_DATEFMT = '%Y-%m-%d %H:%M:%S.%f' class Module(MgrModule): @@ -36,7 +37,10 @@ class Module(MgrModule): def time_from_string(timestr): # drop the 'Z' timezone indication, it's always UTC timestr = timestr.rstrip('Z') - return datetime.datetime.strptime(timestr, DATEFMT) + try: + return datetime.datetime.strptime(timestr, DATEFMT) + except ValueError: + return datetime.datetime.strptime(timestr, OLD_DATEFMT) def timestamp_filter(self, f): """ @@ -171,10 +175,14 @@ class Module(MgrModule): def self_test(self): # test time conversion - timestr = '2018-06-22 20:35:38.058818Z' + timestr = '2018-06-22T20:35:38.058818Z' + old_timestr = '2018-06-22 20:35:38.058818Z' dt = self.time_from_string(timestr) if dt != datetime.datetime(2018, 6, 22, 20, 35, 38, 58818): raise RuntimeError('time_from_string() failed') + dt = self.time_from_string(old_timestr) + if dt != datetime.datetime(2018, 6, 22, 20, 35, 38, 58818): + raise RuntimeError('time_from_string() (old) failed') COMMANDS = [ {