mirror of https://github.com/docker/compose.git
Merge pull request #4770 from shin-/4767-check_ipam_nonetype
Prevent NoneType error when remote IPAM options is None
This commit is contained in:
commit
d9902e89df
|
@ -158,8 +158,8 @@ def check_remote_ipam_config(remote, local):
|
||||||
if sorted(lc.get('AuxiliaryAddresses')) != sorted(rc.get('AuxiliaryAddresses')):
|
if sorted(lc.get('AuxiliaryAddresses')) != sorted(rc.get('AuxiliaryAddresses')):
|
||||||
raise NetworkConfigChangedError(local.full_name, 'IPAM config aux_addresses')
|
raise NetworkConfigChangedError(local.full_name, 'IPAM config aux_addresses')
|
||||||
|
|
||||||
remote_opts = remote_ipam.get('Options', {})
|
remote_opts = remote_ipam.get('Options') or {}
|
||||||
local_opts = local.ipam.get('options', {})
|
local_opts = local.ipam.get('options') or {}
|
||||||
for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
|
for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
|
||||||
if remote_opts.get(k) != local_opts.get(k):
|
if remote_opts.get(k) != local_opts.get(k):
|
||||||
raise NetworkConfigChangedError(local.full_name, 'IPAM option "{}"'.format(k))
|
raise NetworkConfigChangedError(local.full_name, 'IPAM option "{}"'.format(k))
|
||||||
|
|
|
@ -100,6 +100,44 @@ class NetworkTest(unittest.TestCase):
|
||||||
{'Driver': 'overlay', 'Options': None}, net
|
{'Driver': 'overlay', 'Options': None}, net
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_check_remote_network_config_null_remote_ipam_options(self):
|
||||||
|
ipam_config = {
|
||||||
|
'driver': 'default',
|
||||||
|
'config': [
|
||||||
|
{'subnet': '172.0.0.1/16', },
|
||||||
|
{
|
||||||
|
'subnet': '156.0.0.1/25',
|
||||||
|
'gateway': '156.0.0.1',
|
||||||
|
'aux_addresses': ['11.0.0.1', '24.25.26.27'],
|
||||||
|
'ip_range': '156.0.0.1-254'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
net = Network(
|
||||||
|
None, 'compose_test', 'net1', 'bridge', ipam=ipam_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
check_remote_network_config(
|
||||||
|
{
|
||||||
|
'Driver': 'bridge',
|
||||||
|
'Attachable': True,
|
||||||
|
'IPAM': {
|
||||||
|
'Driver': 'default',
|
||||||
|
'Config': [{
|
||||||
|
'Subnet': '156.0.0.1/25',
|
||||||
|
'Gateway': '156.0.0.1',
|
||||||
|
'AuxiliaryAddresses': ['24.25.26.27', '11.0.0.1'],
|
||||||
|
'IPRange': '156.0.0.1-254'
|
||||||
|
}, {
|
||||||
|
'Subnet': '172.0.0.1/16',
|
||||||
|
'Gateway': '172.0.0.1'
|
||||||
|
}],
|
||||||
|
'Options': None
|
||||||
|
},
|
||||||
|
},
|
||||||
|
net
|
||||||
|
)
|
||||||
|
|
||||||
def test_check_remote_network_labels_mismatch(self):
|
def test_check_remote_network_labels_mismatch(self):
|
||||||
net = Network(None, 'compose_test', 'net1', 'overlay', labels={
|
net = Network(None, 'compose_test', 'net1', 'overlay', labels={
|
||||||
'com.project.touhou.character': 'sakuya.izayoi'
|
'com.project.touhou.character': 'sakuya.izayoi'
|
||||||
|
|
Loading…
Reference in New Issue