Skip to content

Commit 3518c9f

Browse files
authored
Merge pull request docker#822 from docker/no_start_config
Remove support for host_config in Client.start
2 parents 4c8c761 + 5eacb98 commit 3518c9f

File tree

2 files changed

+26
-101
lines changed

2 files changed

+26
-101
lines changed

docker/api/container.py

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,25 @@ def restart(self, container, timeout=10):
997997
self._raise_for_status(res)
998998

999999
@utils.check_resource
1000-
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
1001-
publish_all_ports=None, links=None, privileged=None,
1002-
dns=None, dns_search=None, volumes_from=None, network_mode=None,
1003-
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
1004-
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
1005-
security_opt=None, ulimits=None):
1000+
def start(self, container, *args, **kwargs):
10061001
"""
10071002
Start a container. Similar to the ``docker start`` command, but
10081003
doesn't support attach options.
10091004
1010-
**Deprecation warning:** For API version > 1.15, it is highly
1011-
recommended to provide host config options in the ``host_config``
1012-
parameter of :py:meth:`~ContainerApiMixin.create_container`.
1005+
**Deprecation warning:** Passing configuration options in ``start`` is
1006+
no longer supported. Users are expected to provide host config options
1007+
in the ``host_config`` parameter of
1008+
:py:meth:`~ContainerApiMixin.create_container`.
1009+
10131010
10141011
Args:
10151012
container (str): The container to start
10161013
10171014
Raises:
10181015
:py:class:`docker.errors.APIError`
10191016
If the server returns an error.
1017+
:py:class:`docker.errors.DeprecatedMethod`
1018+
If any argument besides ``container`` are provided.
10201019
10211020
Example:
10221021
@@ -1025,64 +1024,14 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
10251024
... command='/bin/sleep 30')
10261025
>>> cli.start(container=container.get('Id'))
10271026
"""
1028-
if utils.compare_version('1.10', self._version) < 0:
1029-
if dns is not None:
1030-
raise errors.InvalidVersion(
1031-
'dns is only supported for API version >= 1.10'
1032-
)
1033-
if volumes_from is not None:
1034-
raise errors.InvalidVersion(
1035-
'volumes_from is only supported for API version >= 1.10'
1036-
)
1037-
1038-
if utils.compare_version('1.15', self._version) < 0:
1039-
if security_opt is not None:
1040-
raise errors.InvalidVersion(
1041-
'security_opt is only supported for API version >= 1.15'
1042-
)
1043-
if ipc_mode:
1044-
raise errors.InvalidVersion(
1045-
'ipc_mode is only supported for API version >= 1.15'
1046-
)
1047-
1048-
if utils.compare_version('1.17', self._version) < 0:
1049-
if read_only is not None:
1050-
raise errors.InvalidVersion(
1051-
'read_only is only supported for API version >= 1.17'
1052-
)
1053-
if pid_mode is not None:
1054-
raise errors.InvalidVersion(
1055-
'pid_mode is only supported for API version >= 1.17'
1056-
)
1057-
1058-
if utils.compare_version('1.18', self._version) < 0:
1059-
if ulimits is not None:
1060-
raise errors.InvalidVersion(
1061-
'ulimits is only supported for API version >= 1.18'
1062-
)
1063-
1064-
start_config_kwargs = dict(
1065-
binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
1066-
publish_all_ports=publish_all_ports, links=links, dns=dns,
1067-
privileged=privileged, dns_search=dns_search, cap_add=cap_add,
1068-
cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
1069-
network_mode=network_mode, restart_policy=restart_policy,
1070-
extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
1071-
ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits,
1072-
)
1073-
start_config = None
1074-
1075-
if any(v is not None for v in start_config_kwargs.values()):
1076-
if utils.compare_version('1.15', self._version) > 0:
1077-
warnings.warn(
1078-
'Passing host config parameters in start() is deprecated. '
1079-
'Please use host_config in create_container instead!',
1080-
DeprecationWarning
1081-
)
1082-
start_config = self.create_host_config(**start_config_kwargs)
1083-
1027+
if args or kwargs:
1028+
raise errors.DeprecatedMethod(
1029+
'Providing configuration in the start() method is no longer '
1030+
'supported. Use the host_config param in create_container '
1031+
'instead.'
1032+
)
10841033
url = self._url("/containers/{0}/start", container)
1085-
res = self._post_json(url, data=start_config)
1034+
res = self._post(url)
10861035
self._raise_for_status(res)
10871036

10881037
@utils.minimum_version('1.17')

tests/unit/api_container_test.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ def test_start_container(self):
3434
args[0][1],
3535
url_prefix + 'containers/3cc2351ab11b/start'
3636
)
37-
self.assertEqual(json.loads(args[1]['data']), {})
38-
self.assertEqual(
39-
args[1]['headers'], {'Content-Type': 'application/json'}
40-
)
37+
assert 'data' not in args[1]
4138
self.assertEqual(
4239
args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
4340
)
@@ -63,25 +60,21 @@ def test_start_container_regression_573(self):
6360
self.client.start(**{'container': fake_api.FAKE_CONTAINER_ID})
6461

6562
def test_start_container_with_lxc_conf(self):
66-
def call_start():
63+
with pytest.raises(docker.errors.DeprecatedMethod):
6764
self.client.start(
6865
fake_api.FAKE_CONTAINER_ID,
6966
lxc_conf={'lxc.conf.k': 'lxc.conf.value'}
7067
)
7168

72-
pytest.deprecated_call(call_start)
73-
7469
def test_start_container_with_lxc_conf_compat(self):
75-
def call_start():
70+
with pytest.raises(docker.errors.DeprecatedMethod):
7671
self.client.start(
7772
fake_api.FAKE_CONTAINER_ID,
7873
lxc_conf=[{'Key': 'lxc.conf.k', 'Value': 'lxc.conf.value'}]
7974
)
8075

81-
pytest.deprecated_call(call_start)
82-
8376
def test_start_container_with_binds_ro(self):
84-
def call_start():
77+
with pytest.raises(docker.errors.DeprecatedMethod):
8578
self.client.start(
8679
fake_api.FAKE_CONTAINER_ID, binds={
8780
'/tmp': {
@@ -91,22 +84,18 @@ def call_start():
9184
}
9285
)
9386

94-
pytest.deprecated_call(call_start)
95-
9687
def test_start_container_with_binds_rw(self):
97-
def call_start():
88+
with pytest.raises(docker.errors.DeprecatedMethod):
9889
self.client.start(
9990
fake_api.FAKE_CONTAINER_ID, binds={
10091
'/tmp': {"bind": '/mnt', "ro": False}
10192
}
10293
)
10394

104-
pytest.deprecated_call(call_start)
105-
10695
def test_start_container_with_port_binds(self):
10796
self.maxDiff = None
10897

109-
def call_start():
98+
with pytest.raises(docker.errors.DeprecatedMethod):
11099
self.client.start(fake_api.FAKE_CONTAINER_ID, port_bindings={
111100
1111: None,
112101
2222: 2222,
@@ -116,18 +105,14 @@ def call_start():
116105
6666: [('127.0.0.1',), ('192.168.0.1',)]
117106
})
118107

119-
pytest.deprecated_call(call_start)
120-
121108
def test_start_container_with_links(self):
122-
def call_start():
109+
with pytest.raises(docker.errors.DeprecatedMethod):
123110
self.client.start(
124111
fake_api.FAKE_CONTAINER_ID, links={'path': 'alias'}
125112
)
126113

127-
pytest.deprecated_call(call_start)
128-
129114
def test_start_container_with_multiple_links(self):
130-
def call_start():
115+
with pytest.raises(docker.errors.DeprecatedMethod):
131116
self.client.start(
132117
fake_api.FAKE_CONTAINER_ID,
133118
links={
@@ -136,21 +121,15 @@ def call_start():
136121
}
137122
)
138123

139-
pytest.deprecated_call(call_start)
140-
141124
def test_start_container_with_links_as_list_of_tuples(self):
142-
def call_start():
125+
with pytest.raises(docker.errors.DeprecatedMethod):
143126
self.client.start(fake_api.FAKE_CONTAINER_ID,
144127
links=[('path', 'alias')])
145128

146-
pytest.deprecated_call(call_start)
147-
148129
def test_start_container_privileged(self):
149-
def call_start():
130+
with pytest.raises(docker.errors.DeprecatedMethod):
150131
self.client.start(fake_api.FAKE_CONTAINER_ID, privileged=True)
151132

152-
pytest.deprecated_call(call_start)
153-
154133
def test_start_container_with_dict_instead_of_id(self):
155134
self.client.start({'Id': fake_api.FAKE_CONTAINER_ID})
156135

@@ -159,10 +138,7 @@ def test_start_container_with_dict_instead_of_id(self):
159138
args[0][1],
160139
url_prefix + 'containers/3cc2351ab11b/start'
161140
)
162-
self.assertEqual(json.loads(args[1]['data']), {})
163-
self.assertEqual(
164-
args[1]['headers'], {'Content-Type': 'application/json'}
165-
)
141+
assert 'data' not in args[1]
166142
self.assertEqual(
167143
args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
168144
)

0 commit comments

Comments
 (0)