]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: sort and align output
authorTheofilos Mouratidis <t.mour@cern.ch>
Fri, 4 May 2018 09:37:18 +0000 (11:37 +0200)
committerJan Fajerski <jfajerski@suse.com>
Fri, 28 Feb 2020 10:50:00 +0000 (11:50 +0100)
This commit targets the `ceph-volume lvm list` command.
The output is sorted by the osd id and each device's
attributed are sorted, so the ceph operators can find
relevant information easier. The devices (block,db,..etc)
are now properly aligned.

Signed-off-by: Theofilos Mouratidis <t.mour@cern.ch>
(cherry picked from commit 209afb54ad1812f2b380081de8ae92f37e953623)

src/ceph-volume/ceph_volume/devices/lvm/listing.py
src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py

index 798d6df40b3ca259bc6d8c4849c98bb47ec0a55b..a3824423c35eca6becbe9481cd138f9a46666bd6 100644 (file)
@@ -18,7 +18,7 @@ osd_list_header_template = """\n
 
 osd_device_header_template = """
 
-  [{type: >4}]    {path}
+  {type: <13} {path}
 """
 
 device_metadata_item_template = """
@@ -32,18 +32,18 @@ def readable_tag(tag):
 
 def pretty_report(report):
     output = []
-    for _id, devices in report.items():
+    for _id, devices in sorted(report.items()):
         output.append(
             osd_list_header_template.format(osd_id=" osd.%s " % _id)
         )
         for device in devices:
             output.append(
                 osd_device_header_template.format(
-                    type=device['type'],
+                    type='[%s]' % device['type'],
                     path=device['path']
                 )
             )
-            for tag_name, value in device.get('tags', {}).items():
+            for tag_name, value in sorted(device.get('tags', {}).items()):
                 output.append(
                     device_metadata_item_template.format(
                         tag_name=readable_tag(tag_name),
@@ -193,7 +193,6 @@ class List(object):
 
         # TODO: a call to full_report just might work.
         if lv:
-
             try:
                 _id = lv.tags['ceph.osd_id']
             except KeyError:
index 5c0fec75611b32197c48b6fe3f5faeba207aaaf2..efbb460f96033e46acc72885d9e6e2cf0c4afe01 100644 (file)
@@ -26,7 +26,7 @@ class TestPrettyReport(object):
             {'type': 'data', 'path': '/dev/sda1', 'devices': ['/dev/sda']}
         ]})
         stdout, stderr = capsys.readouterr()
-        assert '[data]    /dev/sda1' in stdout
+        assert '[data]        /dev/sda1' in stdout
 
     def test_osd_id_header_is_reported(self, capsys):
         lvm.listing.pretty_report({0: [