Merge "ring: Prevent IndexErrors in calc_replica_count"

This commit is contained in:
Zuul 2021-02-11 02:22:33 +00:00 committed by Gerrit Code Review
commit c646b51e9f
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)'