forked from adamlaska/runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.bats
More file actions
59 lines (47 loc) · 1.88 KB
/
hooks.bats
File metadata and controls
59 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bats
load helpers
function setup() {
requires root no_systemd
setup_debian
# CR = CreateRuntime, CC = CreateContainer
HOOKLIBCR=librunc-hooks-create-runtime.so
HOOKLIBCC=librunc-hooks-create-container.so
LIBPATH="$(pwd)/rootfs/lib/"
}
function teardown() {
if [ -v LIBPATH ]; then
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0
unset LIBPATH HOOKLIBCR HOOKLIBCC
fi
teardown_bundle
}
@test "runc run (hooks library tests)" {
# setup some dummy libs
gcc -shared -Wl,-soname,librunc-hooks-create-runtime.so.1 -o "$HOOKLIBCR.1.0.0"
gcc -shared -Wl,-soname,librunc-hooks-create-container.so.1 -o "$HOOKLIBCC.1.0.0"
bundle=$(pwd)
# To mount $HOOKLIBCR we need to do that in the container namespace
create_runtime_hook=$(
cat <<-EOF
pid=\$(cat - | jq -r '.pid')
touch "$LIBPATH/$HOOKLIBCR.1.0.0"
nsenter -m \$ns -t \$pid mount --bind "$bundle/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0"
EOF
)
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $bundle/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
# shellcheck disable=SC2016
update_config --arg create_runtime_hook "$create_runtime_hook" --arg create_container_hook "$create_container_hook" '
.hooks |= . + {"createRuntime": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_runtime_hook]}]} |
.hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} |
.hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} |
.root.readonly |= false |
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]'
runc run test_debian
[ "$status" -eq 0 ]
echo "Checking create-runtime library"
echo "$output" | grep $HOOKLIBCR
echo "Checking create-container library"
echo "$output" | grep $HOOKLIBCC
}