From 1c577fed15005c6ac6116009a5077d12b70d9386 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 2 Aug 2022 12:08:41 -0700 Subject: [PATCH] ring-builder: Better format large weights Previously, weights over 1000 would mess up the column alignment. Change-Id: I973ea5b083b34e40b5d61c4e548b6fe3db766dcc --- swift/cli/ringbuilder.py | 8 ++++++-- test/unit/cli/test_ipv6_output.stub | 10 +++++----- test/unit/cli/test_ringbuilder.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/swift/cli/ringbuilder.py b/swift/cli/ringbuilder.py index 1b99105788..5ab6a6f3aa 100644 --- a/swift/cli/ringbuilder.py +++ b/swift/cli/ringbuilder.py @@ -476,6 +476,7 @@ def _make_display_device_table(builder): rep_ip_width = 14 rep_port_width = 4 ip_ipv6 = rep_ipv6 = False + weight_width = 6 for dev in builder._iter_devs(): if is_valid_ipv6(dev['ip']): ip_ipv6 = True @@ -486,6 +487,8 @@ def _make_display_device_table(builder): port_width = max(len(str(dev['port'])), port_width) rep_port_width = max(len(str(dev['replication_port'])), rep_port_width) + weight_width = max(len('%6.02f' % dev['weight']), + weight_width) if ip_ipv6: ip_width += 2 if rep_ipv6: @@ -493,7 +496,7 @@ def _make_display_device_table(builder): header_line = ('Devices:%5s %6s %4s %' + str(ip_width) + 's:%-' + str(port_width) + 's %' + str(rep_ip_width) + 's:%-' + str(rep_port_width) + - 's %5s %6s %10s %7s %5s %s') % ( + 's %5s %' + str(weight_width) + 's %10s %7s %5s %s') % ( 'id', 'region', 'zone', 'ip address', 'port', 'replication ip', 'port', 'name', 'weight', 'partitions', 'balance', 'flags', @@ -511,7 +514,8 @@ def _make_display_device_table(builder): '%', str(ip_width), 's:%-', str(port_width), 'd ', '%', str(rep_ip_width), 's', ':%-', - str(rep_port_width), 'd %5s %6.02f' + str(rep_port_width), 'd %5s %', + str(weight_width), '.02f' ' %10s %7.02f %5s %s']) args = (dev['id'], dev['region'], dev['zone'], dev_ip, dev['port'], dev_replication_ip, dev['replication_port'], dev['device'], diff --git a/test/unit/cli/test_ipv6_output.stub b/test/unit/cli/test_ipv6_output.stub index 423b8fae16..30be348618 100644 --- a/test/unit/cli/test_ipv6_output.stub +++ b/test/unit/cli/test_ipv6_output.stub @@ -3,8 +3,8 @@ __RINGFILE__, build version 4, id __BUILDER_ID__ The minimum number of hours before a partition can be reassigned is 1 (0:00:00 remaining) The overload factor is 0.00% (0.000000) Ring file __RINGFILE__.ring.gz not found, probably it hasn't been written yet -Devices: id region zone ip address:port replication ip:port name weight partitions balance flags meta - 0 0 0 [2001:db8:85a3::8a2e:370:7334]:6200 [2001:db8:85a3::8a2e:370:7334]:6200 sda1 100.00 0 -100.00 some meta data - 1 1 1 127.0.0.1:66201 127.0.0.1:66201 sda2 100.00 0 -100.00 - 2 2 2 [2001:db8:85a3::8a2e:370:7336]:6202 127.0.10.127:7070 sdc3 100.00 0 -100.00 - 3 3 3 [2001:db8:85a3::8a2e:370:7337]:6203 [7001:db8:85a3::8a2e:370:7337]:11664 sdd4 100.00 0 -100.00 +Devices: id region zone ip address:port replication ip:port name weight partitions balance flags meta + 0 0 0 [2001:db8:85a3::8a2e:370:7334]:6200 [2001:db8:85a3::8a2e:370:7334]:6200 sda1 100.00 0 -100.00 some meta data + 1 1 1 127.0.0.1:66201 127.0.0.1:66201 sda2 100.00 0 -100.00 + 2 2 2 [2001:db8:85a3::8a2e:370:7336]:6202 127.0.10.127:7070 sdc3 10000.00 0 -100.00 + 3 3 3 [2001:db8:85a3::8a2e:370:7337]:6203 [7001:db8:85a3::8a2e:370:7337]:11664 sdd4 100.00 0 -100.00 diff --git a/test/unit/cli/test_ringbuilder.py b/test/unit/cli/test_ringbuilder.py index 6327c980e5..11a2d40ae8 100644 --- a/test/unit/cli/test_ringbuilder.py +++ b/test/unit/cli/test_ringbuilder.py @@ -2077,7 +2077,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin): 'port': 66201, 'device': 'sda2', }) - ring.add_dev({'weight': 100.0, + ring.add_dev({'weight': 10000.0, 'region': 2, 'zone': 2, 'ip': '2001:db8:85a3::8a2e:370:7336',