22
33load helpers
44
5- TEST_CGROUP_NAME=" runc-cgroups-integration-test"
6- CGROUP_MEMORY=" ${CGROUP_MEMORY_BASE_PATH} /${TEST_CGROUP_NAME} "
7-
85function teardown() {
9- rm -f $BATS_TMPDIR /runc-update -integration-test.json
6+ rm -f $BATS_TMPDIR /runc-cgroups -integration-test.json
107 teardown_running_container test_cgroups_kmem
8+ teardown_running_container test_cgroups_permissions
119 teardown_busybox
1210}
1311
@@ -28,11 +26,10 @@ function check_cgroup_value() {
2826}
2927
3028@test " runc update --kernel-memory (initialized)" {
31- # XXX: currently cgroups require root containers.
32- requires cgroups_kmem root
29+ [[ " $ROOTLESS " -ne 0 ]] && requires rootless_cgroup
30+ requires cgroups_kmem
3331
34- # Add cgroup path
35- sed -i ' s/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE} /config.json
32+ set_cgroups_path " $BUSYBOX_BUNDLE "
3633
3734 # Set some initial known values
3835 DATA=$( cat << -EOF
5754}
5855
5956@test " runc update --kernel-memory (uninitialized)" {
60- # XXX: currently cgroups require root containers.
61- requires cgroups_kmem root
57+ [[ " $ROOTLESS " -ne 0 ]] && requires rootless_cgroup
58+ requires cgroups_kmem
6259
63- # Add cgroup path
64- sed -i ' s/\("linux": {\)/\1\n "cgroupsPath": "\/runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE} /config.json
60+ set_cgroups_path " $BUSYBOX_BUNDLE "
6561
6662 # run a detached busybox to work with
6763 runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_kmem
7874 check_cgroup_value $CGROUP_MEMORY " memory.kmem.limit_in_bytes" 50331648
7975 fi
8076}
77+
78+ @test " runc create (no limits + no cgrouppath + no permission) succeeds" {
79+ runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_permissions
80+ [ " $status " -eq 0 ]
81+ }
82+
83+ @test " runc create (rootless + no limits + cgrouppath + no permission) fails with permission error" {
84+ requires rootless
85+ requires rootless_no_cgroup
86+
87+ set_cgroups_path " $BUSYBOX_BUNDLE "
88+
89+ runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_permissions
90+ [ " $status " -eq 1 ]
91+ [[ ${lines[1]} == * " permission denied" * ]]
92+ }
93+
94+ @test " runc create (rootless + limits + no cgrouppath + no permission) fails with informative error" {
95+ requires rootless
96+ requires rootless_no_cgroup
97+
98+ set_resources_limit " $BUSYBOX_BUNDLE "
99+
100+ runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_permissions
101+ [ " $status " -eq 1 ]
102+ [[ ${lines[1]} == * " cannot set limits on the pids cgroup, as the container has not joined it" * ]]
103+ }
104+
105+ @test " runc create (limits + cgrouppath + permission on the cgroup dir) succeeds" {
106+ [[ " $ROOTLESS " -ne 0 ]] && requires rootless_cgroup
107+
108+ set_cgroups_path " $BUSYBOX_BUNDLE "
109+ set_resources_limit " $BUSYBOX_BUNDLE "
110+
111+ runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_permissions
112+ [ " $status " -eq 0 ]
113+ }
114+
115+ @test " runc exec (limits + cgrouppath + permission on the cgroup dir) succeeds" {
116+ [[ " $ROOTLESS " -ne 0 ]] && requires rootless_cgroup
117+
118+ set_cgroups_path " $BUSYBOX_BUNDLE "
119+ set_resources_limit " $BUSYBOX_BUNDLE "
120+
121+ runc run -d --console-socket $CONSOLE_SOCKET test_cgroups_permissions
122+ [ " $status " -eq 0 ]
123+
124+ runc exec test_cgroups_permissions echo " cgroups_exec"
125+ [ " $status " -eq 0 ]
126+ [[ ${lines[0]} == * " cgroups_exec" * ]]
127+ }
0 commit comments