Fix the behavior of swift-ring-builder list_parts before rebalance

The swift-ring-builder list_parts before rebalance failed abnormally so
this patch fix the behavior. After this patch applies the behavior is
completion normally with the following messages.

Specified builder file "<builder_file>" is not rebalanced yet.
Please rebalance first.

Closes-Bug: #1399529
Change-Id: I9e5db6da85de4188915c51bc401604733f0e1b77
This commit is contained in:
Hisashi Osanai 2014-12-05 23:43:52 +09:00
parent 96439301a2
commit d742b610df
2 changed files with 16 additions and 0 deletions
swift/cli
test/unit/cli

@ -328,6 +328,11 @@ swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
print parse_search_value.__doc__.strip()
exit(EXIT_ERROR)
if not builder._replica2part2dev:
print('Specified builder file \"%s\" is not rebalanced yet. '
'Please rebalance first.' % argv[1])
exit(EXIT_ERROR)
sorted_partition_count = find_parts(builder, argv)
if not sorted_partition_count:

@ -85,6 +85,17 @@ class TestCommands(unittest.TestCase):
self.assertEqual(ring.replicas, 3.14159265359)
self.assertEqual(ring.min_part_hours, 1)
def test_list_parts(self):
self.create_sample_ring()
argv = ["", self.tmpfile, "list_parts", "r1"]
err = None
try:
swift.cli.ringbuilder.main(argv)
except SystemExit as e:
err = e
self.assertEqual(err.code, 2)
def test_add_device(self):
self.create_sample_ring()
argv = ["", self.tmpfile, "add",