Ignore NotFound for external overlay networks

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-03-28 16:47:25 -07:00
parent 8d96980ba4
commit 344003a2f9
2 changed files with 25 additions and 0 deletions

View File

@ -42,6 +42,11 @@ class Network(object):
def ensure(self):
if self.external:
if self.driver == 'overlay':
# Swarm nodes do not register overlay networks that were
# created on a different node unless they're in use.
# See docker/compose#4399
return
try:
self.inspect()
log.debug(

View File

@ -1,7 +1,10 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from .testcases import DockerClientTestCase
from compose.config.errors import ConfigurationError
from compose.const import LABEL_NETWORK
from compose.const import LABEL_PROJECT
from compose.network import Network
@ -15,3 +18,20 @@ class NetworkTest(DockerClientTestCase):
labels = net_data['Labels']
assert labels[LABEL_NETWORK] == net.name
assert labels[LABEL_PROJECT] == net.project
def test_network_external_default_ensure(self):
net = Network(
self.client, 'composetest', 'foonet',
external=True
)
with pytest.raises(ConfigurationError):
net.ensure()
def test_network_external_overlay_ensure(self):
net = Network(
self.client, 'composetest', 'foonet',
driver='overlay', external=True
)
assert net.ensure() is None