diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py index be606dcf31..2f301976c1 100644 --- a/swift/common/ring/builder.py +++ b/swift/common/ring/builder.py @@ -335,7 +335,7 @@ class RingBuilder(object): :raises RingValidationError: problem was found with the ring. """ - # "len" showed up in profling, so it's just computed once. + # "len" showed up in profiling, so it's just computed once. dev_len = len(self.devs) if sum(d['parts'] for d in self._iter_devs()) != \ self.parts * self.replicas: @@ -360,6 +360,12 @@ class RingBuilder(object): "to a device." % (part, replica)) + for dev in self._iter_devs(): + if not isinstance(dev['port'], int): + raise exceptions.RingValidationError( + "Device %d has port %r, which is not an integer." % + (dev['id'], dev['port'])) + if stats: weight_of_one_part = self.weight_of_one_part() worst = 0 diff --git a/test/unit/common/ring/test_builder.py b/test/unit/common/ring/test_builder.py index e9a1011ef1..6ffc2edc91 100644 --- a/test/unit/common/ring/test_builder.py +++ b/test/unit/common/ring/test_builder.py @@ -615,6 +615,11 @@ class TestRingBuilder(unittest.TestCase): self.assertRaises(exceptions.RingValidationError, rb.validate) rb.devs[1]['parts'] += 1 + # Test non-numeric port + rb.devs[1]['port'] = '10001' + self.assertRaises(exceptions.RingValidationError, rb.validate) + rb.devs[1]['port'] = 10001 + # Test partition on nonexistent device rb.pretend_min_part_hours_passed() orig_dev_id = rb._replica2part2dev[0][0]