Skip to content

Commit 67f12bd

Browse files
authored
Merge pull request #1583 from delcypher/cpuset_fixes
CPUset* parameter fixes
2 parents 35b8c0a + 2a0a7ad commit 67f12bd

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

docker/api/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ def create_host_config(self, *args, **kwargs):
479479
cpu_shares (int): CPU shares (relative weight).
480480
cpuset_cpus (str): CPUs in which to allow execution (``0-3``,
481481
``0,1``).
482+
cpuset_mems (str): Memory nodes (MEMs) in which to allow execution
483+
(``0-3``, ``0,1``). Only effective on NUMA systems.
482484
device_read_bps: Limit read rate (bytes per second) from a device
483485
in the form of: `[{"Path": "device_path", "Rate": rate}]`
484486
device_read_iops: Limit read rate (IO per second) from a device.

docker/models/containers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ def run(self, image, command=None, stdout=True, stderr=False,
483483
cpu_shares (int): CPU shares (relative weight).
484484
cpuset_cpus (str): CPUs in which to allow execution (``0-3``,
485485
``0,1``).
486+
cpuset_mems (str): Memory nodes (MEMs) in which to allow execution
487+
(``0-3``, ``0,1``). Only effective on NUMA systems.
486488
detach (bool): Run container in the background and return a
487489
:py:class:`Container` object.
488490
device_read_bps: Limit read rate (bytes per second) from a device
@@ -829,6 +831,7 @@ def prune(self, filters=None):
829831
'cpu_quota',
830832
'cpu_shares',
831833
'cpuset_cpus',
834+
'cpuset_mems',
832835
'device_read_bps',
833836
'device_read_iops',
834837
'device_write_bps',

docker/types/containers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def __init__(self, version, binds=None, port_bindings=None,
119119
cpuset_cpus=None, userns_mode=None, pids_limit=None,
120120
isolation=None, auto_remove=False, storage_opt=None,
121121
init=None, init_path=None, volume_driver=None,
122-
cpu_count=None, cpu_percent=None, nano_cpus=None):
122+
cpu_count=None, cpu_percent=None, nano_cpus=None,
123+
cpuset_mems=None):
123124

124125
if mem_limit is not None:
125126
self['Memory'] = parse_bytes(mem_limit)
@@ -326,7 +327,17 @@ def __init__(self, version, binds=None, port_bindings=None,
326327
if version_lt(version, '1.18'):
327328
raise host_config_version_error('cpuset_cpus', '1.18')
328329

329-
self['CpuSetCpus'] = cpuset_cpus
330+
self['CpusetCpus'] = cpuset_cpus
331+
332+
if cpuset_mems:
333+
if version_lt(version, '1.19'):
334+
raise host_config_version_error('cpuset_mems', '1.19')
335+
336+
if not isinstance(cpuset_mems, str):
337+
raise host_config_type_error(
338+
'cpuset_mems', cpuset_mems, 'str'
339+
)
340+
self['CpusetMems'] = cpuset_mems
330341

331342
if blkio_weight:
332343
if not isinstance(blkio_weight, int):

tests/unit/api_container_test.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,34 @@ def test_create_container_with_host_config_cpuset(self):
332332
"StdinOnce": false,
333333
"NetworkDisabled": false,
334334
"HostConfig": {
335-
"CpuSetCpus": "0,1",
335+
"CpusetCpus": "0,1",
336+
"NetworkMode": "default"
337+
}}'''))
338+
self.assertEqual(args[1]['headers'],
339+
{'Content-Type': 'application/json'})
340+
341+
@requires_api_version('1.19')
342+
def test_create_container_with_host_config_cpuset_mems(self):
343+
self.client.create_container(
344+
'busybox', 'ls', host_config=self.client.create_host_config(
345+
cpuset_mems='0'
346+
)
347+
)
348+
349+
args = fake_request.call_args
350+
self.assertEqual(args[0][1],
351+
url_prefix + 'containers/create')
352+
353+
self.assertEqual(json.loads(args[1]['data']),
354+
json.loads('''
355+
{"Tty": false, "Image": "busybox",
356+
"Cmd": ["ls"], "AttachStdin": false,
357+
"AttachStderr": true,
358+
"AttachStdout": true, "OpenStdin": false,
359+
"StdinOnce": false,
360+
"NetworkDisabled": false,
361+
"HostConfig": {
362+
"CpusetMems": "0",
336363
"NetworkMode": "default"
337364
}}'''))
338365
self.assertEqual(args[1]['headers'],

tests/unit/models_containers_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_create_container_args(self):
135135
'CpuPeriod': 1,
136136
'CpuQuota': 2,
137137
'CpuShares': 5,
138-
'CpuSetCpus': '0-3',
138+
'CpusetCpus': '0-3',
139139
'Devices': [{'PathOnHost': '/dev/sda',
140140
'CgroupPermissions': 'rwm',
141141
'PathInContainer': '/dev/xvda'}],

0 commit comments

Comments
 (0)