mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests/int/hooks.bats: don't use DEBIAN_BUNDLE
1. Do not depend on $DEBIAN_BUNDLE, instead use the current directory. 2. Simplify setup() by calling teardown(). 3. In teardown(), check that LIBPATH is set. 4. Move global variables into setup. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -2,27 +2,23 @@
|
||||
|
||||
load helpers
|
||||
|
||||
# CR = CreateRuntime
|
||||
# CC = CreataContainer
|
||||
HOOKLIBCR=librunc-hooks-create-runtime.so
|
||||
HOOKLIBCC=librunc-hooks-create-container.so
|
||||
LIBPATH="$DEBIAN_BUNDLE/rootfs/lib/"
|
||||
|
||||
function setup() {
|
||||
umount "$LIBPATH"/$HOOKLIBCR.1.0.0 &>/dev/null || true
|
||||
umount "$LIBPATH"/$HOOKLIBCC.1.0.0 &>/dev/null || true
|
||||
|
||||
requires root no_systemd
|
||||
|
||||
teardown_debian
|
||||
teardown
|
||||
setup_debian
|
||||
# CR = CreateRuntime, CC = CreataContainer
|
||||
HOOKLIBCR=librunc-hooks-create-runtime.so
|
||||
HOOKLIBCC=librunc-hooks-create-container.so
|
||||
LIBPATH="$(pwd)/rootfs/lib/"
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
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
|
||||
if [ -n "$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
|
||||
fi
|
||||
teardown_debian
|
||||
}
|
||||
|
||||
@@ -31,25 +27,25 @@ function teardown() {
|
||||
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"
|
||||
|
||||
current_pwd="$(pwd)"
|
||||
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 "$current_pwd/$HOOKLIBCR.1.0.0" "$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 $current_pwd/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
|
||||
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $bundle/$HOOKLIBCC.1.0.0 ./lib/$HOOKLIBCC.1.0.0"
|
||||
|
||||
CONFIG=$(jq --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"]' "$DEBIAN_BUNDLE"/config.json)
|
||||
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' "$bundle"/config.json)
|
||||
echo "${CONFIG}" >config.json
|
||||
|
||||
runc run test_debian
|
||||
|
||||
Reference in New Issue
Block a user