test (3498B)
1 #!/bin/bash 2 set -euo pipefail 3 export ANSIBLE_NOCOWS=1 4 5 repo_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) 6 cd "$repo_dir" 7 8 test_image=ansible-taler-test 9 test_container=ansible-taler-test-$$ 10 test_state_dir=$(mktemp -d) 11 12 cleanup() { 13 if [[ ${TALER_TEST_KEEP_CONTAINER:-0} == 1 ]]; then 14 echo "Kept test container $test_container and test files $test_state_dir" 15 return 16 fi 17 podman rm --force "$test_container" >/dev/null 2>&1 || true 18 rm -rf -- "${test_state_dir:?}" 19 } 20 trap cleanup EXIT 21 22 ssh-keygen -q -t ed25519 -N "" -f "$test_state_dir/id_ed25519" 23 24 # Fast isolated regressions run before the complete deployment. 25 python3 contrib/tests/test_backup.py 26 python3 contrib/tests/test_upgrade_policy.py 27 python3 contrib/tests/test_monitoring_listeners.py 28 29 # Build our image 30 podman build -f Containerfile -t "$test_image" 31 32 # Exercise interrupted deployment recovery with isolated service fixtures. 33 python3 contrib/tests/test_deployment_recovery.py --image "localhost/$test_image" 34 35 # Run in background (-d) with systemd init. Taler's hardened systemd units 36 # require capabilities that Podman otherwise removes from the container. 37 podman run \ 38 --rm \ 39 --name "$test_container" \ 40 -p 127.0.0.1:8022:22 \ 41 --systemd=always \ 42 --privileged \ 43 -d "localhost/$test_image" sh -c "exec /usr/sbin/init --show-status" 44 45 # Use a disposable key because the deployment correctly disables SSH password 46 # authentication, and check mode runs in a separate SSH session afterwards. 47 podman exec "$test_container" install -d -m 0700 /root/.ssh 48 podman cp "$test_state_dir/id_ed25519.pub" "$test_container:/root/.ssh/authorized_keys" 49 podman exec "$test_container" chmod 0600 /root/.ssh/authorized_keys 50 51 # Print to log that container is running 52 podman ps 53 54 export ANSIBLE_CONFIG="$repo_dir/test-ansible.cfg" 55 export ANSIBLE_SSH_ARGS="-o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=$test_state_dir/known_hosts" 56 57 for attempt in {1..30}; do 58 if ssh \ 59 -i "$test_state_dir/id_ed25519" \ 60 -p 8022 \ 61 -o StrictHostKeyChecking=no \ 62 -o "UserKnownHostsFile=$test_state_dir/known_hosts" \ 63 root@127.0.0.1 true; then 64 break 65 fi 66 if (( attempt == 30 )); then 67 echo "SSH did not become ready in the test container" >&2 68 exit 1 69 fi 70 sleep 1 71 done 72 73 ansible_args=( 74 -i inventories/default 75 -l podman-localhost 76 --user root 77 --private-key "$test_state_dir/id_ed25519" 78 playbooks/setup.yml 79 ) 80 81 # Provision, then prove that a separate check-mode run can inspect the result. 82 ansible-playbook --verbose --diff "${ansible_args[@]}" | tee "$test_state_dir/setup.log" 83 python3 contrib/tests/test_deployment.py \ 84 "$test_container" "$test_state_dir/id_ed25519" "$test_state_dir/setup.log" 85 python3 contrib/tests/test_monitoring.py \ 86 "$test_container" "$test_state_dir/id_ed25519" 87 88 # Basic smoke checks independent of Ansible's post-deployment checks. 89 podman exec "$test_container" systemctl is-active --quiet \ 90 taler-exchange.target \ 91 taler-exchange-httpd.service \ 92 libeufin-nexus-httpd.service \ 93 taler-auditor-httpd.service 94 podman exec "$test_container" curl --fail --silent --show-error \ 95 --unix-socket /var/run/taler-exchange/httpd/exchange-http.sock \ 96 http://localhost/config >/dev/null 97 podman exec "$test_container" curl --fail --silent --show-error \ 98 http://127.0.0.1:8082/taler-prepared-transfer/config >/dev/null 99 podman exec "$test_container" curl --fail --silent --show-error \ 100 --unix-socket /var/run/taler-auditor/httpd/auditor-http.sock \ 101 http://localhost/config >/dev/null