Add whitelisted driver option added by the overlay driver to avoid breakage

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2016-11-01 11:09:29 -07:00
parent e002171ab1
commit e6985de971
2 changed files with 68 additions and 0 deletions

View File

@ -12,6 +12,10 @@ from .config import ConfigurationError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
OPTS_EXCEPTIONS = [
'com.docker.network.driver.overlay.vxlanid_list',
]
class Network(object): class Network(object):
def __init__(self, client, project, name, driver=None, driver_opts=None, def __init__(self, client, project, name, driver=None, driver_opts=None,
@ -113,6 +117,23 @@ def create_ipam_config_from_dict(ipam_dict):
) )
def check_remote_network_config(remote, local):
if local.driver and remote['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())):
if k in OPTS_EXCEPTIONS:
continue
if remote['Options'].get(k) != local_opts.get(k):
raise ConfigurationError(
'Network "{}" needs to be recreated - options have changed'
.format(local.full_name)
)
def build_networks(name, config_data, client): def build_networks(name, config_data, client):
network_config = config_data.networks or {} network_config = config_data.networks or {}
networks = { networks = {

View File

@ -0,0 +1,47 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from .. import unittest
from compose.config import ConfigurationError
from compose.network import check_remote_network_config
from compose.network import Network
class NetworkTest(unittest.TestCase):
def test_check_remote_network_config_success(self):
options = {'com.docker.network.driver.foo': 'bar'}
net = Network(
None, 'compose_test', 'net1', 'bridge',
options
)
check_remote_network_config(
{'Driver': 'bridge', 'Options': options}, net
)
def test_check_remote_network_config_whitelist(self):
options = {'com.docker.network.driver.foo': 'bar'}
remote_options = {
'com.docker.network.driver.overlay.vxlanid_list': '257',
'com.docker.network.driver.foo': 'bar'
}
net = Network(
None, 'compose_test', 'net1', 'overlay',
options
)
check_remote_network_config(
{'Driver': 'overlay', 'Options': remote_options}, net
)
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)
def test_check_remote_network_config_options_mismatch(self):
net = Network(None, 'compose_test', 'net1', 'overlay')
with pytest.raises(ConfigurationError):
check_remote_network_config({'Driver': 'overlay', 'Options': {
'com.docker.network.driver.foo': 'baz'
}}, net)