From c7b8278e78197b87399977c8a512ef72631816a3 Mon Sep 17 00:00:00 2001 From: George Lester Date: Wed, 13 Jul 2016 02:05:08 -0700 Subject: [PATCH 1/2] Implemented dns_opt Signed-off-by: George Lester --- compose/config/config.py | 1 + compose/config/config_schema_v2.0.json | 7 +++++++ compose/service.py | 3 ++- tests/integration/service_test.py | 8 ++++++++ tests/unit/config/config_test.py | 20 +++++++++++++++++++- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/compose/config/config.py b/compose/config/config.py index 003b2e2f4..72d2e8e43 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -61,6 +61,7 @@ DOCKER_CONFIG_KEYS = [ 'devices', 'dns', 'dns_search', + 'dns_opt', 'domainname', 'entrypoint', 'env_file', diff --git a/compose/config/config_schema_v2.0.json b/compose/config/config_schema_v2.0.json index 59c7b30c9..da0105aea 100644 --- a/compose/config/config_schema_v2.0.json +++ b/compose/config/config_schema_v2.0.json @@ -81,6 +81,13 @@ "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "dns": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"}, + "dns_opt": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, "domainname": {"type": "string"}, "entrypoint": { "oneOf": [ diff --git a/compose/service.py b/compose/service.py index b42094e68..0b6200dd5 100644 --- a/compose/service.py +++ b/compose/service.py @@ -54,6 +54,7 @@ DOCKER_START_KEYS = [ 'devices', 'dns', 'dns_search', + 'dns_opt', 'env_file', 'extra_hosts', 'group_add', @@ -755,7 +756,7 @@ class Service(object): network_mode=self.network_mode.mode, devices=options.get('devices'), dns=options.get('dns'), - dns_search=options.get('dns_search'), + dns_opt=options.get('dns_opt'), restart_policy=options.get('restart'), cap_add=options.get('cap_add'), cap_drop=options.get('cap_drop'), diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index 734da5dfa..f3dc346d1 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -890,6 +890,14 @@ class ServiceTest(DockerClientTestCase): self.assertTrue("root" in host_container_groupadd) self.assertTrue("1" in host_container_groupadd) + def test_dns_opt_value(self): + service = self.create_service('web', dns_opt=["use-vc", "no-tld-query"]) + container = create_and_start_container(service) + + dns_opt = container.get('HostConfig.DNSOptions') + self.assertTrue("use-vc" in dns_opt) + self.assertTrue("no-tld-query" in dns_opt) + def test_restart_on_failure_value(self): service = self.create_service('web', restart={ 'Name': 'on-failure', diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index aaa7fbf8d..728206d57 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1411,7 +1411,6 @@ class ConfigTest(unittest.TestCase): ] def test_group_add_option(self): - actual = config.load(build_config_details({ 'version': '2', 'services': { @@ -1430,6 +1429,25 @@ class ConfigTest(unittest.TestCase): } ] + def test_dns_opt_option(self): + actual = config.load(build_config_details({ + 'version': '2', + 'services': { + 'web': { + 'image': 'alpine', + 'dns_opt': ["use-vc", "no-tld-query"] + } + } + })) + + assert actual.services == [ + { + 'name': 'web', + 'image': 'alpine', + 'dns_opt': ["use-vc", "no-tld-query"] + } + ] + def test_isolation_option(self): actual = config.load(build_config_details({ 'version': V2_1, From 7512dccaa85e1c891aca12c87fe0647676e34890 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Fri, 3 Mar 2017 15:40:10 -0800 Subject: [PATCH 2/2] Add dns_opt to 2.1 schema Signed-off-by: Joffrey F --- compose/config/config_schema_v2.0.json | 14 +++++++------- compose/config/config_schema_v2.1.json | 7 +++++++ compose/service.py | 1 + tests/integration/service_test.py | 10 +++++----- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/compose/config/config_schema_v2.0.json b/compose/config/config_schema_v2.0.json index da0105aea..d20a0d89a 100644 --- a/compose/config/config_schema_v2.0.json +++ b/compose/config/config_schema_v2.0.json @@ -80,14 +80,14 @@ "depends_on": {"$ref": "#/definitions/list_of_strings"}, "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "dns": {"$ref": "#/definitions/string_or_list"}, + "dns_opt": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, "dns_search": {"$ref": "#/definitions/string_or_list"}, - "dns_opt": { - "type": "array", - "items": { - "type": "string" - }, - "uniqueItems": true - }, "domainname": {"type": "string"}, "entrypoint": { "oneOf": [ diff --git a/compose/config/config_schema_v2.1.json b/compose/config/config_schema_v2.1.json index d1ffff89a..3b01ddf69 100644 --- a/compose/config/config_schema_v2.1.json +++ b/compose/config/config_schema_v2.1.json @@ -100,6 +100,13 @@ ] }, "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "dns_opt": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, "dns": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"}, "domainname": {"type": "string"}, diff --git a/compose/service.py b/compose/service.py index 0b6200dd5..353c96af4 100644 --- a/compose/service.py +++ b/compose/service.py @@ -757,6 +757,7 @@ class Service(object): devices=options.get('devices'), dns=options.get('dns'), dns_opt=options.get('dns_opt'), + dns_search=options.get('dns_search'), restart_policy=options.get('restart'), cap_add=options.get('cap_add'), cap_drop=options.get('cap_drop'), diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index f3dc346d1..910f2c69c 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -887,16 +887,16 @@ class ServiceTest(DockerClientTestCase): container = create_and_start_container(service) host_container_groupadd = container.get('HostConfig.GroupAdd') - self.assertTrue("root" in host_container_groupadd) - self.assertTrue("1" in host_container_groupadd) + assert "root" in host_container_groupadd + assert "1" in host_container_groupadd def test_dns_opt_value(self): service = self.create_service('web', dns_opt=["use-vc", "no-tld-query"]) container = create_and_start_container(service) - dns_opt = container.get('HostConfig.DNSOptions') - self.assertTrue("use-vc" in dns_opt) - self.assertTrue("no-tld-query" in dns_opt) + dns_opt = container.get('HostConfig.DnsOptions') + assert 'use-vc' in dns_opt + assert 'no-tld-query' in dns_opt def test_restart_on_failure_value(self): service = self.create_service('web', restart={