From 209afb54ad1812f2b380081de8ae92f37e953623 Mon Sep 17 00:00:00 2001 From: Theofilos Mouratidis Date: Fri, 4 May 2018 11:37:18 +0200 Subject: [PATCH] ceph-volume: sort and align output 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 --- src/ceph-volume/ceph_volume/devices/lvm/listing.py | 9 ++++----- .../ceph_volume/tests/devices/lvm/test_listing.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ceph-volume/ceph_volume/devices/lvm/listing.py b/src/ceph-volume/ceph_volume/devices/lvm/listing.py index a84a39c182a51..6bc84a16864ee 100644 --- a/src/ceph-volume/ceph_volume/devices/lvm/listing.py +++ b/src/ceph-volume/ceph_volume/devices/lvm/listing.py @@ -17,7 +17,7 @@ osd_list_header_template = """\n osd_device_header_template = """ - [{type: >4}] {path} + {type: <13} {path} """ device_metadata_item_template = """ @@ -31,18 +31,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), @@ -179,7 +179,6 @@ class List(object): return self.full_report(lvs=lvs) if lv: - try: _id = lv.tags['ceph.osd_id'] except KeyError: diff --git a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py index a49a3e9e6a08f..fba7d73e135d3 100644 --- a/src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py +++ b/src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py @@ -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: [ -- 2.39.5