Skip to content

Commit 2fd2eeb

Browse files
committed
Added deprecation warning for host config in start
1 parent f28e90b commit 2fd2eeb

File tree

3 files changed

+192
-501
lines changed

3 files changed

+192
-501
lines changed

docker/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,12 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
10591059
url = self._url("/containers/{0}/start".format(container))
10601060
if not start_config:
10611061
start_config = None
1062+
elif utils.compare_version('1.15', self._version) > 0:
1063+
warnings.warn(
1064+
'Passing host config parameters in start() is deprecated. '
1065+
'Please use host_config in create_container instead!',
1066+
DeprecationWarning
1067+
)
10621068
res = self._post_json(url, data=start_config)
10631069
self._raise_for_status(res)
10641070

tests/integration_test.py

Lines changed: 0 additions & 282 deletions
Original file line numberDiff line numberDiff line change
@@ -242,113 +242,6 @@ def runTest(self):
242242
self.assertFalse(inspect_data['VolumesRW'][mount_dest])
243243

244244

245-
class TestStartContainerWithBinds(BaseTestCase):
246-
def runTest(self):
247-
mount_dest = '/mnt'
248-
mount_origin = tempfile.mkdtemp()
249-
self.tmp_folders.append(mount_origin)
250-
251-
filename = 'shared.txt'
252-
shared_file = os.path.join(mount_origin, filename)
253-
binds = {
254-
mount_origin: {
255-
'bind': mount_dest,
256-
'ro': False,
257-
},
258-
}
259-
260-
with open(shared_file, 'w'):
261-
container = self.client.create_container(
262-
'busybox', ['ls', mount_dest], volumes={mount_dest: {}}
263-
)
264-
container_id = container['Id']
265-
self.client.start(container_id, binds=binds)
266-
self.tmp_containers.append(container_id)
267-
exitcode = self.client.wait(container_id)
268-
self.assertEqual(exitcode, 0)
269-
logs = self.client.logs(container_id)
270-
271-
os.unlink(shared_file)
272-
if six.PY3:
273-
logs = logs.decode('utf-8')
274-
self.assertIn(filename, logs)
275-
inspect_data = self.client.inspect_container(container_id)
276-
self.assertIn('Volumes', inspect_data)
277-
self.assertIn(mount_dest, inspect_data['Volumes'])
278-
self.assertEqual(mount_origin, inspect_data['Volumes'][mount_dest])
279-
self.assertIn(mount_dest, inspect_data['VolumesRW'])
280-
self.assertTrue(inspect_data['VolumesRW'][mount_dest])
281-
282-
283-
class TestStartContainerWithRoBinds(BaseTestCase):
284-
def runTest(self):
285-
mount_dest = '/mnt'
286-
mount_origin = tempfile.mkdtemp()
287-
self.tmp_folders.append(mount_origin)
288-
289-
filename = 'shared.txt'
290-
shared_file = os.path.join(mount_origin, filename)
291-
binds = {
292-
mount_origin: {
293-
'bind': mount_dest,
294-
'ro': True,
295-
},
296-
}
297-
298-
with open(shared_file, 'w'):
299-
container = self.client.create_container(
300-
'busybox', ['ls', mount_dest], volumes={mount_dest: {}}
301-
)
302-
container_id = container['Id']
303-
self.client.start(container_id, binds=binds)
304-
self.tmp_containers.append(container_id)
305-
exitcode = self.client.wait(container_id)
306-
self.assertEqual(exitcode, 0)
307-
logs = self.client.logs(container_id)
308-
309-
os.unlink(shared_file)
310-
if six.PY3:
311-
logs = logs.decode('utf-8')
312-
self.assertIn(filename, logs)
313-
314-
inspect_data = self.client.inspect_container(container_id)
315-
self.assertIn('Volumes', inspect_data)
316-
self.assertIn(mount_dest, inspect_data['Volumes'])
317-
self.assertEqual(mount_origin, inspect_data['Volumes'][mount_dest])
318-
self.assertIn('VolumesRW', inspect_data)
319-
self.assertIn(mount_dest, inspect_data['VolumesRW'])
320-
self.assertFalse(inspect_data['VolumesRW'][mount_dest])
321-
322-
323-
class TestStartContainerWithFileBind(BaseTestCase):
324-
def runTest(self):
325-
mount_dest = '/myfile/myfile'
326-
mount_origin = tempfile.mktemp()
327-
try:
328-
binds = {
329-
mount_origin: {
330-
'bind': mount_dest,
331-
'ro': True
332-
},
333-
}
334-
335-
with open(mount_origin, 'w') as f:
336-
f.write('sakuya izayoi')
337-
338-
container = self.client.create_container(
339-
'busybox', ['cat', mount_dest], volumes={mount_dest: {}}
340-
)
341-
self.client.start(container, binds=binds)
342-
exitcode = self.client.wait(container)
343-
self.assertEqual(exitcode, 0)
344-
logs = self.client.logs(container)
345-
if six.PY3:
346-
logs = logs.decode('utf-8')
347-
self.assertIn('sakuya izayoi', logs)
348-
finally:
349-
os.unlink(mount_origin)
350-
351-
352245
class TestCreateContainerWithLogConfig(BaseTestCase):
353246
def runTest(self):
354247
config = docker.utils.LogConfig(
@@ -388,21 +281,6 @@ def runTest(self):
388281
self.assertNotEqual(res, 0)
389282

390283

391-
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
392-
class TestStartContainerReadOnlyFs(BaseTestCase):
393-
def runTest(self):
394-
# Presumably a bug in 1.5.0
395-
# https://github.com/docker/docker/issues/10695
396-
ctnr = self.client.create_container(
397-
'busybox', ['mkdir', '/shrine'],
398-
)
399-
self.assertIn('Id', ctnr)
400-
self.tmp_containers.append(ctnr['Id'])
401-
self.client.start(ctnr, read_only=True)
402-
# res = self.client.wait(ctnr)
403-
# self.assertNotEqual(res, 0)
404-
405-
406284
class TestCreateContainerWithName(BaseTestCase):
407285
def runTest(self):
408286
res = self.client.create_container('busybox', 'true', name='foobar')
@@ -490,29 +368,6 @@ def runTest(self):
490368
self.assertEqual(inspect['Config']['Privileged'], True)
491369

492370

493-
class TestStartContainerPrivileged(BaseTestCase):
494-
def runTest(self):
495-
res = self.client.create_container('busybox', 'true')
496-
self.assertIn('Id', res)
497-
self.tmp_containers.append(res['Id'])
498-
self.client.start(res['Id'], privileged=True)
499-
inspect = self.client.inspect_container(res['Id'])
500-
self.assertIn('Config', inspect)
501-
self.assertIn('Id', inspect)
502-
self.assertTrue(inspect['Id'].startswith(res['Id']))
503-
self.assertIn('Image', inspect)
504-
self.assertIn('State', inspect)
505-
self.assertIn('Running', inspect['State'])
506-
if not inspect['State']['Running']:
507-
self.assertIn('ExitCode', inspect['State'])
508-
self.assertEqual(inspect['State']['ExitCode'], 0)
509-
# Since Nov 2013, the Privileged flag is no longer part of the
510-
# container's config exposed via the API (safety concerns?).
511-
#
512-
if 'Privileged' in inspect['Config']:
513-
self.assertEqual(inspect['Config']['Privileged'], True)
514-
515-
516371
class TestWait(BaseTestCase):
517372
def runTest(self):
518373
res = self.client.create_container('busybox', ['sleep', '3'])
@@ -754,34 +609,6 @@ def runTest(self):
754609
self.client.kill(id)
755610

756611

757-
class TestStartWithPortBindings(BaseTestCase):
758-
def runTest(self):
759-
760-
port_bindings = {
761-
'1111': ('127.0.0.1', '4567'),
762-
'2222': ('127.0.0.1', '4568')
763-
}
764-
765-
container = self.client.create_container(
766-
'busybox', ['sleep', '60'], ports=list(port_bindings.keys())
767-
)
768-
id = container['Id']
769-
770-
self.client.start(container, port_bindings=port_bindings)
771-
772-
# Call the port function on each biding and compare expected vs actual
773-
for port in port_bindings:
774-
actual_bindings = self.client.port(container, port)
775-
port_binding = actual_bindings.pop()
776-
777-
ip, host_port = port_binding['HostIp'], port_binding['HostPort']
778-
779-
self.assertEqual(ip, port_bindings[port][0])
780-
self.assertEqual(host_port, port_bindings[port][1])
781-
782-
self.client.kill(id)
783-
784-
785612
class TestMacAddress(BaseTestCase):
786613
def runTest(self):
787614
mac_address_expected = "02:42:ac:11:00:0a"
@@ -949,101 +776,6 @@ def runTest(self):
949776
self.assertIn('{0}_ENV_FOO=1'.format(link_env_prefix2), logs)
950777

951778

952-
class TestStartContainerWithVolumesFrom(BaseTestCase):
953-
def runTest(self):
954-
vol_names = ['foobar_vol0', 'foobar_vol1']
955-
956-
res0 = self.client.create_container(
957-
'busybox', 'true',
958-
name=vol_names[0])
959-
container1_id = res0['Id']
960-
self.tmp_containers.append(container1_id)
961-
self.client.start(container1_id)
962-
963-
res1 = self.client.create_container(
964-
'busybox', 'true',
965-
name=vol_names[1])
966-
container2_id = res1['Id']
967-
self.tmp_containers.append(container2_id)
968-
self.client.start(container2_id)
969-
with self.assertRaises(docker.errors.DockerException):
970-
res2 = self.client.create_container(
971-
'busybox', 'cat',
972-
detach=True, stdin_open=True,
973-
volumes_from=vol_names)
974-
res2 = self.client.create_container(
975-
'busybox', 'cat',
976-
detach=True, stdin_open=True)
977-
container3_id = res2['Id']
978-
self.tmp_containers.append(container3_id)
979-
self.client.start(container3_id, volumes_from=vol_names)
980-
981-
info = self.client.inspect_container(res2['Id'])
982-
self.assertCountEqual(info['HostConfig']['VolumesFrom'], vol_names)
983-
984-
985-
class TestStartContainerWithUlimits(BaseTestCase):
986-
def runTest(self):
987-
ulimit = docker.utils.Ulimit(name='nofile', soft=4096, hard=4096)
988-
989-
res0 = self.client.create_container('busybox', 'true')
990-
container1_id = res0['Id']
991-
self.tmp_containers.append(container1_id)
992-
self.client.start(container1_id, ulimits=[ulimit])
993-
994-
info = self.client.inspect_container(container1_id)
995-
self.assertCountEqual(info['HostConfig']['Ulimits'], [ulimit])
996-
997-
998-
class TestStartContainerWithLinks(BaseTestCase):
999-
def runTest(self):
1000-
res0 = self.client.create_container(
1001-
'busybox', 'cat',
1002-
detach=True, stdin_open=True,
1003-
environment={'FOO': '1'})
1004-
1005-
container1_id = res0['Id']
1006-
self.tmp_containers.append(container1_id)
1007-
1008-
self.client.start(container1_id)
1009-
1010-
res1 = self.client.create_container(
1011-
'busybox', 'cat',
1012-
detach=True, stdin_open=True,
1013-
environment={'FOO': '1'})
1014-
1015-
container2_id = res1['Id']
1016-
self.tmp_containers.append(container2_id)
1017-
1018-
self.client.start(container2_id)
1019-
1020-
# we don't want the first /
1021-
link_path1 = self.client.inspect_container(container1_id)['Name'][1:]
1022-
link_alias1 = 'mylink1'
1023-
link_env_prefix1 = link_alias1.upper()
1024-
1025-
link_path2 = self.client.inspect_container(container2_id)['Name'][1:]
1026-
link_alias2 = 'mylink2'
1027-
link_env_prefix2 = link_alias2.upper()
1028-
1029-
res2 = self.client.create_container('busybox', 'env')
1030-
container3_id = res2['Id']
1031-
self.tmp_containers.append(container3_id)
1032-
self.client.start(
1033-
container3_id,
1034-
links={link_path1: link_alias1, link_path2: link_alias2}
1035-
)
1036-
self.assertEqual(self.client.wait(container3_id), 0)
1037-
1038-
logs = self.client.logs(container3_id)
1039-
if six.PY3:
1040-
logs = logs.decode('utf-8')
1041-
self.assertIn('{0}_NAME='.format(link_env_prefix1), logs)
1042-
self.assertIn('{0}_ENV_FOO=1'.format(link_env_prefix1), logs)
1043-
self.assertIn('{0}_NAME='.format(link_env_prefix2), logs)
1044-
self.assertIn('{0}_ENV_FOO=1'.format(link_env_prefix2), logs)
1045-
1046-
1047779
class TestRestartingContainer(BaseTestCase):
1048780
def runTest(self):
1049781
container = self.client.create_container(
@@ -1190,20 +922,6 @@ def runTest(self):
1190922
self.assertEqual(host_config['PidMode'], 'host')
1191923

1192924

1193-
class TestStartContainerWithHostPidMode(BaseTestCase):
1194-
def runTest(self):
1195-
ctnr = self.client.create_container(
1196-
'busybox', 'true'
1197-
)
1198-
self.assertIn('Id', ctnr)
1199-
self.tmp_containers.append(ctnr['Id'])
1200-
self.client.start(ctnr, pid_mode='host')
1201-
inspect = self.client.inspect_container(ctnr)
1202-
self.assertIn('HostConfig', inspect)
1203-
host_config = inspect['HostConfig']
1204-
self.assertIn('PidMode', host_config)
1205-
self.assertEqual(host_config['PidMode'], 'host')
1206-
1207925
#################
1208926
# LINKS TESTS #
1209927
#################

0 commit comments

Comments
 (0)