the-bastion/tests/functional/docker/tester_role.sh
Stéphane Lesimple c201f44d83 enh: tests: refactor the framework for more maintainability
The chain of executions is as is:
- `docker_build_and_run_tests_all.sh`
  - launches several instances of `docker_build_and_run_tests.sh`
    - builds docker images with the `target_role.sh` and `tester_role.sh` entrypoints
      - inside the tester docker, `tester_role.sh` launches `launch_tests_on_instance.sh`
      - the target docker gets tested after setting up accounts, SSH etc.

Previously, these scripts passed options to each other either by a mix of environment
variables and command-line arguments, with some inconsistencies here and there.

Now, `launch_tests_on_instance.sh` supports a lot of command-line options, which can
be specified directly if testing a remote server, or can be passed-through by the calling
script in case of docker tests. `docker_build_and_run_tests.sh` and
`docker_build_and_run_tests_all.sh` also support to passthrough these options down.
2021-06-25 16:02:38 +02:00

49 lines
1.7 KiB
Bash
Executable file

#! /usr/bin/env bash
# vim: set filetype=sh ts=4 sw=4 sts=4 et:
set -e
set -u
basedir=$(readlink -f "$(dirname "$0")"/../../..)
# shellcheck source=lib/shell/colors.inc
. "$basedir"/lib/shell/colors.inc
printf '%b>>> %b <<<%b\n' "$BOLD_CYAN" "SETTING UP KEYS" "$NOC"
base64 -d <<< "$USER_PRIVKEY_B64" > /root/user.privkey
chmod 400 /root/user.privkey
base64 -d <<< "$ROOT_PRIVKEY_B64" > /root/root.privkey
chmod 400 /root/root.privkey
printf '%b>>> %b <<<%b\n' "$BOLD_CYAN" "STARTING TESTS" "$NOC"
chmod 755 "$(dirname "$0")/../launch_tests_on_instance.sh"
mkdir -p /root/.ssh
delay=10
for i in $(seq 1 $delay); do
echo "tester: waiting for target docker to be up ($i/$delay)..."
fping -r 1 "$TARGET_IP" && break
done
if [ "$i" = "$delay" ]; then
echo "tester: Error, target doesn't answer to pings after $delay tries :("
exit 255
fi
delay=300
for i in $(seq 1 $delay); do
echo "tester: waiting for target SSH to be up ($i/$delay)..."
sleep 1
if echo test | nc -w 1 "$TARGET_IP" "$TARGET_PORT" | grep -q ^SSH-2 ; then
echo "tester: it's alive, starting tests!"
# we want EXTRA_OPTIONS to expand
# shellcheck disable=SC2086
"$(dirname "$0")"/../launch_tests_on_instance.sh ${EXTRA_OPTIONS:-} "$TARGET_IP" "$TARGET_PORT" "${TARGET_PROXY_PORT:-0}" "$TARGET_USER" /root/user.privkey /root/root.privkey; ret=$?
[ "$ret" -gt 253 ] && ret=253
exit "$ret"
elif ! fping -r 1 "$TARGET_IP" >/dev/null 2>&1; then
echo "tester: Error, target stopped pinging before SSH was up, problem in target_role.sh entrypoint?"
exit 255
fi
done
echo "tester: Error, target is not alive or not listening for SSH :("
exit 255