Unverified Kaydet (Commit) 5eacb986 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) Ben Firshman

Remove support for host_config in Client.start

Any additional arguments passed to start will raise a
DeprecatedMethod (DockerException) exception.
Signed-off-by: 's avatarJoffrey F <joffrey@docker.com>
üst 4c8c761b
...@@ -997,19 +997,16 @@ class ContainerApiMixin(object): ...@@ -997,19 +997,16 @@ class ContainerApiMixin(object):
self._raise_for_status(res) self._raise_for_status(res)
@utils.check_resource @utils.check_resource
def start(self, container, binds=None, port_bindings=None, lxc_conf=None, def start(self, container, *args, **kwargs):
publish_all_ports=None, links=None, privileged=None,
dns=None, dns_search=None, volumes_from=None, network_mode=None,
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
security_opt=None, ulimits=None):
""" """
Start a container. Similar to the ``docker start`` command, but Start a container. Similar to the ``docker start`` command, but
doesn't support attach options. doesn't support attach options.
**Deprecation warning:** For API version > 1.15, it is highly **Deprecation warning:** Passing configuration options in ``start`` is
recommended to provide host config options in the ``host_config`` no longer supported. Users are expected to provide host config options
parameter of :py:meth:`~ContainerApiMixin.create_container`. in the ``host_config`` parameter of
:py:meth:`~ContainerApiMixin.create_container`.
Args: Args:
container (str): The container to start container (str): The container to start
...@@ -1017,6 +1014,8 @@ class ContainerApiMixin(object): ...@@ -1017,6 +1014,8 @@ class ContainerApiMixin(object):
Raises: Raises:
:py:class:`docker.errors.APIError` :py:class:`docker.errors.APIError`
If the server returns an error. If the server returns an error.
:py:class:`docker.errors.DeprecatedMethod`
If any argument besides ``container`` are provided.
Example: Example:
...@@ -1025,64 +1024,14 @@ class ContainerApiMixin(object): ...@@ -1025,64 +1024,14 @@ class ContainerApiMixin(object):
... command='/bin/sleep 30') ... command='/bin/sleep 30')
>>> cli.start(container=container.get('Id')) >>> cli.start(container=container.get('Id'))
""" """
if utils.compare_version('1.10', self._version) < 0: if args or kwargs:
if dns is not None: raise errors.DeprecatedMethod(
raise errors.InvalidVersion( 'Providing configuration in the start() method is no longer '
'dns is only supported for API version >= 1.10' 'supported. Use the host_config param in create_container '
) 'instead.'
if volumes_from is not None: )
raise errors.InvalidVersion(
'volumes_from is only supported for API version >= 1.10'
)
if utils.compare_version('1.15', self._version) < 0:
if security_opt is not None:
raise errors.InvalidVersion(
'security_opt is only supported for API version >= 1.15'
)
if ipc_mode:
raise errors.InvalidVersion(
'ipc_mode is only supported for API version >= 1.15'
)
if utils.compare_version('1.17', self._version) < 0:
if read_only is not None:
raise errors.InvalidVersion(
'read_only is only supported for API version >= 1.17'
)
if pid_mode is not None:
raise errors.InvalidVersion(
'pid_mode is only supported for API version >= 1.17'
)
if utils.compare_version('1.18', self._version) < 0:
if ulimits is not None:
raise errors.InvalidVersion(
'ulimits is only supported for API version >= 1.18'
)
start_config_kwargs = dict(
binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
publish_all_ports=publish_all_ports, links=links, dns=dns,
privileged=privileged, dns_search=dns_search, cap_add=cap_add,
cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
network_mode=network_mode, restart_policy=restart_policy,
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits,
)
start_config = None
if any(v is not None for v in start_config_kwargs.values()):
if utils.compare_version('1.15', self._version) > 0:
warnings.warn(
'Passing host config parameters in start() is deprecated. '
'Please use host_config in create_container instead!',
DeprecationWarning
)
start_config = self.create_host_config(**start_config_kwargs)
url = self._url("/containers/{0}/start", container) url = self._url("/containers/{0}/start", container)
res = self._post_json(url, data=start_config) res = self._post(url)
self._raise_for_status(res) self._raise_for_status(res)
@utils.minimum_version('1.17') @utils.minimum_version('1.17')
......
...@@ -34,10 +34,7 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -34,10 +34,7 @@ class StartContainerTest(BaseAPIClientTest):
args[0][1], args[0][1],
url_prefix + 'containers/3cc2351ab11b/start' url_prefix + 'containers/3cc2351ab11b/start'
) )
self.assertEqual(json.loads(args[1]['data']), {}) assert 'data' not in args[1]
self.assertEqual(
args[1]['headers'], {'Content-Type': 'application/json'}
)
self.assertEqual( self.assertEqual(
args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
) )
...@@ -63,25 +60,21 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -63,25 +60,21 @@ class StartContainerTest(BaseAPIClientTest):
self.client.start(**{'container': fake_api.FAKE_CONTAINER_ID}) self.client.start(**{'container': fake_api.FAKE_CONTAINER_ID})
def test_start_container_with_lxc_conf(self): def test_start_container_with_lxc_conf(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, fake_api.FAKE_CONTAINER_ID,
lxc_conf={'lxc.conf.k': 'lxc.conf.value'} lxc_conf={'lxc.conf.k': 'lxc.conf.value'}
) )
pytest.deprecated_call(call_start)
def test_start_container_with_lxc_conf_compat(self): def test_start_container_with_lxc_conf_compat(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, fake_api.FAKE_CONTAINER_ID,
lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}] lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}]
) )
pytest.deprecated_call(call_start)
def test_start_container_with_binds_ro(self): def test_start_container_with_binds_ro(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, binds={ fake_api.FAKE_CONTAINER_ID, binds={
'/tmp': { '/tmp': {
...@@ -91,22 +84,18 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -91,22 +84,18 @@ class StartContainerTest(BaseAPIClientTest):
} }
) )
pytest.deprecated_call(call_start)
def test_start_container_with_binds_rw(self): def test_start_container_with_binds_rw(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, binds={ fake_api.FAKE_CONTAINER_ID, binds={
'/tmp': {"bind": '/mnt', "ro": False} '/tmp': {"bind": '/mnt', "ro": False}
} }
) )
pytest.deprecated_call(call_start)
def test_start_container_with_port_binds(self): def test_start_container_with_port_binds(self):
self.maxDiff = None self.maxDiff = None
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start(fake_api.FAKE_CONTAINER_ID, port_bindings={ self.client.start(fake_api.FAKE_CONTAINER_ID, port_bindings={
1111: None, 1111: None,
2222: 2222, 2222: 2222,
...@@ -116,18 +105,14 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -116,18 +105,14 @@ class StartContainerTest(BaseAPIClientTest):
6666: [('127.0.0.1',), ('192.168.0.1',)] 6666: [('127.0.0.1',), ('192.168.0.1',)]
}) })
pytest.deprecated_call(call_start)
def test_start_container_with_links(self): def test_start_container_with_links(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, links={'path': 'alias'} fake_api.FAKE_CONTAINER_ID, links={'path': 'alias'}
) )
pytest.deprecated_call(call_start)
def test_start_container_with_multiple_links(self): def test_start_container_with_multiple_links(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start( self.client.start(
fake_api.FAKE_CONTAINER_ID, fake_api.FAKE_CONTAINER_ID,
links={ links={
...@@ -136,21 +121,15 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -136,21 +121,15 @@ class StartContainerTest(BaseAPIClientTest):
} }
) )
pytest.deprecated_call(call_start)
def test_start_container_with_links_as_list_of_tuples(self): def test_start_container_with_links_as_list_of_tuples(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start(fake_api.FAKE_CONTAINER_ID, self.client.start(fake_api.FAKE_CONTAINER_ID,
links=[('path', 'alias')]) links=[('path', 'alias')])
pytest.deprecated_call(call_start)
def test_start_container_privileged(self): def test_start_container_privileged(self):
def call_start(): with pytest.raises(docker.errors.DeprecatedMethod):
self.client.start(fake_api.FAKE_CONTAINER_ID, privileged=True) self.client.start(fake_api.FAKE_CONTAINER_ID, privileged=True)
pytest.deprecated_call(call_start)
def test_start_container_with_dict_instead_of_id(self): def test_start_container_with_dict_instead_of_id(self):
self.client.start({'Id': fake_api.FAKE_CONTAINER_ID}) self.client.start({'Id': fake_api.FAKE_CONTAINER_ID})
...@@ -159,10 +138,7 @@ class StartContainerTest(BaseAPIClientTest): ...@@ -159,10 +138,7 @@ class StartContainerTest(BaseAPIClientTest):
args[0][1], args[0][1],
url_prefix + 'containers/3cc2351ab11b/start' url_prefix + 'containers/3cc2351ab11b/start'
) )
self.assertEqual(json.loads(args[1]['data']), {}) assert 'data' not in args[1]
self.assertEqual(
args[1]['headers'], {'Content-Type': 'application/json'}
)
self.assertEqual( self.assertEqual(
args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment