Merge pull request #4134 from shin-/fix_none_opts_network_check

Avoid breaking when remote driver options are null
This commit is contained in:
Joffrey F 2016-11-15 15:01:24 -08:00 committed by GitHub
commit 721bf89447
2 changed files with 13 additions and 4 deletions

View File

@ -111,16 +111,17 @@ def create_ipam_config_from_dict(ipam_dict):
def check_remote_network_config(remote, local):
if local.driver and remote['Driver'] != local.driver:
if local.driver and remote.get('Driver') != local.driver:
raise ConfigurationError(
'Network "{}" needs to be recreated - driver has changed'
.format(local.full_name)
)
local_opts = local.driver_opts or {}
for k in set.union(set(remote['Options'].keys()), set(local_opts.keys())):
remote_opts = remote.get('Options') or {}
for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
if k in OPTS_EXCEPTIONS:
continue
if remote['Options'].get(k) != local_opts.get(k):
if remote_opts.get(k) != local_opts.get(k):
raise ConfigurationError(
'Network "{}" needs to be recreated - options have changed'
.format(local.full_name)

View File

@ -37,7 +37,9 @@ class NetworkTest(unittest.TestCase):
def test_check_remote_network_config_driver_mismatch(self):
net = Network(None, 'compose_test', 'net1', 'overlay')
with pytest.raises(ConfigurationError):
check_remote_network_config({'Driver': 'bridge', 'Options': {}}, net)
check_remote_network_config(
{'Driver': 'bridge', 'Options': {}}, net
)
def test_check_remote_network_config_options_mismatch(self):
net = Network(None, 'compose_test', 'net1', 'overlay')
@ -45,3 +47,9 @@ class NetworkTest(unittest.TestCase):
check_remote_network_config({'Driver': 'overlay', 'Options': {
'com.docker.network.driver.foo': 'baz'
}}, net)
def test_check_remote_network_config_null_remote(self):
net = Network(None, 'compose_test', 'net1', 'overlay')
check_remote_network_config(
{'Driver': 'overlay', 'Options': None}, net
)