If -x-networking is used, set the correct API version.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-10-14 12:09:50 -04:00
parent d5f5eb1924
commit e2f792c4f4
3 changed files with 18 additions and 9 deletions

View File

@ -67,8 +67,8 @@ def get_config_path(file_option):
return [config_file] if config_file else None
def get_client(verbose=False):
client = docker_client()
def get_client(verbose=False, version=None):
client = docker_client(version=version)
if verbose:
version_info = six.iteritems(client.version())
log.info("Compose version %s", __version__)
@ -83,11 +83,12 @@ def get_project(base_dir, config_path=None, project_name=None, verbose=False,
use_networking=False, network_driver=None):
config_details = config.find(base_dir, config_path)
api_version = '1.21' if use_networking else None
try:
return Project.from_dicts(
get_project_name(config_details.working_dir, project_name),
config.load(config_details),
get_client(verbose=verbose),
get_client(verbose=verbose, version=api_version),
use_networking=use_networking,
network_driver=network_driver,
)

View File

@ -9,7 +9,10 @@ from ..const import HTTP_TIMEOUT
log = logging.getLogger(__name__)
def docker_client():
DEFAULT_API_VERSION = '1.19'
def docker_client(version=None):
"""
Returns a docker-py client configured using environment variables
according to the same logic as the official Docker client.
@ -18,6 +21,8 @@ def docker_client():
log.warn('The DOCKER_CLIENT_TIMEOUT environment variable is deprecated. Please use COMPOSE_HTTP_TIMEOUT instead.')
kwargs = kwargs_from_env(assert_hostname=False)
kwargs['version'] = os.environ.get('COMPOSE_API_VERSION', '1.19')
kwargs['version'] = version or os.environ.get(
'COMPOSE_API_VERSION',
DEFAULT_API_VERSION)
kwargs['timeout'] = HTTP_TIMEOUT
return Client(**kwargs)

View File

@ -10,6 +10,7 @@ from six import StringIO
from .. import mock
from .testcases import DockerClientTestCase
from compose.cli.command import get_project
from compose.cli.docker_client import docker_client
from compose.cli.errors import UserError
from compose.cli.main import TopLevelCommand
from compose.project import NoSuchService
@ -190,8 +191,9 @@ class CLITestCase(DockerClientTestCase):
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['up', '-d'], None)
client = docker_client(version='1.21')
networks = [n for n in self.client.networks(names=[self.project.name])]
networks = client.networks(names=[self.project.name])
self.assertEqual(len(networks), 0)
for service in self.project.get_services():
@ -207,16 +209,17 @@ class CLITestCase(DockerClientTestCase):
self.command.base_dir = 'tests/fixtures/links-composefile'
self.command.dispatch(['--x-networking', 'up', '-d'], None)
client = docker_client(version='1.21')
services = self.project.get_services()
networks = [n for n in self.client.networks(names=[self.project.name])]
networks = client.networks(names=[self.project.name])
for n in networks:
self.addCleanup(self.client.remove_network, n['id'])
self.addCleanup(client.remove_network, n['id'])
self.assertEqual(len(networks), 1)
self.assertEqual(networks[0]['driver'], 'bridge')
network = self.client.inspect_network(networks[0]['id'])
network = client.inspect_network(networks[0]['id'])
self.assertEqual(len(network['containers']), len(services))
for service in services: