Merge "Fix 'swift-ring-builder write_builder' after you remove a device"

This commit is contained in:
Jenkins 2015-10-13 00:04:25 +00:00 committed by Gerrit Code Review
commit 8cfe1b701a
2 changed files with 26 additions and 0 deletions

View File

@ -1005,6 +1005,8 @@ swift-ring-builder <ring_file> write_builder [min_part_hours]
min_part_hours = 24
ring = Ring(ring_file)
for dev in ring.devs:
if dev is None:
continue
dev.update({
'parts': 0,
'parts_wanted': 0,

View File

@ -1717,6 +1717,30 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
err = e
self.assertEqual(err.code, 2)
def test_write_builder_after_device_removal(self):
# Test regenerating builder file after having removed a device
# and lost the builder file
self.create_sample_ring()
argv = ["", self.tmpfile, "add", "r1z1-127.0.0.1:6000/sdb" "1.0"]
self.assertRaises(SystemExit, ringbuilder.main, argv)
argv = ["", self.tmpfile, "add", "r1z1-127.0.0.1:6000/sdc" "1.0"]
self.assertRaises(SystemExit, ringbuilder.main, argv)
argv = ["", self.tmpfile, "rebalance"]
self.assertRaises(SystemExit, ringbuilder.main, argv)
argv = ["", self.tmpfile, "remove", "--id", "0"]
self.assertRaises(SystemExit, ringbuilder.main, argv)
argv = ["", self.tmpfile, "rebalance"]
self.assertRaises(SystemExit, ringbuilder.main, argv)
backup_file = os.path.join(os.path.dirname(self.tmpfile),
os.path.basename(self.tmpfile) + ".ring.gz")
os.remove(self.tmpfile) # loses file...
argv = ["", backup_file, "write_builder"]
self.assertEqual(ringbuilder.main(argv), None)
def test_warn_at_risk(self):
# when the number of total part replicas (3 * 2 ** 4 = 48 in
# this ring) is less than the total units of weight (310 in this