diff --git a/swift/common/ring/ring.py b/swift/common/ring/ring.py index 99370fd284..68635acd67 100644 --- a/swift/common/ring/ring.py +++ b/swift/common/ring/ring.py @@ -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 diff --git a/test/unit/common/ring/test_builder.py b/test/unit/common/ring/test_builder.py index b9421b3043..6d96a321a1 100644 --- a/test/unit/common/ring/test_builder.py +++ b/test/unit/common/ring/test_builder.py @@ -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)'