diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py index 43185789a6..1ac41594c5 100644 --- a/swift/common/ring/builder.py +++ b/swift/common/ring/builder.py @@ -937,6 +937,8 @@ class RingBuilder(object): Deliberately includes duplicates. """ + if self._replica2part2dev is None: + return [] return [self.devs[part2dev[part]] for part2dev in self._replica2part2dev if part < len(part2dev)] diff --git a/test/unit/common/ring/test_builder.py b/test/unit/common/ring/test_builder.py index 5a1d4faf10..d9007fb5ba 100644 --- a/test/unit/common/ring/test_builder.py +++ b/test/unit/common/ring/test_builder.py @@ -797,6 +797,8 @@ class TestRingBuilder(unittest.TestCase): def test_get_part_devices(self): rb = ring.RingBuilder(8, 3, 1) + self.assertEqual(rb.get_part_devices(0), []) + rb.add_dev({'id': 0, 'region': 0, 'zone': 0, 'weight': 1, 'ip': '127.0.0.1', 'port': 10000, 'device': 'sda1'}) rb.add_dev({'id': 1, 'region': 0, 'zone': 1, 'weight': 1,