Skip to content

Commit d8e873e

Browse files
Trăistaru Andrei Cristianpb8o
authored andcommitted
chore: enhance cgroupv2 checking
On Ubuntu 22 we have cgroupv2 enabled by default. Thus, we no longer need to add the `cgroup_no_v1=all` flag in the cmdline to enforce cgroupv2. This resulted in a wrong detection of cgroup version by just looking into the cmdline. According to docs, existence of /sys/fs/cgroup/cgroup.controllers should be a marker of cgroupsv2 enabled. Signed-off-by: Trăistaru Andrei Cristian <[email protected]>
1 parent a5a6a9b commit d8e873e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

tests/integration_tests/security/test_jail.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,10 @@ def test_arbitrary_usocket_location(test_microvm_with_initrd):
218218

219219

220220
@functools.lru_cache(maxsize=None)
221-
def cgroup_v1_available():
222-
"""Check if cgroup-v1 is disabled on the system."""
223-
with open("/proc/cmdline", encoding="utf-8") as cmdline_file:
224-
cmdline = cmdline_file.readline()
225-
return bool("cgroup_no_v1=all" not in cmdline)
221+
def cgroup_v2_available():
222+
"""Check if cgroup-v2 is enabled on the system."""
223+
# https://rootlesscontaine.rs/getting-started/common/cgroup2/#checking-whether-cgroup-v2-is-already-enabled
224+
return os.path.isfile("/sys/fs/cgroup/cgroup.controllers")
226225

227226

228227
@pytest.fixture
@@ -234,7 +233,7 @@ def sys_setup_cgroups():
234233
This set-up is important to do when running from inside a Docker
235234
container while the system is using cgroup-v2.
236235
"""
237-
cgroup_version = 1 if cgroup_v1_available() else 2
236+
cgroup_version = 2 if cgroup_v2_available() else 1
238237
if cgroup_version == 2:
239238
# Cgroup-v2 adds a no internal process constraint which means that
240239
# non-root cgroups can distribute domain resources to their children
@@ -510,7 +509,7 @@ def test_cgroups_without_numa(test_microvm_with_initrd, sys_setup_cgroups):
510509

511510

512511
@pytest.mark.skipif(
513-
cgroup_v1_available() is False, reason="Requires system with cgroup-v1 enabled."
512+
cgroup_v2_available() is True, reason="Requires system with cgroup-v1 enabled."
514513
)
515514
@pytest.mark.usefixtures("sys_setup_cgroups")
516515
def test_v1_default_cgroups(test_microvm_with_initrd):

0 commit comments

Comments
 (0)