]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/crash: make 'crash ls' a nice table with a NEW column
authorSage Weil <sage@redhat.com>
Fri, 12 Jul 2019 21:34:37 +0000 (16:34 -0500)
committerSage Weil <sage@redhat.com>
Fri, 19 Jul 2019 14:43:04 +0000 (09:43 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
qa/workunits/rados/test_crash.sh
src/pybind/mgr/crash/module.py

index 6e7aaaaba63485b311887be2617b958e1518524a..04597c195375358e3c87e1e12fc768c2957c01b3 100755 (executable)
@@ -29,5 +29,5 @@ sudo systemctl restart ceph-crash
 sleep 30
 
 # must be 3 crashdumps registered and moved to crash/posted
-[ $(ceph crash ls | wc -l) = 3 ]  || exit 1
+[ $(ceph crash ls | wc -l) = 4 ]  || exit 1   # 4 here bc of the table header
 [ $(sudo find /var/lib/ceph/crash/posted/ -name meta | wc -l) = 3 ] || exit 1
index df2771bf156ac6accc72006904d4fb5501df1f6c..df298fbc50626ad389062704891847bef48df416 100644 (file)
@@ -4,6 +4,7 @@ import errno
 import json
 import six
 from collections import defaultdict
+from prettytable import PrettyTable
 
 
 DATEFMT = '%Y-%m-%dT%H:%M:%S.%f'
@@ -83,12 +84,23 @@ class Module(MgrModule):
         return 0, '', ''
 
     def do_ls(self, cmd, inbuf):
-        keys = []
+        r = []
         for k, meta in self.timestamp_filter(lambda ts: True):
-            entity_name = meta.get('entity_name', 'unknown')
-            keys.append("%s %s" % (k.replace('crash/', ''), entity_name))
-        keys.sort()
-        return 0, '\n'.join(keys), ''
+            r.append(meta)
+        if cmd.get('format') == 'json' or cmd.get('format') == 'json-pretty':
+            return 0, json.dumps(r, indent=4), ''
+        else:
+            table = PrettyTable(['ID', 'ENTITY', 'NEW'],
+                                border=False)
+            table.left_padding_width = 0
+            table.right_padding_width = 1
+            table.align['ID'] = 'l'
+            table.align['ENTITY'] = 'l'
+            for c in r:
+                table.add_row([c.get('crash_id'),
+                               c.get('entity_name','unknown'),
+                               '' if 'archived' in c else '*'])
+            return 0, table.get_string(), ''
 
     def do_rm(self, cmd, inbuf):
         crashid = cmd['id']