check _last_part_moves when pretend_min_part_hours_passed

pretend_min_part_hours_passed do things like this:
self._last_part_moves[part] = 0xff

this will throw exception if self._last_part_moves is None.

this patch is to check self._last_part_moves to prevent exception.
Closes-bug: #1578835

Change-Id: Ic83c7a338b45bfcf61f5ab6100e6db335c3fa81a
This commit is contained in:
cheng 2016-07-25 13:23:04 +00:00
parent 574a666a43
commit c1c18da82c
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"]