Files
archy/scripts/test-c01-network-systemd-isolated.sh

40 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT=$(git rev-parse --show-toplevel)
ATTEMPT=${1:?unique attempt required}
REPORT=${2:?new absolute report directory required}
[[ "$ATTEMPT" =~ ^[a-z0-9-]+$ && "$REPORT" = /* && ! -e "$REPORT" && $(id -u) != 0 ]]
[[ $(podman info --format '{{.Host.Security.Rootless}}') == true ]]
NAME="archy-c01-network-$ATTEMPT"
! podman container exists "$NAME"
IMAGE=$(podman image inspect localhost/archipelago-rootfs:latest --format '{{.Id}}')
umask 077
mkdir "$REPORT"
printf '%s\n' "$IMAGE" > "$REPORT/image-id.txt"
sha256sum scripts/c01_network{,_owner,_client}.py scripts/c01_endpoints.py \
image-recipe/configs/archipelago-c01-network.service tests/regression/c01-network-systemd.py > "$REPORT/source.sha256"
cleanup() {
local status=$?
podman exec "$NAME" journalctl --no-pager > "$REPORT/journal.log" 2>&1 || true
podman logs "$NAME" > "$REPORT/container.log" 2>&1 || true
podman stop --time 10 "$NAME" > "$REPORT/stop.log" 2>&1 || true
printf '%s\n' "$status" > "$REPORT/exit-code.txt"
}
# Retain startup failures as well as fixture failures.
trap cleanup EXIT
podman run --detach --tty --pull=never --name "$NAME" --hostname d09-qualification \
--network=none --cgroupns=private --systemd=always --security-opt=unmask=ALL --cap-add=SYS_ADMIN --cap-add=SYS_PTRACE \
--cap-add=NET_ADMIN --memory=1g --cpus=1 --pids-limit=256 --tmpfs /run --tmpfs /tmp \
--entrypoint /sbin/init "$IMAGE" --unit=basic.target --log-target=console > "$REPORT/container-id.txt"
podman exec "$NAME" install -d /opt/d09-fixture/image-recipe /opt/d09-fixture/tests/regression
podman cp "$ROOT/scripts" "$NAME:/opt/d09-fixture/scripts"
podman cp "$ROOT/image-recipe/configs" "$NAME:/opt/d09-fixture/image-recipe/configs"
podman cp "$ROOT/tests/regression/c01-network-systemd.py" "$NAME:/opt/d09-fixture/tests/regression/c01-network-systemd.py"
podman exec "$NAME" chown -R root:root /opt/d09-fixture
podman exec --workdir /opt/d09-fixture "$NAME" sha256sum \
scripts/c01_network.py scripts/c01_network_owner.py scripts/c01_network_client.py scripts/c01_endpoints.py \
image-recipe/configs/archipelago-c01-network.service tests/regression/c01-network-systemd.py > "$REPORT/copied.sha256"
cmp "$REPORT/source.sha256" "$REPORT/copied.sha256"
podman exec --env C01_NETWORK_FIXTURE=1 "$NAME" python3 \
/opt/d09-fixture/tests/regression/c01-network-systemd.py 2>&1 | tee "$REPORT/test.log"