Merge "ring-builder: Better format large weights"

This commit is contained in:
Zuul 2022-08-05 18:49:26 +00:00 committed by Gerrit Code Review
commit 0c8c36b3fa
3 changed files with 12 additions and 8 deletions

View File

@ -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'],

View File

@ -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

View File

@ -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',