From c9052f665cb92d63ef30c989a939d9dd7c7e878d Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 12 Mar 2021 11:08:08 -0800 Subject: [PATCH] Change alignment on `compact` output Change-Id: I4735c725ad152ca5bed3f64decc101a9fb034469 --- swift/cli/manage_shard_ranges.py | 4 +- test/unit/cli/test_manage_shard_ranges.py | 48 +++++++++++++++++------ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/swift/cli/manage_shard_ranges.py b/swift/cli/manage_shard_ranges.py index 6599c7daa5..30d510fb22 100644 --- a/swift/cli/manage_shard_ranges.py +++ b/swift/cli/manage_shard_ranges.py @@ -182,9 +182,9 @@ DEFAULT_SHRINK_THRESHOLD = DEFAULT_SHARD_CONTAINER_THRESHOLD * \ def _print_shard_range(sr, level=0): indent = ' ' * level print(indent + '%r' % sr.name) - print(indent + ' objects: %-9d lower: %r' % (sr.object_count, + print(indent + ' objects: %9d lower: %r' % (sr.object_count, sr.lower_str)) - print(indent + ' state: %-9s upper: %r' % (sr.state_text, sr.upper_str)) + print(indent + ' state: %9s upper: %r' % (sr.state_text, sr.upper_str)) def _load_and_validate_shard_data(args): diff --git a/test/unit/cli/test_manage_shard_ranges.py b/test/unit/cli/test_manage_shard_ranges.py index 2f66f32605..d2bedaaf22 100644 --- a/test/unit/cli/test_manage_shard_ranges.py +++ b/test/unit/cli/test_manage_shard_ranges.py @@ -693,17 +693,43 @@ class TestManageShardRanges(unittest.TestCase): err_lines = err.getvalue().split('\n') self.assert_starts_with(err_lines[0], 'Loaded db broker for ') out_lines = out.getvalue().split('\n') - self.assertIn('total of 20 objects', out_lines[0]) - self.assertIn('.shards_a', out_lines[1]) - self.assertIn('objects: 10', out_lines[2]) - self.assertIn('state: active', out_lines[3]) - self.assertIn('.shards_a', out_lines[4]) - self.assertIn('objects: 10', out_lines[5]) - self.assertIn('state: active', out_lines[6]) - self.assertIn('can be compacted into', out_lines[7]) - self.assertIn('.shards_a', out_lines[8]) - self.assertIn('objects: 10', out_lines[9]) - self.assertIn('state: active', out_lines[10]) + expected = [ + 'Donor shard range(s) with total of 20 objects:', + " '.shards_a", + " objects: 10 lower: 'obj29'", + " state: active upper: 'obj39'", + " '.shards_a", + " objects: 10 lower: 'obj39'", + " state: active upper: 'obj49'", + 'can be compacted into acceptor shard range:', + " '.shards_a", + " objects: 100001 lower: 'obj49'", + " state: active upper: 'obj59'", + 'Donor shard range(s) with total of 10 objects:', + " '.shards_a", + " objects: 10 lower: 'obj69'", + " state: active upper: 'obj79'", + 'can be compacted into acceptor shard range:', + " '.shards_a", + " objects: 100001 lower: 'obj79'", + " state: active upper: 'obj89'", + 'Once applied to the broker these changes will result in ' + 'shard range compaction the next time the sharder runs.', + ] + if user_input == 'y': + expected.extend([ + 'Updated 2 shard sequences for compaction.', + 'Run container-replicator to replicate the changes to ' + 'other nodes.', + 'Run container-sharder on all nodes to compact shards.', + '', + ]) + else: + expected.extend([ + 'No changes applied', + '', + ]) + self.assertEqual(expected, [l.split('/', 1)[0] for l in out_lines]) return broker.get_shard_ranges() broker_ranges = do_compact('n')