Merge "Make add_dev complain louder about missing keys"
This commit is contained in:
commit
a852397578
@ -367,6 +367,11 @@ class RingBuilder(object):
|
|||||||
# Add holes to self.devs to ensure self.devs[dev['id']] will be the dev
|
# Add holes to self.devs to ensure self.devs[dev['id']] will be the dev
|
||||||
while dev['id'] >= len(self.devs):
|
while dev['id'] >= len(self.devs):
|
||||||
self.devs.append(None)
|
self.devs.append(None)
|
||||||
|
required_keys = ('ip', 'port', 'weight')
|
||||||
|
if any(required not in dev for required in required_keys):
|
||||||
|
raise ValueError(
|
||||||
|
'%r is missing at least one the required key %r' % (
|
||||||
|
dev, required_keys))
|
||||||
dev['weight'] = float(dev['weight'])
|
dev['weight'] = float(dev['weight'])
|
||||||
dev['parts'] = 0
|
dev['parts'] = 0
|
||||||
self.devs[dev['id']] = dev
|
self.devs[dev['id']] = dev
|
||||||
@ -1657,9 +1662,7 @@ class RingBuilder(object):
|
|||||||
# NOTE(akscram): An old ring builder file don't contain
|
# NOTE(akscram): An old ring builder file don't contain
|
||||||
# replication parameters.
|
# replication parameters.
|
||||||
if dev:
|
if dev:
|
||||||
if 'ip' in dev:
|
|
||||||
dev.setdefault('replication_ip', dev['ip'])
|
dev.setdefault('replication_ip', dev['ip'])
|
||||||
if 'port' in dev:
|
|
||||||
dev.setdefault('replication_port', dev['port'])
|
dev.setdefault('replication_port', dev['port'])
|
||||||
return builder
|
return builder
|
||||||
|
|
||||||
|
@ -229,6 +229,13 @@ class TestRingBuilder(unittest.TestCase):
|
|||||||
'ip': '127.0.0.1', 'port': 6200})
|
'ip': '127.0.0.1', 'port': 6200})
|
||||||
self.assertEqual(rb.devs[1]['id'], 1)
|
self.assertEqual(rb.devs[1]['id'], 1)
|
||||||
self.assertEqual(dev_id, 1)
|
self.assertEqual(dev_id, 1)
|
||||||
|
# some keys are required
|
||||||
|
self.assertRaises(ValueError, rb.add_dev, {})
|
||||||
|
stub_dev = {'weight': 1, 'ip': '127.0.0.1', 'port': 7000}
|
||||||
|
for key in (stub_dev.keys()):
|
||||||
|
dev = stub_dev.copy()
|
||||||
|
dev.pop(key)
|
||||||
|
self.assertRaises(ValueError, rb.add_dev, dev)
|
||||||
|
|
||||||
def test_set_dev_weight(self):
|
def test_set_dev_weight(self):
|
||||||
rb = ring.RingBuilder(8, 3, 1)
|
rb = ring.RingBuilder(8, 3, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user