From 16ea49ac8cb71771f52cafc327e864285b6d39ef Mon Sep 17 00:00:00 2001 From: Matthieu Nottale Date: Fri, 16 Mar 2018 15:56:30 +0100 Subject: [PATCH] Add support for cpu_rt_period and cpu_rt_runtime. Signed-off-by: Matthieu Nottale --- compose/config/config.py | 2 ++ compose/config/config_schema_v2.2.json | 2 ++ compose/config/config_schema_v2.3.json | 2 ++ compose/config/interpolation.py | 2 ++ compose/service.py | 4 ++++ tests/integration/service_test.py | 8 ++++++++ 6 files changed, 20 insertions(+) diff --git a/compose/config/config.py b/compose/config/config.py index 59f9d35ba..7bc220e5f 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -69,6 +69,8 @@ DOCKER_CONFIG_KEYS = [ 'cpu_percent', 'cpu_period', 'cpu_quota', + 'cpu_rt_period', + 'cpu_rt_runtime', 'cpu_shares', 'cpus', 'cpuset', diff --git a/compose/config/config_schema_v2.2.json b/compose/config/config_schema_v2.2.json index e15223fc3..dc7076745 100644 --- a/compose/config/config_schema_v2.2.json +++ b/compose/config/config_schema_v2.2.json @@ -111,6 +111,8 @@ "cpu_shares": {"type": ["number", "string"]}, "cpu_quota": {"type": ["number", "string"]}, "cpu_period": {"type": ["number", "string"]}, + "cpu_rt_period": {"type": ["number", "string"]}, + "cpu_rt_runtime": {"type": ["number", "string"]}, "cpus": {"type": "number", "minimum": 0}, "cpuset": {"type": "string"}, "depends_on": { diff --git a/compose/config/config_schema_v2.3.json b/compose/config/config_schema_v2.3.json index c2e860be2..bd7ce166d 100644 --- a/compose/config/config_schema_v2.3.json +++ b/compose/config/config_schema_v2.3.json @@ -114,6 +114,8 @@ "cpu_shares": {"type": ["number", "string"]}, "cpu_quota": {"type": ["number", "string"]}, "cpu_period": {"type": ["number", "string"]}, + "cpu_rt_period": {"type": ["number", "string"]}, + "cpu_rt_runtime": {"type": ["number", "string"]}, "cpus": {"type": "number", "minimum": 0}, "cpuset": {"type": "string"}, "depends_on": { diff --git a/compose/config/interpolation.py b/compose/config/interpolation.py index 7e50f9892..59a567bb2 100644 --- a/compose/config/interpolation.py +++ b/compose/config/interpolation.py @@ -239,6 +239,8 @@ class ConversionMap(object): service_path('cpu_count'): to_int, service_path('cpu_quota'): to_microseconds, service_path('cpu_period'): to_microseconds, + service_path('cpu_rt_period'): to_microseconds, + service_path('cpu_rt_runtime'): to_microseconds, service_path('configs', 'mode'): to_int, service_path('secrets', 'mode'): to_int, service_path('healthcheck', 'retries'): to_int, diff --git a/compose/service.py b/compose/service.py index bcd21d02f..a4e5d9b82 100644 --- a/compose/service.py +++ b/compose/service.py @@ -64,6 +64,8 @@ HOST_CONFIG_KEYS = [ 'cpu_percent', 'cpu_period', 'cpu_quota', + 'cpu_rt_period', + 'cpu_rt_runtime', 'cpu_shares', 'cpus', 'cpuset', @@ -949,6 +951,8 @@ class Service(object): mounts=options.get('mounts'), device_cgroup_rules=options.get('device_cgroup_rules'), cpu_period=options.get('cpu_period'), + cpu_rt_period=options.get('cpu_rt_period'), + cpu_rt_runtime=options.get('cpu_rt_runtime'), ) def get_secret_volumes(self): diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index befc0204a..7c1be24b9 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -128,6 +128,14 @@ class ServiceTest(DockerClientTestCase): assert container.get('HostConfig.CpuQuota') == 40000 assert container.get('HostConfig.CpuPeriod') == 150000 + @pytest.mark.xfail(raises=OperationFailedError, reason='not supported by kernel') + def test_create_container_with_cpu_rt(self): + service = self.create_service('db', cpu_rt_runtime=40000, cpu_rt_period=150000) + container = service.create_container() + container.start() + assert container.get('HostConfig.CpuRealtimeRuntime') == 40000 + assert container.get('HostConfig.CpuRealtimePeriod') == 150000 + @v2_2_only() def test_create_container_with_cpu_count(self): self.require_api_version('1.25')