Make docker-tests less verbose and easier to add new tests (#311)

* Make docker-tests less verbose and easier to add new tests

* Fix positional argument parsing

* Suppress more logs unless --verbose is specified
pull/310/head
Ryo Kawaguchi 2024-04-22 21:10:57 +09:00 committed by GitHub
parent 15602388f6
commit 8ab0989f8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 133 additions and 117 deletions

View File

@ -17,5 +17,5 @@ jobs:
- name: Build the Docker images - name: Build the Docker images
run: docker-tests/build-docker-images.sh run: docker-tests/build-docker-images.sh
- name: Run the Docker tests - name: Run the Docker tests
run: docker-tests/run-docker-tests.sh userspace run: docker-tests/run-docker-tests.sh --userspace --verbose

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex set -ex
SELF_DIR="$(dirname "$0")" SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$SELF_DIR/.." cd "$SELF_DIR/.."
docker build -t innernet -f "$SELF_DIR/Dockerfile.innernet" . docker build -t innernet -f "$SELF_DIR/Dockerfile.innernet" .

View File

@ -2,37 +2,54 @@
set -e set -e
shopt -s nocasematch shopt -s nocasematch
SELF_DIR="$(dirname "$0")" SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$SELF_DIR/.." cd "$SELF_DIR/.."
if [[ $# -eq 1 ]]; then help() {
case "$1" in
kernel)
INNERNET_ARGS="-vvv"
;;
userspace)
INNERNET_ARGS="-vvv --backend userspace"
;;
*)
echo "invalid backend (must be kernel or userspace)"
exit 1
esac
else
cat >&2 <<-_EOF cat >&2 <<-_EOF
Usage: "${0##*/}" <BACKEND> Usage: "${0##*/}" [options...] (<test>)
--userspace Use userspace wireguard instead of kernel one
BACKEND: "kernel" or "userspace" --verbose Print verbose innernet logs
_EOF _EOF
exit }
fi
TEST_FILTER=()
while [[ $# -gt 0 ]]; do
case $1 in
--userspace)
INNERNET_ARGS="$INNERNET_ARGS --backend userspace"
shift
;;
--verbose)
INNERNET_ARGS="$INNERNET_ARGS -vvv"
CLIENT_ARGS="$CLIENT_ARGS --verbose"
SERVER_RUST_LOG="debug"
CLIENT_RUST_LOG="trace"
shift
;;
--help)
help
exit
;;
-*)
echo "Invalid option."
help
exit 1
;;
*)
TEST_FILTER+=("$1")
shift
;;
esac
done
cmd() { cmd() {
echo "[#] $*" >&2 echo "[#] $*" >&2
"$@" "$@"
} }
info() { info() {
echo -e "\033[0;34m- $@\033[0m" 1>&2 echo -e "\033[0;34m- $@\033[0m" 1>&2
} }
tmp_dir=$(mktemp -d -t innernet-tests-XXXXXXXXXX) tmp_dir=$(mktemp -d -t innernet-tests-XXXXXXXXXX)
@ -53,7 +70,7 @@ SERVER_CONTAINER=$(cmd docker create -it --rm \
--network "$NETWORK" \ --network "$NETWORK" \
--ip 172.18.1.1 \ --ip 172.18.1.1 \
--volume /dev/net/tun:/dev/net/tun \ --volume /dev/net/tun:/dev/net/tun \
--env RUST_LOG=debug \ --env RUST_LOG="$SERVER_RUST_LOG" \
--env INNERNET_ARGS="$INNERNET_ARGS" \ --env INNERNET_ARGS="$INNERNET_ARGS" \
--cap-add NET_ADMIN \ --cap-add NET_ADMIN \
innernet) innernet)
@ -63,17 +80,23 @@ info "server started as $SERVER_CONTAINER"
info "Waiting for server to initialize." info "Waiting for server to initialize."
cmd sleep 5 cmd sleep 5
create_peer_docker() {
local IP=$1
cmd docker create --rm -it \
--network "$NETWORK" \
--ip $IP \
--volume /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \
--env RUST_LOG="$CLIENT_RUST_LOG" \
--env INTERFACE=evilcorp \
--env INNERNET_ARGS="$INNERNET_ARGS" \
--env CLIENT_ARGS="$CLIENT_ARGS" \
innernet /app/start-client.sh
}
info "Starting first peer." info "Starting first peer."
cmd docker cp "$SERVER_CONTAINER:/app/peer1.toml" "$tmp_dir" cmd docker cp "$SERVER_CONTAINER:/app/peer1.toml" "$tmp_dir"
PEER1_CONTAINER=$(cmd docker create --rm -it \ PEER1_CONTAINER=$(create_peer_docker 172.18.1.2)
--network "$NETWORK" \
--ip 172.18.1.2 \
--volume /dev/net/tun:/dev/net/tun \
--env INTERFACE=evilcorp \
--env RUST_LOG=trace \
--env INNERNET_ARGS="$INNERNET_ARGS" \
--cap-add NET_ADMIN \
innernet /app/start-client.sh)
info "peer1 started as $PEER1_CONTAINER" info "peer1 started as $PEER1_CONTAINER"
cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml" cmd docker cp "$tmp_dir/peer1.toml" "$PEER1_CONTAINER:/app/invite.toml"
cmd docker start -a "$PEER1_CONTAINER" | sed -e 's/^/\x1B[0;96mpeer 1\x1B[0m: /' & cmd docker start -a "$PEER1_CONTAINER" | sed -e 's/^/\x1B[0;96mpeer 1\x1B[0m: /' &
@ -106,99 +129,87 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
cmd docker cp "$PEER1_CONTAINER:/app/peer2.toml" "$tmp_dir" cmd docker cp "$PEER1_CONTAINER:/app/peer2.toml" "$tmp_dir"
info "Starting second peer." info "Starting second peer."
PEER2_CONTAINER=$(docker create --rm -it \ PEER2_CONTAINER=$(create_peer_docker 172.18.1.3)
--network "$NETWORK" \
--ip 172.18.1.3 \
--volume /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \
--env INTERFACE=evilcorp \
--env INNERNET_ARGS="$INNERNET_ARGS" \
innernet /app/start-client.sh)
info "peer2 started as $PEER2_CONTAINER" info "peer2 started as $PEER2_CONTAINER"
cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml" cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml"
cmd docker start -a "$PEER2_CONTAINER" | sed -e 's/^/\x1B[0;93mpeer 2\x1B[0m: /' & cmd docker start -a "$PEER2_CONTAINER" | sed -e 's/^/\x1B[0;93mpeer 2\x1B[0m: /' &
sleep 10 sleep 10
info "Creating short-lived invitation for third peer." test_short_lived_invitation() {
cmd docker exec "$PEER1_CONTAINER" innernet \ info "Creating short-lived invitation for third peer."
add-peer evilcorp \ cmd docker exec "$PEER1_CONTAINER" innernet \
--name "peer3" \ add-peer evilcorp \
--cidr "robots" \ --name "peer3" \
--admin false \ --cidr "robots" \
--ip "10.66.2.100" \ --admin false \
--save-config "/app/peer3.toml" \ --ip "10.66.2.100" \
--invite-expires "1s" \ --save-config "/app/peer3.toml" \
--yes --invite-expires "1s" \
--yes
info "waiting 15 seconds to see if the server clears out the IP address." info "waiting 15 seconds to see if the server clears out the IP address."
sleep 11 sleep 11
info "Re-requesting invite after expiration with the same parameters." info "Re-requesting invite after expiration with the same parameters."
cmd docker exec "$PEER1_CONTAINER" innernet \ cmd docker exec "$PEER1_CONTAINER" innernet \
add-peer evilcorp \ add-peer evilcorp \
--name "peer3" \ --name "peer3" \
--cidr "robots" \ --cidr "robots" \
--admin false \ --admin false \
--ip "10.66.2.100" \ --ip "10.66.2.100" \
--save-config "/app/peer3_2.toml" \ --save-config "/app/peer3_2.toml" \
--invite-expires "30m" \ --invite-expires "30m" \
--yes --yes
}
info "peer2 started as $PEER2_CONTAINER" test_simultaneous_redemption() {
cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml" info "Creating invitation for fourth and fifth peer from first peer."
cmd docker start -a "$PEER2_CONTAINER" | sed -e 's/^/\x1B[0;93mpeer 2\x1B[0m: /' & cmd docker exec "$PEER1_CONTAINER" innernet \
sleep 10 add-peer evilcorp \
--name "peer4" \
--cidr "robots" \
--admin false \
--auto-ip \
--save-config "/app/peer4.toml" \
--invite-expires "30s" \
--yes
cmd docker cp "$PEER1_CONTAINER:/app/peer4.toml" "$tmp_dir"
cmd docker exec "$PEER1_CONTAINER" innernet \
add-peer evilcorp \
--name "peer5" \
--cidr "robots" \
--admin false \
--auto-ip \
--save-config "/app/peer5.toml" \
--invite-expires "30s" \
--yes
cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir"
info "Creating invitation for fourth and fifth peer from first peer." info "Starting fourth and fifth peer and redeeming simultaneously."
cmd docker exec "$PEER1_CONTAINER" innernet \ PEER4_CONTAINER=$(create_peer_docker 172.18.1.4)
add-peer evilcorp \ cmd docker cp "$tmp_dir/peer4.toml" "$PEER4_CONTAINER:/app/invite.toml"
--name "peer4" \ PEER5_CONTAINER=$(create_peer_docker 172.18.1.5)
--cidr "robots" \ cmd docker cp "$tmp_dir/peer5.toml" "$PEER5_CONTAINER:/app/invite.toml"
--admin false \
--auto-ip \
--save-config "/app/peer4.toml" \
--invite-expires "30s" \
--yes
cmd docker cp "$PEER1_CONTAINER:/app/peer4.toml" "$tmp_dir"
cmd docker exec "$PEER1_CONTAINER" innernet \
add-peer evilcorp \
--name "peer5" \
--cidr "robots" \
--admin false \
--auto-ip \
--save-config "/app/peer5.toml" \
--invite-expires "30s" \
--yes
cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir"
info "Starting fourth and fifth peer and redeeming simultaneously." cmd docker start -a "$PEER4_CONTAINER" | sed -e 's/^/\x1B[0;92mpeer 4\x1B[0m: /' &
PEER4_CONTAINER=$(docker create --rm -it \ info "peer4 started as $PEER4_CONTAINER"
--network "$NETWORK" \ cmd docker start -a "$PEER5_CONTAINER" | sed -e 's/^/\x1B[0;94mpeer 5\x1B[0m: /' &
--ip 172.18.1.4 \ info "peer5 started as $PEER5_CONTAINER"
--volume /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \
--env INTERFACE=evilcorp \
--env INNERNET_ARGS="$INNERNET_ARGS" \
innernet /app/start-client.sh)
cmd docker cp "$tmp_dir/peer4.toml" "$PEER4_CONTAINER:/app/invite.toml"
PEER5_CONTAINER=$(docker create --rm -it \
--network "$NETWORK" \
--ip 172.18.1.5 \
--volume /dev/net/tun:/dev/net/tun \
--cap-add NET_ADMIN \
--env INTERFACE=evilcorp \
--env INNERNET_ARGS="$INNERNET_ARGS" \
innernet /app/start-client.sh)
cmd docker cp "$tmp_dir/peer5.toml" "$PEER5_CONTAINER:/app/invite.toml"
cmd docker start -a "$PEER4_CONTAINER" | sed -e 's/^/\x1B[0;92mpeer 4\x1B[0m: /' & info "Checking connectivity betweeen peers."
info "peer4 started as $PEER4_CONTAINER" cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1
cmd docker start -a "$PEER5_CONTAINER" | sed -e 's/^/\x1B[0;94mpeer 5\x1B[0m: /' & cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1
info "peer5 started as $PEER5_CONTAINER" }
info "Checking connectivity betweeen peers." # Run tests (functions prefixed with test_) in alphabetical order.
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1 # Optional filter provided by positional arguments is applied.
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1 for func in $(declare -F | awk '{print $3}'); do
if [[ "$func" =~ ^test_ ]]; then
if [ ${#TEST_FILTER[@]} -eq 0 ] || [[ "${TEST_FILTER[*]}" =~ "$func" ]]; then
$func
fi
fi
done
echo echo
info "test succeeded." info "Test succeeded."

View File

@ -2,6 +2,7 @@
set -e set -e
INTERFACE="${INTERFACE:-innernet}" INTERFACE="${INTERFACE:-innernet}"
innernet $INNERNET_ARGS install \ innernet $INNERNET_ARGS install \
--name "$INTERFACE" \ --name "$INTERFACE" \
--delete-invite \ --delete-invite \
@ -9,6 +10,10 @@ innernet $INNERNET_ARGS install \
/app/invite.toml /app/invite.toml
while true; do while true; do
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE" if [[ $CLIENT_ARGS =~ --verbose ]]; then
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE"
else
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE" > /dev/null
fi
sleep 1 sleep 1
done done