@@ -249,6 +249,13 @@ def check_cgroups_v2(vm):
249
249
parent_cgroup = FC_BINARY_NAME
250
250
cg_parent = cg .root / parent_cgroup
251
251
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
+
252
259
for cgroup in vm .jailer .cgroups :
253
260
controller = cgroup .split ("." )[0 ]
254
261
file_name , value = cgroup .split ("=" )
@@ -406,6 +413,24 @@ def test_v1_default_cgroups(test_microvm_with_api, cgroups_info):
406
413
check_cgroups_v1 (test_microvm .jailer .cgroups , test_microvm .jailer .jailer_id )
407
414
408
415
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
+
409
434
410
435
def test_args_default_resource_limits (test_microvm_with_api ):
411
436
"""
0 commit comments