Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests:cgroups: tests for cgroups package #401

Merged
merged 7 commits into from
Sep 15, 2022
Merged

Conversation

tixxdz
Copy link
Member

@tixxdz tixxdz commented Sep 13, 2022

No description provided.

@tixxdz tixxdz requested a review from a team as a code owner September 13, 2022 08:37
@tixxdz tixxdz requested a review from willfindlay September 13, 2022 08:37
@tixxdz tixxdz changed the title tests:cgroups: more tests for cgroups package tests:cgroups: tests for cgroups package Sep 13, 2022
@tixxdz tixxdz closed this Sep 13, 2022
@tixxdz tixxdz force-pushed the pr/tixxdz/cgroup-tests-batch1 branch from f133f45 to 38149e5 Compare September 13, 2022 09:12
@tixxdz tixxdz reopened this Sep 13, 2022
@tixxdz tixxdz force-pushed the pr/tixxdz/cgroup-tests-batch1 branch from d650b57 to 836ff86 Compare September 13, 2022 09:29
This asserts that TetragonConf and bpf tetragon_conf are aligned properly.

Signed-off-by: Djalal Harouni <[email protected]>
Add unit tests to assert that cgroup mode can be one of the following:
CGROUP_UNDEF    = 0  Can't determin Cgroup mode
CGROUP_LEGACY   = 1  Cgroup is in pure lagacy mode (only cgroupv1 is mounted)
CGROUP_HYBRID   = 2  Cgroup is in hybrid mode, cgroupv1 is default and systemd
                     mounted a cgroupv2 hierarchy at /sys/fs/cgroup/unified
                     to organize units and processes. Container runtimes and
                     kubernetes may use this or not... depends on their
                     configuration.
CGROUP_UNIFIED  = 3  Cgroupv2 is the default mode, pure unified hierarchy.

We follow systemd cgroup setup: https://systemd.io/CGROUP_DELEGATION/, however
our cgroup package should work on non-systemd setups assuming they setup
cgroups on the default location /sys/fs/cgroup

We add two tests:
- TestDetectCgroupModeInvalid() that runs the test on an invalid directory to
  assert that returned value contains errors and the mode is CGROUP_UNDEF

- TestDetectCgroupModeDefault() that tests the default cgroup root location
  /sys/fs/cgroup and tries to guess what is the mode according to it.

Signed-off-by: Djalal Harouni <[email protected]>
This tests the detect cgroup mode logic on our custom location
where we mount Cgroup2: /run/tetragon/cgroup2

Signed-off-by: Djalal Harouni <[email protected]>
This runs DetectCgroupMode() helpers and asserts that global cgroup
vars are set: cgroupMode and cgroupFSPath.

These vars are set only once, the first time when we run the detection,
second call we just return them, so assert they are properly set during
first call.

Signed-off-by: Djalal Harouni <[email protected]>
Add test to assert:

- Cgroup FS magic detection. This will run DetectCgroupFSMagic() that
  returns the fs magic number.

- Assert that cgroupMode is also properly set, since DetectCgroupFSMagic()
  will automatically run DetectCgroupMode(). We have to do this to properly
  detect all the cgroup setups variants. Statfs() the filesystem only will
  not work.

Signed-off-by: Djalal Harouni <[email protected]>
@tixxdz tixxdz force-pushed the pr/tixxdz/cgroup-tests-batch1 branch from 836ff86 to 68df622 Compare September 13, 2022 11:36
This test will perform:
- Assert discovery of compiled-in Cgroups controllers.
- Assert that we properly setup their hierarchy ID
- Assert that we properly setup their cgroup subsystem state index.

Signed-off-by: Djalal Harouni <[email protected]>
@tixxdz tixxdz force-pushed the pr/tixxdz/cgroup-tests-batch1 branch from 68df622 to 5e24ce8 Compare September 13, 2022 13:47
@kkourt kkourt merged commit c368e6f into main Sep 15, 2022
@kkourt kkourt deleted the pr/tixxdz/cgroup-tests-batch1 branch September 15, 2022 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants