Skip to content

Commit

Permalink
Refactoring testing script to make it work similarily to the building
Browse files Browse the repository at this point in the history
script.  Also adding loop on all architectures and testing summary
output at the end.
Removed erroneous doc in README.
  • Loading branch information
laeti-tia committed Sep 23, 2021
1 parent 8b86a6b commit 9bddcab
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 60 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ CMD ["/lib/systemd/systemd"]
### Testing image setup
FROM ps-base-image AS test-image

# Copy testing script
COPY ./ps-install-tester /usr/local/bin/ps-install-tester

# Let docker know that pscheduler listens on 443
EXPOSE 443

Expand Down
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,19 @@ proxy=172.17.0.1:3128 package=pscheduler-archiver-rabbitmq ./build-in-docker psc
```

## Test packages
To test the installation of a resulting package, run something like:

./test-in-docker package.deb

This project provides ways of testing installation of perfSONAR DEB package-based bundles on Debian-based systems using Docker containers.

Fully Supported:
* Debian 9 Stretch
* Debian 10 Buster
* Ubuntu 16 Xenial Xerus
* Ubuntu 18 Bionic Beaver
* Ubuntu 20 Focal Fossa

To test the installation of a resulting package, run something like:

./test-in-docker package

The package will be installed in the different OS supported and for different architectures.

You can run the tests by executing `test_install_instructions.sh $REPO $OS $BUNDLE` (with all args optional but the previous one always required) where:

* `$REPO` is one of these (default is to use production):
* `perfsonar-release` (production)
* `perfsonar-patch-snapshot`
* `perfsonar-minor-snapshot`
* `perfsonar-patch-staging`
* `$OS` is one of these (default to test all):
* `debian:stretch`
* `debian:buster`
* `ubuntu:xenial`
* `ubuntu:bionic`
You can change the perfSONAR repository to be used or limit the number of OS to install to by using the `-r` and `-o` options. See the help included in the script for all the options.

23 changes: 12 additions & 11 deletions build-in-docker
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ case $OSimage in
focal) OSimage=ubuntu:$OSimage ;;
stretch) OSimage=debian:$OSimage ;;
esac
export OSimage REPO
export OSimage ARCH REPO useproxy
if [ -n "$proxy" ]; then
# If $proxy is set, then we will use it
export useproxy=with
useproxy=with
else
export useproxy=without
useproxy=without
fi

# Initialise
Expand All @@ -109,23 +109,24 @@ for ARCH in ${ARCHES[@]}; do
CONTAINERS+=${LARCH/\/}"_build "
TEST_CONTAINERS+=${LARCH/\/}"_test "
done
ARCH=linux/amd64 docker compose down
# ARCH need to be set before calling docker compose
ARCH=linux/amd64
docker compose down

if $build_docker_images ; then
# Loop on all ARCHES we want to build for to prepare images
for ARCH in ${ARCHES[@]}; do
echo -e "\n\033[1;35m============\033[0;35m\nBuilding OS: $OSimage.$ARCH - pS repo: $REPO\n\033[1m============\033[0m\n"
# Build the images, sequentially so that caching is effective
ARCH=$ARCH docker buildx bake --load deb_test
ARCH=$ARCH docker buildx bake --load deb_build
docker buildx bake --load deb_build
done
else
echo -e "\n\033[1;33m -d : I'm not building Docker images but will use the ones already existing in the local registry.\033[0m\n"
echo -e "\n\033[1;33m -d\033[0;33m : I'm not building Docker images but will use the ones already existing in the local registry.\033[0m\n"
fi

# Launch all containers, with deb_build running on amd64
# TODO: deb_build should be running on the main Docker host ARCH
ARCH=linux/amd64 docker compose up -d deb_build $CONTAINERS
docker compose up -d deb_build $CONTAINERS

if ${source_and_binary} ; then
# Build source package and feed all the parameters to ps-builder
Expand All @@ -144,12 +145,12 @@ for ARCH in ${ARCHES[@]}; do
echo -e "\n===== Building \033[1mbinary package\033[0m on \033[1m$ARCH.$OSimage\033[0m in \033[1m$LARCH-build\033[0m container ====="
[ -n "$debug_build" ] && echo -e "\033[1;33m -D : We will run a debug binary build, i.e. call $debug_build.\033[0m\n"
# TODO: can we run all builds in parallel?
ARCH=$ARCH docker compose exec --user psbuild -e package=$package ${LARCH}_build /usr/local/bin/ps-binary-builder $GITREPO $debug_build
docker compose exec --user psbuild -e package=$package ${LARCH}_build /usr/local/bin/ps-binary-builder $GITREPO $debug_build
done

# Shuting down
#echo -e "\nNow stopping all containers."
#ARCH=linux/amd64 docker compose down
echo -e "\nNow stopping all containers."
ARCH=linux/amd64 docker compose down

### Debugging
# ARCH=linux/amd64 OSimage=debian:stretch REPO=perfsonar-4.4-snapshot docker compose up -d deb_build amd64_build
Expand Down
21 changes: 21 additions & 0 deletions ps-install-tester
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# This script will try to install the package given as argument

# Defaults
# Repository to get source from
REPO_LOC='/mnt/build/'

# Check argument
if [ $# -gt 0 ]; then
PKG=$1
else
echo "What package do you want me to try to install?"
exit 1
fi

# Setup the local repository and update APT
/usr/local/bin/ps-local-repo ${REPO_LOC}/build_results/

# Install the package
apt-get -y install $PKG

23 changes: 18 additions & 5 deletions ps-local-repo
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#!/usr/bin/env bash

# This script configures a local APT repository to use locally built packages
# It can be given an argument, the absolut path to the directory where the repository exists
# It needs to be given an argument, the absolut path to the directory where the repository exists

LOCAL_REPO=$1
if [ $# -gt 0 ]; then
LOCAL_REPO=$1
else
echo "Where is the local repository located?"
exit 1
fi

# The script can be run as root or as a user with sudo access
# We might not know if sudo is actually insalled or not
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
SUDO="sudo"
else
SUDO=""
fi
echo "To solve dependencies, I will also use packages from ${LOCAL_REPO} if any."
echo "# Locally built packages" | sudo tee /etc/apt/sources.list.d/localy-built-packages.list
echo "deb [trusted=yes] file:${LOCAL_REPO} ./" | sudo tee -a /etc/apt/sources.list.d/localy-built-packages.list
sudo apt update
echo "# Using locally built packages" | $SUDO tee /etc/apt/sources.list.d/localy-built-packages.list > /dev/null
echo "deb [trusted=yes] file:${LOCAL_REPO} ./" | $SUDO tee -a /etc/apt/sources.list.d/localy-built-packages.list > /dev/null
$SUDO apt update

121 changes: 94 additions & 27 deletions test-in-docker
Original file line number Diff line number Diff line change
@@ -1,30 +1,68 @@
#!/usr/bin/env bash

#######
# test-in-docker [package] [repo] [osimage]
# This script will test the installation of a locally build package
#######
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} -dD -r [repo] -o [osimage] package
This script will test the installation of a locally build package
It is meant to verify that all dependencies can be satisfied at installation time
Requirements:
- Need to be in a directory at the same level as the gitrepo to be built
- Package to be test available in the perfSONAR repo or in the local repo
Arguments understood:
-d don't rebuild Docker images but use locally existing one
-D debug install, will get you into a shell instead of doing the install
-r (optional) repository to be used (local repo will be automatically used as well)
if not repo given, then perfsonar-minor-snapshot will be used)
-o (optional) OS to use to try the install (if empty, then all OS known will be tried)
package to be installed
Some examples:
./test-in-docker perfsonar-toolkit
./test-in-docker -r perfsonar-5.0-snapshot -o debian:buster perfsonar-toolkit
proxy=172.17.0.1:3128 ./test-in-docker -r perfsonar-5.0-snapshot iperf3
EOF
}

# Defaults
declare -a ARCHES=("linux/amd64" "linux/arm/v7")
declare -a ARCHES=("linux/amd64" "linux/arm64")
# See other valid values in build-in-docker
# The ARCHES used need to have a valid image already built, this script is not building any, only the build-in-docker script is building the images
# TODO: Move the image building part into dedicated script
declare -a OSimages=("debian:stretch" "debian:buster" "ubuntu:xenial" "ubuntu:bionic" "ubuntu:focal")
build_docker_images=true
REPO="perfsonar-minor-snapshot"

# Parse CLI args
# Parsing options
while getopts "dDhr:o:" OPT; do
case $OPT in
d) build_docker_images=false ;;
D) debug_build="bash" ;;
r) REPO=$OPTARG ;;
o) OSimages=("$OPTARG") ;;
h)
show_help >&2
exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ -n "$1" ]; then
PKG=$1
if [ -n "$2" ]; then
# Set repo
declare -a REPO=$2
if [ -n "$3" ]; then
# Set OSimage
declare -a OSimages=("$3")
fi
fi
else
echo "I need the name of package to test."
exit 1
fi
export REPO useproxy

# Variable used by the Docker setup
export OSimage ARCH REPO useproxy
if [ -n "$proxy" ]; then
# If $proxy is set, then we will use it
useproxy=with
else
useproxy=without
fi

# Initialise
LOGS_PREFIX="logs/binary_build"
Expand All @@ -35,24 +73,53 @@ for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
TEST_CONTAINERS+=${LARCH/\/}"_test "
done

# These 2 vars need to be set before calling docker compose
OSimage=${OSimages[0]}
ARCH=linux/amd64
docker compose down

# Start containers
if $build_docker_images ; then
# Loop on all OS we want to test
for OSimage in ${OSimages[@]}; do
# Loop on all ARCHES we want to prepare images
for ARCH in ${ARCHES[@]}; do
echo -e "\n\033[1;35m============\033[0;35m\nBuilding OS: $OSimage.$ARCH - pS repo: $REPO\n\033[1m============\033[0m\n"
docker buildx bake --load deb_test
done
done
else
echo -e "\n\033[1;33m -d\033[0;33m : I'm not building Docker images but will use the ones already existing in the local registry.\033[0m\n"
fi

# TODO: deb_test should be running on the main Docker host ARCH and be used to run additional commands, if needed
ARCH=linux/amd64 docker compose up -d deb_test $TEST_CONTAINERS

# Loop on all ARCHES to test install the new package
# Loop on all OS we want to test
OUTPUT=""
# Loop on all OSimage and ARCHES to test install the new package
for OSimage in ${OSimages[@]}; do
LARCH=${ARCH#*\/}
LARCH=${LARCH/\/}
echo -e "\n===== Testing \033[1m$PKG\033[0m on \033[1m$ARCH.$OSimage\033[0m in \033[1m$LARCH-test\033[0m container =====\033[0m"
# TODO: can we run all tests in parallel?
docker compose exec ${LARCH}_test "apt-get update; apt-get -y install $PKG"
# Should we run autopkgtest instead? Or after installation if they exist?
echo "=========="
echo -e "Starting up containers for \033[1m$OSimage\033[0m"
docker compose up -d deb_test $TEST_CONTAINERS
for ARCH in ${ARCHES[@]}; do
LARCH=${ARCH#*\/}
LARCH=${LARCH/\/}
echo -e "\n===== Testing installation of \033[1m$PKG\033[0m on \033[1m$ARCH.$OSimage\033[0m in \033[1m$LARCH-test\033[0m container ====="
# TODO: can we run all tests in parallel?
docker compose exec ${LARCH}_test /usr/local/bin/ps-install-tester $PKG
if [ $? -eq 0 ]; then
OUT="\033[32mInstallation of \033[1m$PKG\033[0;32m for \033[1m$OSimage\033[0;32m on \033[1m$ARCH\033[0;32m went fine.\033[0m"
else
OUT="\033[33mThere seems to be a problem during the installation of \033[1m$PKG\033[0;33m for \033[1m$OSimage\033[0;33m on \033[1m$ARCH\033[0m"
fi
echo -e "\n$OUT"
OUTPUT+=$OUT"\n"
# Should we run autopkgtest instead? Or after installation if test exist?
done
echo -e "\nNow stopping all containers"
docker compose down
OUTPUT+="-----\n"
done

# Shuting down
echo -e "\nNow stopping all containers."
docker compose down
echo -e "\n\n\033[1mTesting summary:\033[0m\n-----"
echo -e $OUTPUT

0 comments on commit 9bddcab

Please sign in to comment.