]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/crash: parse both old and new timestamp formats
authorSage Weil <sage@redhat.com>
Tue, 30 Apr 2019 14:06:21 +0000 (09:06 -0500)
committerSage Weil <sage@redhat.com>
Wed, 29 May 2019 19:12:15 +0000 (14:12 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/crash/module.py

index 18aed3fba6282a6a4e7849951bd46b0164b36e87..cfaf1cc2a176dc30b7f513262ef411af9ba43613 100644 (file)
@@ -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 = [
         {