Skip to content

Commit ba38383

Browse files
committed
tests: add rootless integration tests
This adds targets for rootless integration tests, as well as all of the required setup in order to get the tests to run. This includes quite a few changes, because of a lot of assumptions about things running as root within the bats scripts (which is not true when setting up rootless containers). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 2ce3357 commit ba38383

File tree

14 files changed

+117
-24
lines changed

14 files changed

+117
-24
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/a
66
RUN apt-get update && apt-get install -y \
77
build-essential \
88
curl \
9+
sudo \
910
gawk \
1011
iptables \
1112
jq \
@@ -22,6 +23,12 @@ RUN apt-get update && apt-get install -y \
2223
--no-install-recommends \
2324
&& apt-get clean
2425

26+
# Add a dummy user for the rootless integration tests. While runC does
27+
# not require an entry in /etc/passwd to operate, one of the tests uses
28+
# `git clone` -- and `git clone` does not allow you to clone a
29+
# repository if the current uid does not have an entry in /etc/passwd.
30+
RUN useradd -u1000 -m -d/home/rootless -s/bin/bash rootless
31+
2532
# install bats
2633
RUN cd /tmp \
2734
&& git clone https://github.com/sstephenson/bats.git \

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ runcimage:
7979
docker build -t $(RUNC_IMAGE) .
8080

8181
test:
82-
make unittest integration
82+
make unittest integration rootlessintegration
8383

8484
localtest:
85-
make localunittest localintegration
85+
make localunittest localintegration localrootlessintegration
8686

8787
unittest: runcimage
8888
docker run -e TESTFLAGS -t --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) make localunittest
@@ -96,6 +96,13 @@ integration: runcimage
9696
localintegration: all
9797
bats -t tests/integration${TESTFLAGS}
9898

99+
rootlessintegration: runcimage
100+
docker run -e TESTFLAGS -t --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) --cap-drop=ALL -u rootless $(RUNC_IMAGE) make localintegration
101+
102+
# FIXME: This should not be separate from rootlessintegration's method of running.
103+
localrootlessintegration: all
104+
sudo -u rootless -H PATH="${PATH}" bats -t tests/integration${TESTFLAGS}
105+
99106
shell: all
100107
docker run -e TESTFLAGS -ti --privileged --rm -v $(CURDIR):/go/src/$(PROJECT) $(RUNC_IMAGE) bash
101108

tests/integration/checkpoint.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ function teardown() {
5959
[[ "${output}" == *"running"* ]]
6060
}
6161

62-
@test "checkpoint(pre-dump) and restore" {
63-
requires criu
62+
@test "checkpoint --pre-dump and restore" {
63+
# XXX: currently criu require root containers.
64+
requires criu root
6465

6566
# criu does not work with external terminals so..
6667
# setting terminal and root:readonly: to false

tests/integration/delete.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ function teardown() {
2222
testcontainer test_busybox running
2323

2424
runc kill test_busybox KILL
25+
[ "$status" -eq 0 ]
2526
# wait for busybox to be in the destroyed state
2627
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
2728

2829
# delete test_busybox
2930
runc delete test_busybox
31+
[ "$status" -eq 0 ]
3032

3133
runc state test_busybox
3234
[ "$status" -ne 0 ]

tests/integration/events.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ function teardown() {
1212
}
1313

1414
@test "events --stats" {
15+
# XXX: currently cgroups require root containers.
16+
requires root
17+
1518
# run busybox detached
1619
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
1720
[ "$status" -eq 0 ]
@@ -27,6 +30,9 @@ function teardown() {
2730
}
2831

2932
@test "events --interval default " {
33+
# XXX: currently cgroups require root containers.
34+
requires root
35+
3036
# run busybox detached
3137
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
3238
[ "$status" -eq 0 ]
@@ -54,6 +60,9 @@ function teardown() {
5460
}
5561

5662
@test "events --interval 1s " {
63+
# XXX: currently cgroups require root containers.
64+
requires root
65+
5766
# run busybox detached
5867
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
5968
[ "$status" -eq 0 ]
@@ -80,6 +89,9 @@ function teardown() {
8089
}
8190

8291
@test "events --interval 100ms " {
92+
# XXX: currently cgroups require root containers.
93+
requires root
94+
8395
# run busybox detached
8496
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
8597
[ "$status" -eq 0 ]

tests/integration/exec.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ function teardown() {
112112
}
113113

114114
@test "runc exec --user" {
115+
# --user can't work in rootless containers
116+
requires root
117+
115118
# run busybox detached
116119
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
117120
[ "$status" -eq 0 ]

tests/integration/help.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ load helpers
5757
[ "$status" -eq 0 ]
5858
[[ ${lines[1]} =~ runc\ resume+ ]]
5959

60+
# We don't use runc_spec here, because we're just testing the help page.
6061
runc spec -h
6162
[ "$status" -eq 0 ]
6263
[[ ${lines[1]} =~ runc\ spec+ ]]

tests/integration/helpers.bash

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
55
RUNC="${INTEGRATION_ROOT}/../../runc"
66
RECVTTY="${INTEGRATION_ROOT}/../../contrib/cmd/recvtty/recvtty"
7-
GOPATH="${INTEGRATION_ROOT}/../../../.."
7+
GOPATH="$(mktemp -d --tmpdir runc-integration-gopath.XXXXXX)"
88

99
# Test data path.
1010
TESTDATA="${INTEGRATION_ROOT}/testdata"
@@ -27,7 +27,7 @@ KERNEL_MINOR="${KERNEL_VERSION#$KERNEL_MAJOR.}"
2727
KERNEL_MINOR="${KERNEL_MINOR%%.*}"
2828

2929
# Root state path.
30-
ROOT="$BATS_TMPDIR/runc"
30+
ROOT=$(mktemp -d "$BATS_TMPDIR/runc.XXXXXX")
3131

3232
# Path to console socket.
3333
CONSOLE_SOCKET="$BATS_TMPDIR/console.sock"
@@ -58,6 +58,17 @@ function __runc() {
5858
"$RUNC" --root "$ROOT" "$@"
5959
}
6060

61+
# Wrapper for runc spec.
62+
function runc_spec() {
63+
local args=""
64+
65+
if [ "$ROOTLESS" -ne 0 ]; then
66+
args+="--rootless"
67+
fi
68+
69+
runc spec $args "$@"
70+
}
71+
6172
# Fails the current test, providing the error given.
6273
function fail() {
6374
echo "$@" >&2
@@ -187,18 +198,18 @@ function setup_busybox() {
187198
if [ ! -e $BUSYBOX_IMAGE ]; then
188199
curl -o $BUSYBOX_IMAGE -sSL 'https://github.com/docker-library/busybox/raw/a0558a9006ce0dd6f6ec5d56cfd3f32ebeeb815f/glibc/busybox.tar.xz'
189200
fi
190-
tar -C "$BUSYBOX_BUNDLE"/rootfs -xf "$BUSYBOX_IMAGE"
201+
tar --exclude './dev/*' -C "$BUSYBOX_BUNDLE"/rootfs -xf "$BUSYBOX_IMAGE"
191202
cd "$BUSYBOX_BUNDLE"
192-
runc spec
203+
runc_spec
193204
}
194205

195206
function setup_hello() {
196207
setup_recvtty
197208
run mkdir "$HELLO_BUNDLE"
198209
run mkdir "$HELLO_BUNDLE"/rootfs
199-
tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
210+
tar --exclude './dev/*' -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
200211
cd "$HELLO_BUNDLE"
201-
runc spec
212+
runc_spec
202213
sed -i 's;"sh";"/hello";' config.json
203214
}
204215

tests/integration/ps.bats

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ function teardown() {
1212
}
1313

1414
@test "ps" {
15+
# ps is not supported, it requires cgroups
16+
requires root
17+
1518
# start busybox detached
1619
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
1720
[ "$status" -eq 0 ]
@@ -24,10 +27,13 @@ function teardown() {
2427
runc ps test_busybox
2528
[ "$status" -eq 0 ]
2629
[[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
27-
[[ "${lines[1]}" == *"root"*[0-9]* ]]
30+
[[ "${lines[1]}" == *"$(id -un 2>/dev/null)"*[0-9]* ]]
2831
}
2932

3033
@test "ps -f json" {
34+
# ps is not supported, it requires cgroups
35+
requires root
36+
3137
# start busybox detached
3238
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
3339
[ "$status" -eq 0 ]
@@ -43,6 +49,9 @@ function teardown() {
4349
}
4450

4551
@test "ps -e -x" {
52+
# ps is not supported, it requires cgroups
53+
requires root
54+
4655
# start busybox detached
4756
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
4857
[ "$status" -eq 0 ]

tests/integration/spec.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function teardown() {
2626
[ ! -e config.json ]
2727

2828
# test generation of spec does not return an error
29-
runc spec
29+
runc_spec
3030
[ "$status" -eq 0 ]
3131

3232
# test generation of spec created our config.json (spec)
@@ -51,7 +51,7 @@ function teardown() {
5151
[ ! -e "$HELLO_BUNDLE"/config.json ]
5252

5353
# test generation of spec does not return an error
54-
runc spec --bundle "$HELLO_BUNDLE"
54+
runc_spec --bundle "$HELLO_BUNDLE"
5555
[ "$status" -eq 0 ]
5656

5757
# test generation of spec created our config.json (spec)

0 commit comments

Comments
 (0)