Skip to content

Commit 2fd20e4

Browse files
committed
test(jailer): add test to check solitary --parent-cgroup
Tests that --parent-cgroup without any cgroups moves Firecracker to the cgroup (cgroupsv2 only). Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 27a19fe commit 2fd20e4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/framework/jailer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(
7272
self.new_pid_ns = new_pid_ns
7373
self.extra_args = extra_args
7474
self.api_socket_name = DEFAULT_USOCKET_NAME
75-
self.cgroups = cgroups
75+
self.cgroups = cgroups or []
7676
self.resource_limits = resource_limits
7777
self.cgroup_ver = cgroup_ver
7878
self.parent_cgroup = parent_cgroup
@@ -112,7 +112,7 @@ def construct_param_list(self):
112112
jailer_param_list.extend(["--parent-cgroup", str(self.parent_cgroup)])
113113
if self.cgroup_ver:
114114
jailer_param_list.extend(["--cgroup-version", str(self.cgroup_ver)])
115-
if self.cgroups is not None:
115+
if self.cgroups:
116116
for cgroup in self.cgroups:
117117
jailer_param_list.extend(["--cgroup", str(cgroup)])
118118
if self.resource_limits is not None:

tests/integration_tests/security/test_jail.py

+25
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ def check_cgroups_v2(vm):
249249
parent_cgroup = FC_BINARY_NAME
250250
cg_parent = cg.root / parent_cgroup
251251
cg_jail = cg_parent / vm.jailer.jailer_id
252+
253+
# if no cgroups were specified, then the jailer should move the FC process
254+
# to the parent group
255+
if len(vm.jailer.cgroups) == 0:
256+
procs = cg_parent.joinpath("cgroup.procs").read_text().splitlines()
257+
assert str(vm.firecracker_pid) in procs
258+
252259
for cgroup in vm.jailer.cgroups:
253260
controller = cgroup.split(".")[0]
254261
file_name, value = cgroup.split("=")
@@ -406,6 +413,24 @@ def test_v1_default_cgroups(test_microvm_with_api, cgroups_info):
406413
check_cgroups_v1(test_microvm.jailer.cgroups, test_microvm.jailer.jailer_id)
407414

408415

416+
def test_cgroups_custom_parent_move(test_microvm_with_api, cgroups_info):
417+
"""
418+
Test cgroups when a custom parent cgroup is used and no cgroups are specified
419+
420+
In this case we just want to move under the parent cgroup
421+
"""
422+
if cgroups_info.version != 2:
423+
pytest.skip("cgroupsv2 only")
424+
test_microvm = test_microvm_with_api
425+
test_microvm.jailer.cgroup_ver = cgroups_info.version
426+
# Make it somewhat unique so it doesn't conflict with other test runs
427+
parent_cgroup = f"custom_cgroup/{test_microvm.id[:8]}"
428+
test_microvm.jailer.parent_cgroup = parent_cgroup
429+
430+
cgroups_info.new_cgroup(parent_cgroup)
431+
test_microvm.spawn()
432+
check_cgroups_v2(test_microvm)
433+
409434

410435
def test_args_default_resource_limits(test_microvm_with_api):
411436
"""

0 commit comments

Comments
 (0)