Blame SOURCES/implement-cpu_rt_-switches.patch

331acb
From e2b5a06cfd5375efc9741ea6bdad1ed764a65e54 Mon Sep 17 00:00:00 2001
331acb
From: Tomas Tomecek <ttomecek@redhat.com>
331acb
Date: Wed, 6 Sep 2017 17:57:56 +0200
331acb
Subject: [PATCH] implement cpu_rt_* switches for create_host_config
331acb
331acb
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
331acb
---
331acb
 docker/utils/utils.py               | 23 ++++++++++++++++++++++-
331acb
 docs/hostconfig.md                  |  2 ++
331acb
 tests/integration/container_test.py | 28 ++++++++++++++++++++++++++++
331acb
 tests/unit/container_test.py        | 25 +++++++++++++++++++++++++
331acb
 4 files changed, 77 insertions(+), 1 deletion(-)
331acb
331acb
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
331acb
index 8d55b57..2a183a0 100644
331acb
--- a/docker/utils/utils.py
331acb
+++ b/docker/utils/utils.py
331acb
@@ -609,7 +609,8 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
331acb
                        device_write_iops=None, oom_kill_disable=False,
331acb
                        shm_size=None, sysctls=None, version=None, tmpfs=None,
331acb
                        oom_score_adj=None, dns_opt=None, cpu_shares=None,
331acb
-                       cpuset_cpus=None, userns_mode=None, pids_limit=None):
331acb
+                       cpuset_cpus=None, userns_mode=None, pids_limit=None,
331acb
+                       cpu_rt_period=None, cpu_rt_runtime=None):
331acb
 
331acb
     host_config = {}
331acb
 
331acb
@@ -897,6 +898,26 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
331acb
             raise host_config_version_error('pids_limit', '1.23')
331acb
         host_config["PidsLimit"] = pids_limit
331acb
 
331acb
+    if cpu_rt_period:
331acb
+        if version_lt(version, '1.25'):
331acb
+            raise host_config_version_error('cpu_rt_period', '1.25')
331acb
+
331acb
+        if not isinstance(cpu_rt_period, int):
331acb
+            raise host_config_type_error(
331acb
+                'cpu_rt_period', cpu_rt_period, 'int'
331acb
+            )
331acb
+        host_config['CPURealtimePeriod'] = cpu_rt_period
331acb
+
331acb
+    if cpu_rt_runtime:
331acb
+        if version_lt(version, '1.25'):
331acb
+            raise host_config_version_error('cpu_rt_runtime', '1.25')
331acb
+
331acb
+        if not isinstance(cpu_rt_runtime, int):
331acb
+            raise host_config_type_error(
331acb
+                'cpu_rt_runtime', cpu_rt_runtime, 'int'
331acb
+            )
331acb
+        host_config['CPURealtimeRuntime'] = cpu_rt_runtime
331acb
+
331acb
     return host_config
331acb
 
331acb
 
331acb
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
331acb
index 008d5cf..c39a02c 100644
331acb
--- a/docs/hostconfig.md
331acb
+++ b/docs/hostconfig.md
331acb
@@ -130,6 +130,8 @@ for example:
331acb
 * userns_mode (str): Sets the user namespace mode for the container when user
331acb
   namespace remapping option is enabled. Supported values are: `host`
331acb
 * pids_limit (int): Tune a container’s pids limit. Set -1 for unlimited.
331acb
+* cpu_rt_runtime (int): Limit the CPU real-time runtime in microseconds.
331acb
+* cpu_rt_period (int): Limit the CPU real-time period in microseconds.
331acb
 
331acb
 **Returns** (dict) HostConfig dictionary
331acb
 
331acb
diff --git a/tests/integration/container_test.py b/tests/integration/container_test.py
331acb
index e390acb..7d179d5 100644
331acb
--- a/tests/integration/container_test.py
331acb
+++ b/tests/integration/container_test.py
331acb
@@ -1144,3 +1144,31 @@ class ContainerCPUTest(helpers.BaseTestCase):
331acb
         self.client.start(container)
331acb
         inspect_data = self.client.inspect_container(container)
331acb
         self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus)
331acb
+
331acb
+
331acb
+class ContainerCPURT(helpers.BaseTestCase):
331acb
+    @requires_api_version('1.25')
331acb
+    def test_container_cpu_rt_runtime(self):
331acb
+        cpu_rt_runtime = 1000
331acb
+        container = self.client.create_container(
331acb
+            BUSYBOX, 'ls', host_config=self.client.create_host_config(
331acb
+                cpu_rt_runtime=cpu_rt_runtime
331acb
+            )
331acb
+        )
331acb
+        self.tmp_containers.append(container)
331acb
+        self.client.start(container)
331acb
+        inspect_data = self.client.inspect_container(container)
331acb
+        self.assertEqual(inspect_data['HostConfig']['CPURealtimeRuntime'], 1000)
331acb
+
331acb
+    @requires_api_version('1.285')
331acb
+    def test_container_rt_period(self):
331acb
+        cpu_rt_period = 2000
331acb
+        container = self.client.create_container(
331acb
+            BUSYBOX, 'ls', host_config=self.client.create_host_config(
331acb
+                cpu_rt_period=cpu_rt_period
331acb
+            )
331acb
+        )
331acb
+        self.tmp_containers.append(container)
331acb
+        self.client.start(container)
331acb
+        inspect_data = self.client.inspect_container(container)
331acb
+        self.assertEqual(inspect_data['HostConfig']['CPURealtimePeriod'], 2000)
331acb
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
331acb
index db3dd74..8c7b2c1 100644
331acb
--- a/tests/unit/container_test.py
331acb
+++ b/tests/unit/container_test.py
331acb
@@ -335,6 +335,31 @@ class CreateContainerTest(DockerClientTest):
331acb
         self.assertEqual(args[1]['headers'],
331acb
                          {'Content-Type': 'application/json'})
331acb
 
331acb
+    @requires_api_version('1.25')
331acb
+    def test_create_container_with_rt(self):
331acb
+        self.client.create_container(
331acb
+            'busybox', 'ls', host_config=self.client.create_host_config(
331acb
+                cpu_rt_period=1000, cpu_rt_runtime=1000
331acb
+            )
331acb
+        )
331acb
+
331acb
+        args = fake_request.call_args
331acb
+        self.assertEqual(args[0][1],
331acb
+                         url_prefix + 'containers/create')
331acb
+        self.assertEqual(json.loads(args[1]['data']),
331acb
+                         json.loads('''
331acb
+                            {"Tty": false, "Image": "busybox",
331acb
+                             "Cmd": ["ls"], "AttachStdin": false,
331acb
+                             "AttachStderr": true,
331acb
+                             "AttachStdout": true, "OpenStdin": false,
331acb
+                             "StdinOnce": false,
331acb
+                             "NetworkDisabled": false,
331acb
+                             "HostConfig": {
331acb
+                               "CPURealtimePeriod": 1000,
331acb
+                               "CPURealtimeRuntime": 1000,
331acb
+                               "NetworkMode": "default"
331acb
+                             }}'''))
331acb
+
331acb
     @requires_api_version('1.18')
331acb
     def test_create_container_with_host_config_cpuset(self):
331acb
         self.client.create_container(
331acb
-- 
331acb
2.14.1
331acb