|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +# CR = CreateRuntime |
| 6 | +# CC = CreataContainer |
| 7 | +HOOKLIBCR=librunc-hooks-create-runtime.so |
| 8 | +HOOKLIBCC=librunc-hooks-create-container.so |
| 9 | +LIBPATH="$DEBIAN_BUNDLE/rootfs/lib/" |
| 10 | + |
| 11 | +function setup() { |
| 12 | + umount $LIBPATH/$HOOKLIBCR.1.0.0 &> /dev/null || true |
| 13 | + umount $LIBPATH/$HOOKLIBCC.1.0.0 &> /dev/null || true |
| 14 | + |
| 15 | + teardown_debian |
| 16 | + setup_debian |
| 17 | +} |
| 18 | + |
| 19 | +function teardown() { |
| 20 | + umount $LIBPATH/$HOOKLIBCR.1.0.0 &> /dev/null || true |
| 21 | + umount $LIBPATH/$HOOKLIBCC.1.0.0 &> /dev/null || true |
| 22 | + |
| 23 | + rm -f $HOOKLIBCR.1.0.0 $HOOKLIBCC.1.0.0 |
| 24 | + teardown_debian |
| 25 | +} |
| 26 | + |
| 27 | +@test "runc run (hooks library tests)" { |
| 28 | + requires root |
| 29 | + requires no_systemd |
| 30 | + |
| 31 | + # setup some dummy libs |
| 32 | + gcc -shared -Wl,-soname,librunc-hooks-create-runtime.so.1 -o "$HOOKLIBCR.1.0.0" |
| 33 | + gcc -shared -Wl,-soname,librunc-hooks-create-container.so.1 -o "$HOOKLIBCC.1.0.0" |
| 34 | + |
| 35 | + current_pwd="$(pwd)" |
| 36 | + |
| 37 | + # To mount $HOOKLIBCR we need to do that in the container namespace |
| 38 | + create_runtime_hook=$(cat <<-EOF |
| 39 | + pid=\$(cat - | jq -r '.pid') |
| 40 | + touch "$LIBPATH/$HOOKLIBCR.1.0.0" |
| 41 | + nsenter -m \$ns -t \$pid mount --bind "$current_pwd/$HOOKLIBCR.1.0.0" "$LIBPATH/$HOOKLIBCR.1.0.0" |
| 42 | + EOF) |
| 43 | +
|
| 44 | + create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $current_pwd/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0" |
| 45 | +
|
| 46 | + CONFIG=$(jq --arg create_runtime_hook "$create_runtime_hook" --arg create_container_hook "$create_container_hook" ' |
| 47 | + .hooks |= . + {"createRuntime": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_runtime_hook]}]} | |
| 48 | + .hooks |= . + {"createContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", $create_container_hook]}]} | |
| 49 | + .hooks |= . + {"startContainer": [{"path": "/bin/sh", "args": ["/bin/sh", "-c", "ldconfig"]}]} | |
| 50 | + .process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' $DEBIAN_BUNDLE/config.json) |
| 51 | + echo "${CONFIG}" > config.json |
| 52 | +
|
| 53 | + runc run test_debian |
| 54 | + [ "$status" -eq 0 ] |
| 55 | +
|
| 56 | + echo "Checking create-runtime library" |
| 57 | + echo $output | grep $HOOKLIBCR |
| 58 | + [ "$?" -eq 0 ] |
| 59 | +
|
| 60 | + echo "Checking create-container library" |
| 61 | + echo $output | grep $HOOKLIBCC |
| 62 | + [ "$?" -eq 0 ] |
| 63 | +} |
0 commit comments