mirror of https://github.com/docker/compose.git
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:
parent
e002171ab1
commit
e6985de971
|
@ -12,6 +12,10 @@ from .config import ConfigurationError
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
OPTS_EXCEPTIONS = [
|
||||
'com.docker.network.driver.overlay.vxlanid_list',
|
||||
]
|
||||
|
||||
|
||||
class Network(object):
|
||||
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):
|
||||
network_config = config_data.networks or {}
|
||||
networks = {
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue