Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix filesystem call test suite based on pjdfstest #104

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ GO111MODULE_VALUE=auto
PREFIX ?= out/

CMD=containerd-stargz-grpc ctr-remote

CMD_BINARIES=$(addprefix $(PREFIX),$(CMD))

OUT_POSIX=out-posix

.PHONY: all build check install-check-tools install uninstall clean test test-root test-all integration test-optimize benchmark test-pullsecrets test-cri

all: build
Expand Down Expand Up @@ -61,6 +62,7 @@ uninstall:
clean:
@echo "$@"
@rm -f $(CMD_BINARIES)
@rm -f $(OUT_POSIX)

test:
@echo "$@"
Expand All @@ -86,3 +88,6 @@ test-pullsecrets:

test-cri:
@./script/cri/test.sh

test-posix:
@./script/posix/test.sh
33 changes: 33 additions & 0 deletions script/posix/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright The containerd Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.13

# basic packages
RUN apt-get update -y && \
apt-get --no-install-recommends install -y libbtrfs-dev libseccomp-dev fuse \
apt-transport-https gnupg2 software-properties-common
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean apt-transport-https gnupg2 software-properties-common.


# runtime dependencies
RUN git clone https://github.com/opencontainers/runc \
$GOPATH/src/github.com/opencontainers/runc && \
cd $GOPATH/src/github.com/opencontainers/runc && \
git checkout d736ef14f0288d6993a1845745d6756cfc9ddd5a && \
GO111MODULE=off make BUILDTAGS='seccomp apparmor' && \
GO111MODULE=off make install && \
git clone https://github.com/containerd/containerd \
$GOPATH/src/github.com/containerd/containerd && \
cd $GOPATH/src/github.com/containerd/containerd && \
git checkout 990076b731ec9446437972b41176a6b0f3b7bcbf && \
GO111MODULE=off make && GO111MODULE=off make install
4 changes: 4 additions & 0 deletions script/posix/config/config.containerd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[proxy_plugins]
[proxy_plugins.stargz]
type = "snapshot"
address = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock"
1 change: 1 addition & 0 deletions script/posix/config/config.stargz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
noprefetch = false
13 changes: 13 additions & 0 deletions script/posix/pjdfstest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.9 AS stage-build
WORKDIR /work
RUN apk add git automake autoconf build-base && \
git clone https://github.com/pjd/pjdfstest.git /work/pjdfstest && \
cd /work/pjdfstest && \
git checkout a75ea1caf843a3a1e6c866b61bf954f68cee4a85 && \
autoreconf -ifs && ./configure && make pjdfstest

FROM alpine:3.9 AS stage-final
WORKDIR /work
COPY --from=stage-build /work/pjdfstest /work/pjdfstest
RUN apk add openssl perl-test-harness-utils
CMD ["prove", "-rv", "/work/pjdfstest/tests"]
90 changes: 90 additions & 0 deletions script/posix/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# Copyright The containerd Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

# Check Dockerfile at script/posix/Dockerfile
IMAGE_PJDFSTEST="${IMAGE_PJDFSTEST:-docker.io/sequix/pjdfstest:v1-stargz}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also upload it when we merge it.

CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

function retry {
local RETRYNUM=30
local RETRYINTERVAL=1
local TIMEOUTSEC=180
local SUCCESS=false
for i in $(seq ${RETRYNUM}) ; do
if eval "timeout ${TIMEOUTSEC} ${@}" ; then
SUCCESS=true
break
fi
echo "Fail(${i}). Retrying..."
sleep ${RETRYINTERVAL}
done
if [ "${SUCCESS}" == "true" ] ; then
return 0
else
return 1
fi
}

specList() {
uname -r
cat /etc/os-release
cat /proc/cpuinfo
cat /proc/meminfo
mount
df -T
}
echo "Machine spec list:"
specList

setup() {
local REPO_CONFIG_DIR=$CONTEXT/config/
local CONTAINERD_CONFIG_DIR=/etc/containerd/
local REMOTE_SNAPSHOTTER_SOCKET=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock
local REMOTE_SNAPSHOTTER_CONFIG_DIR=/etc/containerd-stargz-grpc/

mkdir -p /tmp/out
PREFIX=/tmp/out/ make clean
PREFIX=/tmp/out/ make -j2
PREFIX=/tmp/out/ make install
mkdir -p "${CONTAINERD_CONFIG_DIR}"
cp "${REPO_CONFIG_DIR}"config.containerd.toml "${CONTAINERD_CONFIG_DIR}"
mkdir -p "${REMOTE_SNAPSHOTTER_CONFIG_DIR}"
cp "${REPO_CONFIG_DIR}"config.stargz.toml "${REMOTE_SNAPSHOTTER_CONFIG_DIR}"

containerd-stargz-grpc --log-level=debug \
--address="${REMOTE_SNAPSHOTTER_SOCKET}" \
--config="${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.stargz.toml" \
&>/var/log/containerd-stargz-grpc.log &
retry ls "${REMOTE_SNAPSHOTTER_SOCKET}"

containerd --log-level debug \
--config="${CONTAINERD_CONFIG_DIR}config.containerd.toml" \
&>/var/log/containerd.log &
retry ctr version
}
echo "Setting up stargz-snaphsotter & containerd..."
setup

testPosix() {
local containerID="posix-test_$(basename $(mktemp))"
ctr-remote image rpull "$IMAGE_PJDFSTEST"
ctr-remote run --rm --snapshotter=stargz "$IMAGE_PJDFSTEST" "$containerID" >/output || \
echo -e "\e[91mPosix test failed!\e[0m"
Comment on lines +86 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should propagate the exit code to the caller scripts (test.sh) so that Github Actions can know the success/failure of this test.

}
echo "Testing posix calls..."
testPosix
75 changes: 75 additions & 0 deletions script/posix/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Copyright The containerd Authors.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

cleanup() {
local ORG_EXIT_CODE="${1}"
rm "${DOCKER_COMPOSE_YAML}" || true
exit "${ORG_EXIT_CODE}"
}
trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM

CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/"
REPO="${CONTEXT}../../"

echo "Preparing docker-compose.yml..."
DOCKER_COMPOSE_YAML=$(mktemp)
BENCHMARKING_NODE=posix-test
BENCHMARKING_CONTAINER=posix-test
cat <<EOF > "${DOCKER_COMPOSE_YAML}"
version: "3"
services:
${BENCHMARKING_NODE}:
build:
context: "${CONTEXT}/"
dockerfile: Dockerfile
container_name: ${BENCHMARKING_CONTAINER}
privileged: true
working_dir: /go/src/github.com/containerd/stargz-snapshotter
command: tail -f /dev/null
environment:
- NO_PROXY=127.0.0.1,localhost
- HTTP_PROXY=${HTTP_PROXY:-}
- HTTPS_PROXY=${HTTPS_PROXY:-}
- http_proxy=${http_proxy:-}
- https_proxy=${https_proxy:-}
tmpfs:
- /tmp:exec,mode=777
volumes:
- "${REPO}:/go/src/github.com/containerd/stargz-snapshotter:ro"
- "/dev/fuse:/dev/fuse"
- "containerd-data:/var/lib/containerd:delegated"
- "containerd-stargz-grpc-data:/var/lib/containerd-stargz-grpc:delegated"
- "containerd-stargz-grpc-status:/run/containerd-stargz-grpc:delegated"
volumes:
containerd-data:
containerd-stargz-grpc-data:
containerd-stargz-grpc-status:
EOF

echo "Setup posix test environment..."
docker-compose -f "${DOCKER_COMPOSE_YAML}" build ${DOCKER_BUILD_ARGS:-} "${BENCHMARKING_NODE}"
docker-compose -f "${DOCKER_COMPOSE_YAML}" up -d --force-recreate

echo "Posix testing..."
docker exec -i "${BENCHMARKING_CONTAINER}" script/posix/run.sh

echo "Harvesting output..."
docker cp "${BENCHMARKING_CONTAINER}:/output" "${REPO}/out-posix"

echo "Cleaning up benchmark environment..."
docker-compose -f "${DOCKER_COMPOSE_YAML}" down -v