Accepting request 683643 from home:cyphar:containers:docker-test
Makes testing actually work properly. OBS-URL: https://build.opensuse.org/request/show/683643 OBS-URL: https://build.opensuse.org/package/show/Virtualization:containers/docker?expand=0&rev=294
This commit is contained in:
parent
cc89a2459e
commit
2da3bd4f57
11
docker.spec
11
docker.spec
@ -217,11 +217,15 @@ Zsh command line completion support for %{name}.
|
|||||||
%package test
|
%package test
|
||||||
%global __requires_exclude ^libgo.so.*$
|
%global __requires_exclude ^libgo.so.*$
|
||||||
Summary: Test package for docker
|
Summary: Test package for docker
|
||||||
|
Group: System/Management
|
||||||
|
Requires: curl
|
||||||
|
Requires: go
|
||||||
|
Requires: iputils
|
||||||
|
Requires: jq
|
||||||
# KUBIC-SPECIFIC: This was required when upgrading from the original kubic
|
# KUBIC-SPECIFIC: This was required when upgrading from the original kubic
|
||||||
# packaging, when everything was renamed to -kubic. It also is
|
# packaging, when everything was renamed to -kubic. It also is
|
||||||
# used to ensure that nothing complains too much when using
|
# used to ensure that nothing complains too much when using
|
||||||
# -kubic packages. Hopfully it can be removed one day.
|
# -kubic packages. Hopfully it can be removed one day.
|
||||||
Group: System/Management
|
|
||||||
%if "%flavour" == "kubic"
|
%if "%flavour" == "kubic"
|
||||||
# Obsolete old packege without the -kubic suffix
|
# Obsolete old packege without the -kubic suffix
|
||||||
Obsoletes: %{realname}-test = 1.12.6
|
Obsoletes: %{realname}-test = 1.12.6
|
||||||
@ -373,11 +377,6 @@ install -D -m0755 %{SOURCE9} %{buildroot}%{_prefix}/src/docker/tests.sh
|
|||||||
cp -a components/engine/{hack,contrib,integration{,-cli}} %{buildroot}%{_prefix}/src/docker/
|
cp -a components/engine/{hack,contrib,integration{,-cli}} %{buildroot}%{_prefix}/src/docker/
|
||||||
echo "%{version}" > %{buildroot}%{_prefix}/src/docker/VERSION
|
echo "%{version}" > %{buildroot}%{_prefix}/src/docker/VERSION
|
||||||
|
|
||||||
find %{buildroot}%{_prefix}/src/docker/ \
|
|
||||||
\( -type f -name '*_test.go' \) -delete
|
|
||||||
find %{buildroot}%{_prefix}/src/docker/ \
|
|
||||||
\( -type d -empty \) -delete
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# systemd service
|
# systemd service
|
||||||
#
|
#
|
||||||
|
234
tests.sh
234
tests.sh
@ -4,132 +4,125 @@
|
|||||||
# XXX: We currently only support running integration-cli.
|
# XXX: We currently only support running integration-cli.
|
||||||
#
|
#
|
||||||
|
|
||||||
set -Eeuxo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
DOCKER_DIR=/usr/src/docker
|
DOCKER_DIR=/usr/src/docker
|
||||||
SCRIPTS_DIR=$DOCKER_DIR/hack
|
SCRIPTS_DIR="$DOCKER_DIR/hack"
|
||||||
TESTS_EXE=$DOCKER_DIR/integration-cli/tests.main
|
TESTS_EXE="$DOCKER_DIR/integration-cli/tests.main"
|
||||||
VERSION=$(cat $DOCKER_DIR/VERSION)
|
VERSION="$(cat "$DOCKER_DIR/VERSION")"
|
||||||
|
|
||||||
# working dirs
|
# working dirs
|
||||||
TESTS_DIR=/tmp/docker-int-tests
|
TESTS_DIR=/tmp/docker-int-tests
|
||||||
BUNDLES_DIR=$TESTS_DIR/run/bundles
|
FROZEN_IMAGES=/docker-frozen-images
|
||||||
FAKE_GOPATH=$TESTS_DIR/go
|
BUNDLES_DIR="$TESTS_DIR/run/bundles"
|
||||||
|
|
||||||
CHECK_TIMEOUT="${CHECK_TIMEOUT:-5m}"
|
CHECK_TIMEOUT="${CHECK_TIMEOUT:-5m}"
|
||||||
TEST_TIMEOUT="${TEST_TIMEOUT:-60m}"
|
TEST_TIMEOUT="${TEST_TIMEOUT:-60m}"
|
||||||
TEST_ARGS="-check.vv -check.timeout=${CHECK_TIMEOUT} -test.timeout=${TEST_TIMEOUT}"
|
TEST_ARGS=("-check.v" "-check.timeout=${CHECK_TIMEOUT}" "-test.timeout=${TEST_TIMEOUT}")
|
||||||
TEST_SELECT=
|
TEST_SELECT=
|
||||||
TEST_LOG=/tmp/docker-tests.log
|
TEST_LOG=/tmp/docker-tests.log
|
||||||
ENABLE_XUNIT="${ENABLE_XUNIT:=yes}"
|
ENABLE_XUNIT="${ENABLE_XUNIT-yes}"
|
||||||
|
KEEPBUNDLE="${KEEPBUNDLE:-}"
|
||||||
|
|
||||||
# the config file for Docker
|
# the config file for Docker
|
||||||
CFG_DOCKER=/etc/docker/daemon.json
|
CFG_DOCKER=/etc/docker/daemon.json
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
log() { echo ">>> $@" ; }
|
log() { echo ">>> $@" ; }
|
||||||
warn() { log "WARNING: $@" ; }
|
warn() { log "WARNING: $@" ; }
|
||||||
error() { log "ERROR: $@" ; }
|
error() { log "ERROR: $@" ; }
|
||||||
abort() { log "FATAL: $@" ; exit 1 ; }
|
abort() { log "FATAL: $@" ; exit 1 ; }
|
||||||
usage() { echo "$USAGE" ; }
|
usage() { echo "$USAGE" ; }
|
||||||
abort_usage() { usage ; abort $@ ; }
|
abort_usage() { usage ; abort "$@" ; }
|
||||||
|
|
||||||
bundle() {
|
bundle() {
|
||||||
local bundle="$1"; shift
|
local bundle="$1"; shift
|
||||||
log "Making bundle: $(basename "$bundle") (in $DEST)"
|
log "Making bundle: $(basename "$bundle") (in $DEST)"
|
||||||
source "$SCRIPTS_DIR/make/$bundle" "$@"
|
local oldFlags="$-"
|
||||||
|
set +Eeu
|
||||||
|
source "$SCRIPTS_DIR/make/$bundle" "$@"
|
||||||
|
set "-$oldFlags"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_opts() {
|
|
||||||
OPT="$1"
|
|
||||||
VALUE="$2"
|
|
||||||
FILE=$3
|
|
||||||
|
|
||||||
perl -pi -e "s/^$OPT=.*$//g" $FILE
|
|
||||||
echo "$OPT=\"$VALUE\"" >> $FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
set_docker_opts() { set_opts "DOCKER_OPTS" "$DOCKER_OPTS" /etc/sysconfig/docker ; }
|
|
||||||
|
|
||||||
fix_expected() {
|
fix_expected() {
|
||||||
EXPECTED=$1
|
EXPECTED="$1"
|
||||||
EXISTING=$2
|
EXISTING="$2"
|
||||||
|
|
||||||
exp_base=$(basename $EXPECTED)
|
exp_base="$(basename "$EXPECTED")"
|
||||||
exp_dir=$(dirname $EXPECTED)
|
exp_dir="$(dirname "$EXPECTED")"
|
||||||
[ -d $exp_dir ] || mkdir -p $exp_dir
|
[ -d "$exp_dir" ] || mkdir -p "$exp_dir"
|
||||||
rm -f $exp_dir/$exp_base
|
rm -f "$exp_dir/$exp_base"
|
||||||
(cd $exp_dir && ln -sf $EXISTING $exp_base)
|
( cd "$exp_dir" && ln -sf "$EXISTING" "$exp_base" )
|
||||||
}
|
}
|
||||||
|
|
||||||
save_backup() {
|
save_backup() {
|
||||||
for x in $@ ; do
|
for x in $@ ; do
|
||||||
if [ ! -f $x ] ; then
|
if [ ! -f "$x" ] ; then
|
||||||
touch $x.nbak
|
touch "$x.nbak"
|
||||||
elif [ -f $x.bak ] ; then
|
elif [ -f "$x.bak" ] ; then
|
||||||
warn "$x.bak already exists: no backup will be done"
|
warn "$x.bak already exists: no backup will be done"
|
||||||
else
|
else
|
||||||
cp -f $x $x.bak
|
cp -f "$x" "$x.bak"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_backup() {
|
restore_backup() {
|
||||||
for x in $@ ; do
|
for x in $@ ; do
|
||||||
if [ -f $x.nbak ] ; then
|
if [ -f "$x.nbak" ] ; then
|
||||||
rm -f $x.nbak
|
rm -f "$x.nbak"
|
||||||
else
|
else
|
||||||
if [ -f $x.bak ] ; then
|
if [ -f "$x.bak" ] ; then
|
||||||
mv -f $x.bak $x
|
mv -f "$x.bak" "$x"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
require_go() { go version >/dev/null 2>&1 ; }
|
require_go() { go version >/dev/null 2>&1 ; }
|
||||||
require_git() { git version >/dev/null 2>&1 ; }
|
require_git() { git version >/dev/null 2>&1 ; }
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
[ -x $TESTS_EXE ] || abort "integration tests executable not found at $TESTS_EXE"
|
[ -x "$TESTS_EXE" ] || abort "integration tests executable not found at $TESTS_EXE"
|
||||||
[ $EUID -eq 0 ] || abort "this script must be run as root"
|
[ "$EUID" -eq 0 ] || abort "this script must be run as root"
|
||||||
[ -n "$VERSION" ] || abort "could not obtain version"
|
[ -n "$VERSION" ] || abort "could not obtain version"
|
||||||
|
|
||||||
if [ $# -gt 0 ] ; then
|
if [ "$#" -gt 0 ] ; then
|
||||||
# run only some specific tests
|
# run only some specific tests
|
||||||
TEST_SELECT="-check.f=$(echo $@ | tr ' ' '|')"
|
TEST_SELECT="-check.f=$(echo $@ | tr ' ' '|')"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We want this to fail if the bundles already exist and cannot be removed.
|
# We want this to fail if the bundles already exist and cannot be removed.
|
||||||
# This is to avoid mixing bundles from different versions of the code.
|
# This is to avoid mixing bundles from different versions of the code.
|
||||||
mkdir -p $BUNDLES_DIR
|
mkdir -p "$BUNDLES_DIR"
|
||||||
if [ -e "$BUNDLES_DIR/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then
|
if [ -e "$BUNDLES_DIR/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then
|
||||||
log "$BUNDLES_DIR/$VERSION already exists. Removing."
|
log "$BUNDLES_DIR/$VERSION already exists. Removing."
|
||||||
rm -fr "$BUNDLES_DIR/$VERSION" && mkdir "$BUNDLES_DIR/$VERSION" || exit 1
|
rm -fr "$BUNDLES_DIR/$VERSION" && mkdir "$BUNDLES_DIR/$VERSION" || exit 1
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEST="$BUNDLES_DIR/$VERSION/"
|
DEST="$BUNDLES_DIR/$VERSION/"
|
||||||
mkdir -p "$DEST"
|
mkdir -p "$DEST"
|
||||||
export DEST=$(realpath $DEST)
|
export DEST="$(realpath "$DEST")"
|
||||||
|
|
||||||
if [ -n "$ENABLE_XUNIT" ] ; then
|
if [ -n "$ENABLE_XUNIT" ] ; then
|
||||||
if [ ! -x /usr/local/bin/go2xunit ] ; then
|
if [ ! -x /usr/local/bin/go2xunit ] ; then
|
||||||
echo >&2 "Installing go2xunit."
|
echo >&2 "Installing go2xunit."
|
||||||
|
|
||||||
require_go || abort "the Go compiler is not installed"
|
require_go || abort "the Go compiler is not installed"
|
||||||
|
|
||||||
export GOPATH="$(mktemp -d)"
|
export GOPATH="$(mktemp -d)"
|
||||||
|
|
||||||
go get -d github.com/tebeka/go2xunit
|
go get -d github.com/tebeka/go2xunit
|
||||||
cd $GOPATH/src/github.com/tebeka/go2xunit && go build -o /usr/local/bin/go2xunit .
|
cd "$GOPATH/src/github.com/tebeka/go2xunit" && go build -o /usr/local/bin/go2xunit .
|
||||||
chmod 755 /usr/local/bin/go2xunit
|
chmod 755 /usr/local/bin/go2xunit
|
||||||
[ -x /usr/local/bin/go2xunit ] || abort "go2xunit could not be built"
|
[ -x /usr/local/bin/go2xunit ] || abort "go2xunit could not be built"
|
||||||
|
|
||||||
rm -rf "$GOPATH"
|
rm -rf "$GOPATH"
|
||||||
export -n GOPATH
|
export -n GOPATH
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# tests require this user and group
|
# tests require this user and group
|
||||||
@ -137,40 +130,39 @@ fi
|
|||||||
/usr/sbin/useradd --create-home --gid docker unprivilegeduser >/dev/null 2>&1 || /bin/true
|
/usr/sbin/useradd --create-home --gid docker unprivilegeduser >/dev/null 2>&1 || /bin/true
|
||||||
|
|
||||||
# prepare some expected dirs, files, etc...
|
# prepare some expected dirs, files, etc...
|
||||||
fix_expected $TESTS_DIR/contrib $DOCKER_DIR/contrib
|
fix_expected "$TESTS_DIR/contrib" "$DOCKER_DIR/contrib"
|
||||||
fix_expected $DEST/fixtures $DOCKER_DIR/integration-cli/fixtures
|
fix_expected "$DEST/fixtures" "$DOCKER_DIR/integration-cli/fixtures"
|
||||||
|
fix_expected "$DEST/../Dockerfile" "$DOCKER_DIR/Dockerfile"
|
||||||
|
|
||||||
export DOCKER_TEST_HOST="tcp://127.0.0.1:2375"
|
export DOCKER_TEST_HOST="tcp://127.0.0.1:2375"
|
||||||
export PATH=/usr/local/bin:$PATH
|
export PATH="/usr/local/bin:$PATH"
|
||||||
export TZ=utc
|
export TZ=utc
|
||||||
export GOPATH="$FAKE_GOPATH"
|
|
||||||
|
|
||||||
export DOCKER_GRAPHDRIVER="${DOCKER_GRAPHDRIVER:-vfs}"
|
export DOCKER_GRAPHDRIVER="${DOCKER_GRAPHDRIVER:-vfs}"
|
||||||
export DOCKER_USERLANDPROXY="${DOCKER_USERLANDPROXY:-true}"
|
export DOCKER_USERLANDPROXY="${DOCKER_USERLANDPROXY:-true}"
|
||||||
#export DOCKER_REMAP_ROOT=default
|
export DOCKER_STORAGE_OPTS="${DOCKER_STORAGE_OPTS:-}"
|
||||||
|
export DOCKER_REMAP_ROOT="${DOCKER_REMAP_ROOT:-}" # "default" uses dockremap
|
||||||
|
|
||||||
# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
|
# Example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G".
|
||||||
storage_params=""
|
storage_opts=()
|
||||||
if [ -n "$DOCKER_STORAGE_OPTS" ]; then
|
if [ -n "$DOCKER_STORAGE_OPTS" ]; then
|
||||||
IFS=','
|
IFS=','
|
||||||
for i in ${DOCKER_STORAGE_OPTS}; do
|
for i in ${DOCKER_STORAGE_OPTS}; do
|
||||||
storage_params="--storage-opt $i $storage_params"
|
storage_opts+=("$i")
|
||||||
done
|
done
|
||||||
unset IFS
|
unset IFS
|
||||||
fi
|
fi
|
||||||
# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
|
|
||||||
extra_params=""
|
|
||||||
|
|
||||||
# deal with remapping
|
# deal with remapping
|
||||||
save_backup /etc/subuid /etc/subgid
|
save_backup /etc/subuid /etc/subgid
|
||||||
echo "dockremap:500000:65536" > /etc/subuid
|
echo "dockremap:500000:65536" >/etc/subuid
|
||||||
echo "dockremap:500000:65536" > /etc/subgid
|
echo "dockremap:500000:65536" >/etc/subgid
|
||||||
groupadd dockremap >/dev/null 2>&1 || /bin/true
|
groupadd dockremap >/dev/null 2>&1 || /bin/true
|
||||||
useradd -g dockremap dockremap >/dev/null 2>&1 || /bin/true
|
useradd -g dockremap dockremap >/dev/null 2>&1 || /bin/true
|
||||||
|
|
||||||
# make sure Docker is stopped, set our config file and then start again
|
# make sure Docker is stopped, set our config file and then start again
|
||||||
save_backup $CFG_DOCKER
|
save_backup "$CFG_DOCKER"
|
||||||
cat <<CFG_DOCKER_EOF > $CFG_DOCKER
|
cat <<CFG_DOCKER_EOF >"$CFG_DOCKER"
|
||||||
{
|
{
|
||||||
"log-level": "debug",
|
"log-level": "debug",
|
||||||
"log-driver": "json-file",
|
"log-driver": "json-file",
|
||||||
@ -178,42 +170,56 @@ cat <<CFG_DOCKER_EOF > $CFG_DOCKER
|
|||||||
"max-size": "50m",
|
"max-size": "50m",
|
||||||
"max-file": "5"
|
"max-file": "5"
|
||||||
},
|
},
|
||||||
|
"userns-remap": "$DOCKER_REMAP_ROOT",
|
||||||
"pidfile": "$DEST/docker.pid",
|
"pidfile": "$DEST/docker.pid",
|
||||||
"host": [
|
"hosts": [
|
||||||
"tcp://127.0.0.1:2375"
|
"tcp://127.0.0.1:2375"
|
||||||
],
|
],
|
||||||
"storage-driver": "$DOCKER_GRAPHDRIVER",
|
"storage-driver": "$DOCKER_GRAPHDRIVER",
|
||||||
|
"storage-opts": [
|
||||||
|
$(printf '"%s",' "${storage_opts[@]}" | sed 's/"",//g;$s/,$//')
|
||||||
|
],
|
||||||
"userland-proxy": $DOCKER_USERLANDPROXY
|
"userland-proxy": $DOCKER_USERLANDPROXY
|
||||||
}
|
}
|
||||||
CFG_DOCKER_EOF
|
CFG_DOCKER_EOF
|
||||||
systemctl restart docker.service
|
systemctl restart docker.service
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
log "Restoring the Docker service..."
|
log "Restoring the Docker service..."
|
||||||
restore_backup $CFG_DOCKER
|
restore_backup "$CFG_DOCKER"
|
||||||
systemctl restart docker.service
|
systemctl restart docker.service
|
||||||
|
|
||||||
log "Removing extra files and restoring backups..."
|
log "Removing extra files and restoring backups..."
|
||||||
restore_backup /etc/subuid /etc/subgid
|
restore_backup /etc/subuid /etc/subgid
|
||||||
rm -f $TESTS_DIR/contrib \
|
rm -f "$TESTS_DIR/contrib" "$DEST/fixtures"
|
||||||
$DEST/fixtures
|
rm -rf "$FROZEN_IMAGES"
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
cd $DOCKER_DIR
|
cd "$DOCKER_DIR"
|
||||||
|
|
||||||
log "Preparing the environment..."
|
log "Preparing the environment..."
|
||||||
bundle .integration-daemon-start
|
export MAKEDIR="$SCRIPTS_DIR/make"
|
||||||
|
export DOCKER_HOST="$DOCKER_TEST_HOST"
|
||||||
bundle .integration-daemon-setup
|
bundle .integration-daemon-setup
|
||||||
|
|
||||||
|
# XXX: Really this should be sourced from the Dockerfile but this is good
|
||||||
|
# enough for now. This comes from the Docker 18.09.1-ce Dockerfile.
|
||||||
|
log "Downlading frozen images..."
|
||||||
|
mkdir -p "$FROZEN_IMAGES"
|
||||||
|
"$DOCKER_DIR/contrib/download-frozen-image-v2.sh" "$FROZEN_IMAGES" \
|
||||||
|
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
|
||||||
|
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
|
||||||
|
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
|
||||||
|
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
|
||||||
|
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
|
||||||
|
|
||||||
log "Running integration tests..."
|
log "Running integration tests..."
|
||||||
export DOCKER_HOST=$DOCKER_TEST_HOST
|
cd "$DEST" && \
|
||||||
cd $DEST && $TESTS_EXE $TEST_ARGS $TEST_SELECT | tee $TEST_LOG || /bin/true
|
"$TESTS_EXE" "${TEST_ARGS[@]}" $TEST_SELECT 2>&1 | tee "$TEST_LOG" || /bin/true
|
||||||
if [ -n "$ENABLE_XUNIT" ] ; then
|
if [ -n "$ENABLE_XUNIT" ] ; then
|
||||||
log "Generating xunit logs..."
|
log "Generating xunit logs..."
|
||||||
go2xunit -fail -gocheck -input $TEST_LOG -output $TEST_LOG.xml
|
go2xunit -fail -gocheck -input "$TEST_LOG" -output "$TEST_LOG.xml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export -n DOCKER_HOST
|
export -n DOCKER_HOST
|
||||||
|
|
||||||
bundle .integration-daemon-stop
|
|
||||||
|
Loading…
Reference in New Issue
Block a user