Avoid breaking when remote driver options are null.

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-11-09 15:38:09 -08:00
parent 7e40754ffc
commit efda1efffe
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): 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( raise ConfigurationError(
'Network "{}" needs to be recreated - driver has changed' 'Network "{}" needs to be recreated - driver has changed'
.format(local.full_name) .format(local.full_name)
) )
local_opts = local.driver_opts or {} 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: if k in OPTS_EXCEPTIONS:
continue continue
if remote['Options'].get(k) != local_opts.get(k): if remote_opts.get(k) != local_opts.get(k):
raise ConfigurationError( raise ConfigurationError(
'Network "{}" needs to be recreated - options have changed' 'Network "{}" needs to be recreated - options have changed'
.format(local.full_name) .format(local.full_name)

View File

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