Skip to content

Commit 3caaa00

Browse files
mohitsonishin-
authored andcommitted
Added support for cgroup parent
Clean up cgroup_parent usage
1 parent 4008cbc commit 3caaa00

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

docker/utils/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def create_host_config(
395395
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
396396
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
397397
security_opt=None, ulimits=None, log_config=None, mem_limit=None,
398-
memswap_limit=None
398+
memswap_limit=None, cgroup_parent=None
399399
):
400400
host_config = {}
401401

@@ -500,6 +500,9 @@ def create_host_config(
500500
if lxc_conf is not None:
501501
host_config['LxcConf'] = lxc_conf
502502

503+
if cgroup_parent is not None:
504+
host_config['CgroupParent'] = cgroup_parent
505+
503506
if ulimits is not None:
504507
if not isinstance(ulimits, list):
505508
raise errors.DockerException(

tests/test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,24 @@ def test_create_container_with_cpuset(self):
492492
self.assertEqual(args[1]['headers'],
493493
{'Content-Type': 'application/json'})
494494

495+
def test_create_container_with_cgroup_parent(self):
496+
try:
497+
self.client.create_container(
498+
'busybox', 'ls', host_config=create_host_config(
499+
cgroup_parent='test'
500+
)
501+
)
502+
except Exception as e:
503+
self.fail('Command should not raise exception: {0}'.format(e))
504+
505+
args = fake_request.call_args
506+
self.assertEqual(args[0][0],
507+
url_prefix + 'containers/create')
508+
data = json.loads(args[1]['data'])
509+
self.assertIn('HostConfig', data)
510+
self.assertIn('CgroupParent', data['HostConfig'])
511+
self.assertEqual(data['HostConfig']['CgroupParent'], 'test')
512+
495513
def test_create_container_with_working_dir(self):
496514
try:
497515
self.client.create_container('busybox', 'ls',

0 commit comments

Comments
 (0)