Kaydet (Commit) d74f1bc3 authored tarafından Tzu-Chiao Yeh's avatar Tzu-Chiao Yeh

Fix #1575 - Add cpu_rt_period and cpu_rt_runtime args

Add cpu_rt_period and cpu_rt_runtime in hostconfig with version(1.25), types(int) checks.
Also add version and type checks in dockertype unit test.
Signed-off-by: 's avatarTzu-Chiao Yeh <su3g4284zo6y7@gmail.com>
üst 369168e2
......@@ -861,6 +861,8 @@ RUN_HOST_CONFIG_KWARGS = [
'cpu_shares',
'cpuset_cpus',
'cpuset_mems',
'cpu_rt_period',
'cpu_rt_runtime',
'device_read_bps',
'device_read_iops',
'device_write_bps',
......
......@@ -120,7 +120,8 @@ class HostConfig(dict):
isolation=None, auto_remove=False, storage_opt=None,
init=None, init_path=None, volume_driver=None,
cpu_count=None, cpu_percent=None, nano_cpus=None,
cpuset_mems=None, runtime=None):
cpuset_mems=None, runtime=None, cpu_rt_period=None,
cpu_rt_runtime=None):
if mem_limit is not None:
self['Memory'] = parse_bytes(mem_limit)
......@@ -339,6 +340,26 @@ class HostConfig(dict):
)
self['CpusetMems'] = cpuset_mems
if cpu_rt_period:
if version_lt(version, '1.25'):
raise host_config_version_error('cpu_rt_period', '1.25')
if not isinstance(cpu_rt_period, int):
raise host_config_type_error(
'cpu_rt_period', cpu_rt_period, 'int'
)
self['CPURealtimePeriod'] = cpu_rt_period
if cpu_rt_runtime:
if version_lt(version, '1.25'):
raise host_config_version_error('cpu_rt_runtime', '1.25')
if not isinstance(cpu_rt_runtime, int):
raise host_config_type_error(
'cpu_rt_runtime', cpu_rt_runtime, 'int'
)
self['CPURealtimeRuntime'] = cpu_rt_runtime
if blkio_weight:
if not isinstance(blkio_weight, int):
raise host_config_type_error(
......
......@@ -206,6 +206,28 @@ class HostConfigTest(unittest.TestCase):
InvalidVersion, lambda: create_host_config(
version='1.24', nano_cpus=1))
def test_create_host_config_with_cpu_rt_period_types(self):
with pytest.raises(TypeError):
create_host_config(version='1.25', cpu_rt_period='1000')
def test_create_host_config_with_cpu_rt_period(self):
config = create_host_config(version='1.25', cpu_rt_period=1000)
self.assertEqual(config.get('CPURealtimePeriod'), 1000)
self.assertRaises(
InvalidVersion, lambda: create_host_config(
version='1.24', cpu_rt_period=1000))
def test_ctrate_host_config_with_cpu_rt_runtime_types(self):
with pytest.raises(TypeError):
create_host_config(version='1.25', cpu_rt_runtime='1000')
def test_create_host_config_with_cpu_rt_runtime(self):
config = create_host_config(version='1.25', cpu_rt_runtime=1000)
self.assertEqual(config.get('CPURealtimeRuntime'), 1000)
self.assertRaises(
InvalidVersion, lambda: create_host_config(
version='1.24', cpu_rt_runtime=1000))
class ContainerConfigTest(unittest.TestCase):
def test_create_container_config_volume_driver_warning(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment