From dc8a39f70d66948bcd220d1693ed8ab167fa3513 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 28 Sep 2016 15:31:58 -0700 Subject: [PATCH] Add support for "isolation" in config Signed-off-by: Joffrey F --- compose/config/config_schema_v2.1.json | 1 + compose/service.py | 8 ++++- tests/integration/project_test.py | 43 ++++++++++++++++++++++++++ tests/unit/config/config_test.py | 23 ++++++++++++-- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/compose/config/config_schema_v2.1.json b/compose/config/config_schema_v2.1.json index de4ddf250..243759fa6 100644 --- a/compose/config/config_schema_v2.1.json +++ b/compose/config/config_schema_v2.1.json @@ -123,6 +123,7 @@ "hostname": {"type": "string"}, "image": {"type": "string"}, "ipc": {"type": "string"}, + "isolation": {"type": "string"}, "labels": {"$ref": "#/definitions/list_or_dict"}, "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, diff --git a/compose/service.py b/compose/service.py index c461220f5..f4f4b90dd 100644 --- a/compose/service.py +++ b/compose/service.py @@ -682,7 +682,7 @@ class Service(object): logging_dict = options.get('logging', None) log_config = get_log_config(logging_dict) - return self.client.create_host_config( + host_config = self.client.create_host_config( links=self._get_links(link_to_self=one_off), port_bindings=build_port_bindings(options.get('ports') or []), binds=options.get('binds'), @@ -713,6 +713,12 @@ class Service(object): group_add=options.get('group_add') ) + # TODO: Add as an argument to create_host_config once it's supported + # in docker-py + host_config['Isolation'] = options.get('isolation') + + return host_config + def build(self, no_cache=False, pull=False, force_rm=False): log.info('Building %s' % self.name) diff --git a/tests/integration/project_test.py b/tests/integration/project_test.py index 4427fe6b9..8588c6b14 100644 --- a/tests/integration/project_test.py +++ b/tests/integration/project_test.py @@ -794,6 +794,49 @@ class ProjectTest(DockerClientTestCase): assert 'LinkLocalIPs' in ipam_config assert ipam_config['LinkLocalIPs'] == ['169.254.8.8'] + @v2_1_only() + def test_up_with_isolation(self): + self.require_api_version('1.24') + config_data = config.Config( + version=V2_1, + services=[{ + 'name': 'web', + 'image': 'busybox:latest', + 'isolation': 'default' + }], + volumes={}, + networks={} + ) + project = Project.from_config( + client=self.client, + name='composetest', + config_data=config_data + ) + project.up() + service_container = project.get_service('web').containers()[0] + assert service_container.inspect()['HostConfig']['Isolation'] == 'default' + + @v2_1_only() + def test_up_with_invalid_isolation(self): + self.require_api_version('1.24') + config_data = config.Config( + version=V2_1, + services=[{ + 'name': 'web', + 'image': 'busybox:latest', + 'isolation': 'foobar' + }], + volumes={}, + networks={} + ) + project = Project.from_config( + client=self.client, + name='composetest', + config_data=config_data + ) + with self.assertRaises(ProjectError): + project.up() + @v2_only() def test_project_up_with_network_internal(self): self.require_api_version('1.23') diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 88b990e52..d9bc57647 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -351,7 +351,7 @@ class ConfigTest(unittest.TestCase): base_file = config.ConfigFile( 'base.yaml', { - 'version': '2.1', + 'version': V2_1, 'services': { 'web': { 'image': 'example/web', @@ -1330,7 +1330,7 @@ class ConfigTest(unittest.TestCase): 'image': 'alpine', 'group_add': ["docker", 777] } - } + } })) assert actual.services == [ @@ -1341,6 +1341,25 @@ class ConfigTest(unittest.TestCase): } ] + def test_isolation_option(self): + actual = config.load(build_config_details({ + 'version': V2_1, + 'services': { + 'web': { + 'image': 'win10', + 'isolation': 'hyperv' + } + } + })) + + assert actual.services == [ + { + 'name': 'web', + 'image': 'win10', + 'isolation': 'hyperv', + } + ] + def test_merge_service_dicts_from_files_with_extends_in_base(self): base = { 'volumes': ['.:/app'],