...

Text file src/github.com/opencontainers/runc/tests/integration/hooks.bats

Documentation: github.com/opencontainers/runc/tests/integration

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

View as plain text