Merge pull request #1886 from mnowster/create-host-config-needs-version

Stop using deprecated `create_host_config` from utils
This commit is contained in:
Daniel Nephin 2015-09-17 12:37:22 -04:00
commit aab688d27e
4 changed files with 43 additions and 19 deletions

View File

@ -11,7 +11,6 @@ from operator import attrgetter
import enum
import six
from docker.errors import APIError
from docker.utils import create_host_config
from docker.utils import LogConfig
from docker.utils.ports import build_port_bindings
from docker.utils.ports import split_port
@ -679,7 +678,7 @@ class Service(object):
devices = options.get('devices', None)
return create_host_config(
return self.client.create_host_config(
links=self._get_links(link_to_self=one_off),
port_bindings=port_bindings,
binds=options.get('binds'),

View File

@ -813,6 +813,13 @@ class ServiceTest(DockerClientTestCase):
for k, v in {'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''}.items():
self.assertEqual(env[k], v)
def test_with_high_enough_api_version_we_get_default_network_mode(self):
# TODO: remove this test once minimum docker version is 1.8.x
with mock.patch.object(self.client, '_version', '1.20'):
service = self.create_service('web')
service_config = service._get_container_host_config({})
self.assertEquals(service_config['NetworkMode'], 'default')
def test_labels(self):
labels_dict = {
'com.example.description': "Accounting webapp",

View File

@ -144,8 +144,11 @@ class CLITestCase(unittest.TestCase):
'--rm': None,
'--name': None,
})
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
self.assertEquals(call_kwargs['host_config']['RestartPolicy']['Name'], 'always')
self.assertEquals(
mock_client.create_host_config.call_args[1]['restart_policy']['Name'],
'always'
)
command = TopLevelCommand()
mock_client = mock.create_autospec(docker.Client)
@ -170,8 +173,10 @@ class CLITestCase(unittest.TestCase):
'--rm': True,
'--name': None,
})
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
self.assertFalse('RestartPolicy' in call_kwargs['host_config'])
self.assertFalse(
mock_client.create_host_config.call_args[1].get('restart_policy')
)
def test_command_manula_and_service_ports_together(self):
command = TopLevelCommand()

View File

@ -2,7 +2,6 @@ from __future__ import absolute_import
from __future__ import unicode_literals
import docker
from docker.utils import LogConfig
from .. import mock
from .. import unittest
@ -108,19 +107,33 @@ class ServiceTest(unittest.TestCase):
self.assertFalse('domainname' in opts, 'domainname')
def test_memory_swap_limit(self):
self.mock_client.create_host_config.return_value = {}
service = Service(name='foo', image='foo', hostname='name', client=self.mock_client, mem_limit=1000000000, memswap_limit=2000000000)
opts = service._get_container_create_options({'some': 'overrides'}, 1)
self.assertEqual(opts['host_config']['MemorySwap'], 2000000000)
self.assertEqual(opts['host_config']['Memory'], 1000000000)
service._get_container_create_options({'some': 'overrides'}, 1)
self.assertTrue(self.mock_client.create_host_config.called)
self.assertEqual(
self.mock_client.create_host_config.call_args[1]['mem_limit'],
1000000000
)
self.assertEqual(
self.mock_client.create_host_config.call_args[1]['memswap_limit'],
2000000000
)
def test_log_opt(self):
self.mock_client.create_host_config.return_value = {}
log_opt = {'syslog-address': 'tcp://192.168.0.42:123'}
service = Service(name='foo', image='foo', hostname='name', client=self.mock_client, log_driver='syslog', log_opt=log_opt)
opts = service._get_container_create_options({'some': 'overrides'}, 1)
service._get_container_create_options({'some': 'overrides'}, 1)
self.assertIsInstance(opts['host_config']['LogConfig'], LogConfig)
self.assertEqual(opts['host_config']['LogConfig'].type, 'syslog')
self.assertEqual(opts['host_config']['LogConfig'].config, log_opt)
self.assertTrue(self.mock_client.create_host_config.called)
self.assertEqual(
self.mock_client.create_host_config.call_args[1]['log_config'],
{'Type': 'syslog', 'Config': {'syslog-address': 'tcp://192.168.0.42:123'}}
)
def test_split_domainname_fqdn(self):
service = Service(
@ -530,13 +543,13 @@ class ServiceVolumesTest(unittest.TestCase):
}
}
create_options = service._get_container_create_options(
service._get_container_create_options(
override_options={},
number=1,
)
self.assertEqual(
set(create_options['host_config']['Binds']),
set(self.mock_client.create_host_config.call_args[1]['binds']),
set([
'/host/path:/data1:rw',
'/host/path:/data2:rw',
@ -568,14 +581,14 @@ class ServiceVolumesTest(unittest.TestCase):
},
}
create_options = service._get_container_create_options(
service._get_container_create_options(
override_options={},
number=1,
previous_container=Container(self.mock_client, {'Id': '123123123'}),
)
self.assertEqual(
create_options['host_config']['Binds'],
self.mock_client.create_host_config.call_args[1]['binds'],
['/mnt/sda1/host/path:/data:rw'],
)
@ -600,4 +613,4 @@ class ServiceVolumesTest(unittest.TestCase):
).create_container()
self.assertEqual(len(create_calls), 1)
self.assertEqual(create_calls[0][1]['host_config']['Binds'], volumes)
self.assertEqual(self.mock_client.create_host_config.call_args[1]['binds'], volumes)