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 specifiedpull/310/head
parent
15602388f6
commit
8ab0989f8f
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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" .
|
||||||
|
|
|
@ -2,29 +2,46 @@
|
||||||
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
|
cat >&2 <<-_EOF
|
||||||
kernel)
|
Usage: "${0##*/}" [options...] (<test>)
|
||||||
INNERNET_ARGS="-vvv"
|
--userspace Use userspace wireguard instead of kernel one
|
||||||
|
--verbose Print verbose innernet logs
|
||||||
|
_EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_FILTER=()
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
--userspace)
|
||||||
|
INNERNET_ARGS="$INNERNET_ARGS --backend userspace"
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
userspace)
|
--verbose)
|
||||||
INNERNET_ARGS="-vvv --backend userspace"
|
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
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "invalid backend (must be kernel or userspace)"
|
TEST_FILTER+=("$1")
|
||||||
exit 1
|
shift
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
done
|
||||||
cat >&2 <<-_EOF
|
|
||||||
Usage: "${0##*/}" <BACKEND>
|
|
||||||
|
|
||||||
BACKEND: "kernel" or "userspace"
|
|
||||||
_EOF
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
cmd() {
|
cmd() {
|
||||||
echo "[#] $*" >&2
|
echo "[#] $*" >&2
|
||||||
|
@ -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,21 +129,15 @@ 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."
|
||||||
|
cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
add-peer evilcorp \
|
add-peer evilcorp \
|
||||||
--name "peer3" \
|
--name "peer3" \
|
||||||
--cidr "robots" \
|
--cidr "robots" \
|
||||||
|
@ -130,11 +147,11 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
--invite-expires "1s" \
|
--invite-expires "1s" \
|
||||||
--yes
|
--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" \
|
||||||
|
@ -143,14 +160,11 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
--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
|
|
||||||
|
|
||||||
info "Creating invitation for fourth and fifth peer from first peer."
|
|
||||||
cmd docker exec "$PEER1_CONTAINER" innernet \
|
|
||||||
add-peer evilcorp \
|
add-peer evilcorp \
|
||||||
--name "peer4" \
|
--name "peer4" \
|
||||||
--cidr "robots" \
|
--cidr "robots" \
|
||||||
|
@ -159,8 +173,8 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
--save-config "/app/peer4.toml" \
|
--save-config "/app/peer4.toml" \
|
||||||
--invite-expires "30s" \
|
--invite-expires "30s" \
|
||||||
--yes
|
--yes
|
||||||
cmd docker cp "$PEER1_CONTAINER:/app/peer4.toml" "$tmp_dir"
|
cmd docker cp "$PEER1_CONTAINER:/app/peer4.toml" "$tmp_dir"
|
||||||
cmd docker exec "$PEER1_CONTAINER" innernet \
|
cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
add-peer evilcorp \
|
add-peer evilcorp \
|
||||||
--name "peer5" \
|
--name "peer5" \
|
||||||
--cidr "robots" \
|
--cidr "robots" \
|
||||||
|
@ -169,36 +183,33 @@ cmd docker exec "$PEER1_CONTAINER" innernet \
|
||||||
--save-config "/app/peer5.toml" \
|
--save-config "/app/peer5.toml" \
|
||||||
--invite-expires "30s" \
|
--invite-expires "30s" \
|
||||||
--yes
|
--yes
|
||||||
cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir"
|
cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir"
|
||||||
|
|
||||||
info "Starting fourth and fifth peer and redeeming simultaneously."
|
info "Starting fourth and fifth peer and redeeming simultaneously."
|
||||||
PEER4_CONTAINER=$(docker create --rm -it \
|
PEER4_CONTAINER=$(create_peer_docker 172.18.1.4)
|
||||||
--network "$NETWORK" \
|
cmd docker cp "$tmp_dir/peer4.toml" "$PEER4_CONTAINER:/app/invite.toml"
|
||||||
--ip 172.18.1.4 \
|
PEER5_CONTAINER=$(create_peer_docker 172.18.1.5)
|
||||||
--volume /dev/net/tun:/dev/net/tun \
|
cmd docker cp "$tmp_dir/peer5.toml" "$PEER5_CONTAINER:/app/invite.toml"
|
||||||
--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: /' &
|
cmd docker start -a "$PEER4_CONTAINER" | sed -e 's/^/\x1B[0;92mpeer 4\x1B[0m: /' &
|
||||||
info "peer4 started as $PEER4_CONTAINER"
|
info "peer4 started as $PEER4_CONTAINER"
|
||||||
cmd docker start -a "$PEER5_CONTAINER" | sed -e 's/^/\x1B[0;94mpeer 5\x1B[0m: /' &
|
cmd docker start -a "$PEER5_CONTAINER" | sed -e 's/^/\x1B[0;94mpeer 5\x1B[0m: /' &
|
||||||
info "peer5 started as $PEER5_CONTAINER"
|
info "peer5 started as $PEER5_CONTAINER"
|
||||||
|
|
||||||
info "Checking connectivity betweeen peers."
|
info "Checking connectivity betweeen peers."
|
||||||
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1
|
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1
|
||||||
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1
|
cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run tests (functions prefixed with test_) in alphabetical order.
|
||||||
|
# Optional filter provided by positional arguments is applied.
|
||||||
|
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."
|
||||||
|
|
|
@ -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
|
||||||
|
if [[ $CLIENT_ARGS =~ --verbose ]]; then
|
||||||
innernet $INNERNET_ARGS up --no-write-hosts "$INTERFACE"
|
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
|
||||||
|
|
Loading…
Reference in New Issue