Skip to content

Commit 19f76b6

Browse files
kolyshkinlifubang
authored andcommitted
tests/int/ps: enable for rootless
runc ps requires cgroup, but all the tests but one required root. Let's fix this. 1. Add rootless cgroup requirement to setup() to avoid repetition. 2. Add set_cgroups_path to setup() for rootless containers because there is no default cgroup path. 3. Modify output checks to use $output rather than $lines because in case of rootless the first line of output contains the following warning: > runc ps may fail if you don't have the full access to cgroups 4. While at it, move the common part of every test (creating the container and making sure it's running) to setup(). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent c99e6c6 commit 19f76b6

File tree

1 file changed

+15
-46
lines changed

1 file changed

+15
-46
lines changed

tests/integration/ps.bats

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,44 @@
33
load helpers
44

55
function setup() {
6+
# ps requires cgroups
7+
[ $EUID -ne 0 ] && requires rootless_cgroup
8+
69
setup_busybox
10+
11+
# Rootless does not have default cgroup path.
12+
[ $EUID -ne 0 ] && set_cgroups_path
13+
14+
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
15+
[ "$status" -eq 0 ]
16+
testcontainer test_busybox running
717
}
818

919
function teardown() {
1020
teardown_bundle
1121
}
1222

1323
@test "ps" {
14-
# ps is not supported, it requires cgroups
15-
requires root
16-
17-
# start busybox detached
18-
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
19-
[ "$status" -eq 0 ]
20-
21-
# check state
22-
testcontainer test_busybox running
23-
2424
runc ps test_busybox
2525
[ "$status" -eq 0 ]
26-
[[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
27-
[[ "${lines[1]}" == *"$(id -un 2>/dev/null)"*[0-9]* ]]
26+
[[ "$output" =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
27+
[[ "$output" == *"$(id -un 2>/dev/null)"*[0-9]* ]]
2828
}
2929

3030
@test "ps -f json" {
31-
# ps is not supported, it requires cgroups
32-
requires root
33-
34-
# start busybox detached
35-
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
36-
[ "$status" -eq 0 ]
37-
38-
# check state
39-
testcontainer test_busybox running
40-
4131
runc ps -f json test_busybox
4232
[ "$status" -eq 0 ]
43-
[[ ${lines[0]} =~ [0-9]+ ]]
33+
[[ "$output" =~ [0-9]+ ]]
4434
}
4535

4636
@test "ps -e -x" {
47-
# ps is not supported, it requires cgroups
48-
requires root
49-
50-
# start busybox detached
51-
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
52-
[ "$status" -eq 0 ]
53-
54-
# check state
55-
testcontainer test_busybox running
56-
5737
runc ps test_busybox -e -x
5838
[ "$status" -eq 0 ]
59-
[[ ${lines[0]} =~ \ +PID\ +TTY\ +STAT\ +TIME\ +COMMAND+ ]]
60-
[[ "${lines[1]}" =~ [0-9]+ ]]
39+
[[ "$output" =~ \ +PID\ +TTY\ +STAT\ +TIME\ +COMMAND+ ]]
40+
[[ "$output" =~ [0-9]+ ]]
6141
}
6242

6343
@test "ps after the container stopped" {
64-
# ps requires cgroups
65-
[ $EUID -ne 0 ] && requires rootless_cgroup
66-
set_cgroups_path
67-
68-
# start busybox detached
69-
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
70-
[ "$status" -eq 0 ]
71-
72-
# check state
73-
testcontainer test_busybox running
74-
7544
runc ps test_busybox
7645
[ "$status" -eq 0 ]
7746

0 commit comments

Comments
 (0)