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

clayg already posted the code fix in the bug, but noted it needs a test.

Closes-Bug: #1487280
Change-Id: I07317754afac7165baac4e696f07daeba2e72adc
This commit is contained in:
Emile Snyder
2015-10-11 21:24:54 -07:00
parent 6b854bd908
commit 92767f28d6
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