57 lines
1.6 KiB
Bash
Executable File
57 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repository_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
workspace_venv="$repository_root/../.venv"
|
|
test_tmp=$(mktemp -d)
|
|
chmod 0700 "$test_tmp"
|
|
|
|
export ANSIBLE_COLLECTIONS_PATH="$test_tmp/collections"
|
|
export ANSIBLE_ROLES_PATH="$(dirname "$repository_root")"
|
|
|
|
inventory="$repository_root/tests/inventory"
|
|
converge="$repository_root/tests/converge.yml"
|
|
ansible_playbook="$workspace_venv/bin/ansible-playbook"
|
|
binary_path=/usr/local/bin/scriptorium
|
|
config_path=/usr/local/etc/scriptorium/config.yml
|
|
profile_dir="$test_tmp/profiles"
|
|
|
|
cleanup() {
|
|
exit_status=$?
|
|
trap - EXIT
|
|
"$ansible_playbook" -i "$inventory" "$converge" >/dev/null 2>&1 || true
|
|
rm -rf -- "$test_tmp"
|
|
exit "$exit_status"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
require_clean_recap() {
|
|
grep -Eq 'changed=0 .*failed=0' "$1"
|
|
}
|
|
|
|
run_converge() {
|
|
output_file=$1
|
|
"$ansible_playbook" -i "$inventory" "$converge" | tee "$output_file"
|
|
}
|
|
|
|
mkdir -p "$profile_dir"
|
|
printf '%s\n' \
|
|
'id: endpoint-profile' \
|
|
'endpoint: http://127.0.0.1:8000/v1' \
|
|
'model: offline-fixture' > "$profile_dir/endpoint-profile.yml"
|
|
|
|
cd "$repository_root"
|
|
"$workspace_venv/bin/ansible-galaxy" collection install \
|
|
-r collections/requirements.yml \
|
|
-p "$ANSIBLE_COLLECTIONS_PATH"
|
|
"$ansible_playbook" -i "$inventory" --syntax-check "$converge"
|
|
"$workspace_venv/bin/ansible-lint" "$converge"
|
|
|
|
baseline_log="$test_tmp/baseline.log"
|
|
run_converge "$baseline_log"
|
|
"$binary_path" inspect profile --config "$config_path" \
|
|
--profile-dir "$profile_dir" --profile endpoint-profile
|
|
baseline_repeat_log="$test_tmp/baseline-repeat.log"
|
|
run_converge "$baseline_repeat_log"
|
|
require_clean_recap "$baseline_repeat_log"
|