From 8f1a82faeb46cf4eeb3c97bf8cc6a7f0a9105e89 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 15 Jul 2015 12:11:54 -0700 Subject: [PATCH] Add netmode (required by docker) Signed-off-by: John Howard --- docker/utils/utils.py | 10 ++++++++++ tests/integration_test.py | 28 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index a714c97c4b..396c245931 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -615,6 +615,16 @@ def create_container_config( if volumes_from is not None: raise errors.InvalidVersion(message.format('volumes_from')) + # NetworkMode must be present and valid in host config from 1.20 onwards + if compare_version('1.20', version) >= 0: + if host_config is None: + host_config = {'NetworkMode': 'default'} + else: + if 'NetworkMode' not in host_config: + host_config['NetworkMode'] = 'default' + elif host_config['NetworkMode'] == '': + host_config['NetworkMode'] = 'default' + return { 'Hostname': hostname, 'Domainname': domainname, diff --git a/tests/integration_test.py b/tests/integration_test.py index 226ea34c2c..49604332db 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -181,7 +181,8 @@ def runTest(self): container = self.client.create_container( 'busybox', ['ls', mount_dest], volumes={mount_dest: {}}, - host_config=create_host_config(binds=binds) + host_config=create_host_config( + binds=binds, network_mode='none') ) container_id = container['Id'] self.client.start(container_id) @@ -221,7 +222,8 @@ def runTest(self): container = self.client.create_container( 'busybox', ['ls', mount_dest], volumes={mount_dest: {}}, - host_config=create_host_config(binds=binds) + host_config=create_host_config( + binds=binds, network_mode='none') ) container_id = container['Id'] self.client.start(container_id) @@ -273,7 +275,8 @@ class TestCreateContainerReadOnlyFs(BaseTestCase): def runTest(self): ctnr = self.client.create_container( 'busybox', ['mkdir', '/shrine'], - host_config=create_host_config(read_only=True) + host_config=create_host_config( + read_only=True, network_mode='none') ) self.assertIn('Id', ctnr) self.tmp_containers.append(ctnr['Id']) @@ -347,7 +350,8 @@ def runTest(self): class TestCreateContainerPrivileged(BaseTestCase): def runTest(self): res = self.client.create_container( - 'busybox', 'true', host_config=create_host_config(privileged=True) + 'busybox', 'true', host_config=create_host_config( + privileged=True, network_mode='none') ) self.assertIn('Id', res) self.tmp_containers.append(res['Id']) @@ -591,7 +595,8 @@ def runTest(self): container = self.client.create_container( 'busybox', ['sleep', '60'], ports=list(port_bindings.keys()), - host_config=create_host_config(port_bindings=port_bindings) + host_config=create_host_config( + port_bindings=port_bindings, network_mode='bridge') ) id = container['Id'] @@ -717,7 +722,8 @@ def runTest(self): ) res2 = self.client.create_container( 'busybox', 'cat', detach=True, stdin_open=True, - host_config=create_host_config(volumes_from=vol_names) + host_config=create_host_config( + volumes_from=vol_names, network_mode='none') ) container3_id = res2['Id'] self.tmp_containers.append(container3_id) @@ -760,7 +766,8 @@ def runTest(self): res2 = self.client.create_container( 'busybox', 'env', host_config=create_host_config( - links={link_path1: link_alias1, link_path2: link_alias2} + links={link_path1: link_alias1, link_path2: link_alias2}, + network_mode='none' ) ) container3_id = res2['Id'] @@ -781,7 +788,8 @@ class TestRestartingContainer(BaseTestCase): def runTest(self): container = self.client.create_container( 'busybox', ['sleep', '2'], host_config=create_host_config( - restart_policy={"Name": "always", "MaximumRetryCount": 0} + restart_policy={"Name": "always", "MaximumRetryCount": 0}, + network_mode='none' ) ) id = container['Id'] @@ -910,7 +918,7 @@ class TestCreateContainerWithHostPidMode(BaseTestCase): def runTest(self): ctnr = self.client.create_container( 'busybox', 'true', host_config=create_host_config( - pid_mode='host' + pid_mode='host', network_mode='none' ) ) self.assertIn('Id', ctnr) @@ -945,7 +953,7 @@ def runTest(self): container2 = self.client.create_container( 'busybox', 'cat', host_config=create_host_config( - links={link_path: link_alias} + links={link_path: link_alias}, network_mode='none' ) ) container2_id = container2['Id']