-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for the new runc hooks
This patch adds a test based on real world usage of runc hooks (libnvidia-container). We verify that mounting a library inside a container and running ldconfig succeeds. Signed-off-by: Renaud Gaubert <[email protected]>
- Loading branch information
Renaud Gaubert
committed
Jun 17, 2020
1 parent
c29382c
commit a52db3e
Showing
5 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ Vagrant.configure("2") do |config| | |
config exclude kernel,kernel-core | ||
config install_weak_deps false | ||
update | ||
install iptables gcc make golang-go libseccomp-devel bats jq git-core criu | ||
install iptables gcc make golang-go libseccomp-devel bats jq git-core criu skopeo | ||
ts run | ||
EOF | ||
dnf clean all | ||
|
@@ -31,10 +31,15 @@ EOF | |
cat /root/rootless.key.pub >> /home/rootless/.ssh/authorized_keys | ||
chown -R rootless.rootless /home/rootless | ||
# Install umoci | ||
curl -o /usr/local/bin/umoci -fsSL https://github.com/openSUSE/umoci/releases/download/v0.4.5/umoci.amd64 | ||
chmod +x /usr/local/bin/umoci | ||
# Add busybox for libcontainer/integration tests | ||
. /vagrant/tests/integration/multi-arch.bash \ | ||
&& mkdir /busybox \ | ||
&& curl -fsSL $(get_busybox) | tar xfJC - /busybox | ||
&& mkdir /busybox /debian \ | ||
&& curl -fsSL $(get_busybox) | tar xfJC - /busybox \ | ||
&& get_and_extract_debian /debian | ||
# Delegate cgroup v2 controllers to rootless user via --systemd-cgroup | ||
mkdir -p /etc/systemd/system/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bats | ||
|
||
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 | ||
|
||
teardown_debian | ||
setup_debian | ||
} | ||
|
||
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 | ||
teardown_debian | ||
} | ||
|
||
@test "runc run (hooks library tests)" { | ||
requires root | ||
requires no_systemd | ||
|
||
# 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" | ||
|
||
current_pwd="$(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" | ||
EOF) | ||
create_container_hook="touch ./lib/$HOOKLIBCC.1.0.0 && mount --bind $current_pwd/$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"]}]} | | ||
.process.args = ["/bin/sh", "-c", "ldconfig -p | grep librunc"]' $DEBIAN_BUNDLE/config.json) | ||
echo "${CONFIG}" > config.json | ||
runc run test_debian | ||
[ "$status" -eq 0 ] | ||
echo "Checking create-runtime library" | ||
echo $output | grep $HOOKLIBCR | ||
[ "$?" -eq 0 ] | ||
echo "Checking create-container library" | ||
echo $output | grep $HOOKLIBCC | ||
[ "$?" -eq 0 ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters