Merge "check _last_part_moves when pretend_min_part_hours_passed"

This commit is contained in:
Jenkins 2016-08-05 14:56:09 +00:00 committed by Gerrit Code Review
commit e42567f14f
2 changed files with 20 additions and 1 deletions

View File

@ -741,9 +741,11 @@ class RingBuilder(object):
255 hours ago and last move epoch to 'the beginning of time'. This can
be used to force a full rebalance on the next call to rebalance.
"""
self._last_part_moves_epoch = 0
if not self._last_part_moves:
return
for part in range(self.parts):
self._last_part_moves[part] = 0xff
self._last_part_moves_epoch = 0
def get_part_devices(self, part):
"""

View File

@ -1718,6 +1718,23 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
ring_invalid_re = re.compile("Ring file .*\.ring\.gz is invalid")
self.assertTrue(ring_invalid_re.findall(mock_stdout.getvalue()))
def test_pretend_min_part_hours_passed(self):
self.run_srb("create", 8, 3, 1)
argv_pretend = ["", self.tmpfile, "pretend_min_part_hours_passed"]
# pretend_min_part_hours_passed should success, even not rebalanced
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv_pretend)
self.run_srb("add",
"r1z1-10.1.1.1:2345/sda", 100.0,
"r1z1-10.1.1.1:2345/sdb", 100.0,
"r1z1-10.1.1.1:2345/sdc", 100.0)
argv_rebalance = ["", self.tmpfile, "rebalance"]
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv_rebalance)
self.run_srb("add", "r1z1-10.1.1.1:2345/sdd", 100.0)
# rebalance fail without pretend_min_part_hours_passed
self.assertSystemExit(EXIT_WARNING, ringbuilder.main, argv_rebalance)
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv_pretend)
self.assertSystemExit(EXIT_SUCCESS, ringbuilder.main, argv_rebalance)
def test_rebalance(self):
self.create_sample_ring()
argv = ["", self.tmpfile, "rebalance", "3"]