ring: Prevent IndexErrors in calc_replica_count

Change-Id: Ibdf85fd80ba4c1bc216153a2f5fa4d7b6d9b432e
This commit is contained in:
Tim Burke 2021-01-22 14:06:02 -08:00
parent 48b26ba833
commit 967c9c6962
2 changed files with 7 additions and 0 deletions

View File

@ -36,6 +36,8 @@ from swift.common.ring.utils import tiers_for_dev
def calc_replica_count(replica2part2dev_id):
if not replica2part2dev_id:
return 0
base = len(replica2part2dev_id) - 1
extra = 1.0 * len(replica2part2dev_id[-1]) / len(replica2part2dev_id[0])
return base + extra

View File

@ -73,6 +73,11 @@ class TestRingBuilder(unittest.TestCase):
self.assertFalse(rb.devs_changed)
self.assertEqual(rb.version, 0)
self.assertIsNotNone(rb._last_part_moves)
rd = rb.get_ring()
self.assertEqual(rd.devs, [])
self.assertEqual(rd.version, 0)
self.assertIsNone(rd.next_part_power)
self.assertEqual(rd.replica_count, 0)
def test_overlarge_part_powers(self):
expected_msg = 'part_power must be at most 32 (was 33)'