1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ AU_FROM_SEED=" $1 "
5+ OS_IMAGE=" $2 "
6+
7+ echo " Starting AUFN test action with:"
8+ echo " AU_FROM_SEED: $AU_FROM_SEED "
9+ echo " OS Image: $OS_IMAGE "
10+
11+ if [[ " $OS_IMAGE " == " Ubuntu" ]]; then
12+ export LAB_IMAGE_USER=" ubuntu"
13+ elif [[ " $OS_IMAGE " == " Rocky9" ]]; then
14+ export LAB_IMAGE_USER=" rocky"
15+ else
16+ echo " Unsupported OS image: $OS_IMAGE "
17+ exit 1
18+ fi
19+
20+ function check_lab_vm_connections() {
21+ echo " Checking VM connections..."
22+ while IFS= read -r line; do
23+ ip=$( echo " $line " | awk ' {print $2}' )
24+ name=$( echo " $line " | awk ' {print $3}' )
25+ password=$( echo " $line " | awk ' {print $5}' )
26+ echo " ::add-mask::$password "
27+
28+ echo " Connecting to $name at $ip via bastion..."
29+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
30+ " ${LAB_IMAGE_USER} @${ip} " ' echo "Connected to $(hostname)"'
31+ done < ssh_list.txt
32+ }
33+
34+ function validate_lab_vms() {
35+ echo " Validating Lab VMs setup..."
36+ index=0
37+ failed_indexes=()
38+ while IFS= read -r line; do
39+ ip=$( echo " $line " | awk ' {print $2}' )
40+ name=$( echo " $line " | awk ' {print $3}' )
41+ password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
42+
43+ echo " Validating $name at $ip ..."
44+
45+ taint=" false"
46+
47+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no " ${LAB_IMAGE_USER} @${ip} " << 'EOF '
48+ output=$(sudo virsh list --all)
49+ echo "$output"
50+ if ! echo "$output" | grep -q 'seed.*running'; then echo "'seed' not running"; exit 1; fi
51+ if ! echo "$output" | grep -q 'compute0.*shut off'; then echo "'compute0' not shut off"; exit 1; fi
52+ if ! echo "$output" | grep -q 'controller0.*shut off'; then echo "'controller0' not shut off"; exit 1; fi
53+
54+ if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi 55+ if ! ssh [email protected] 'sudo dnf info openssh' | grep -q 'Repository *: *@System'; then exit 1; fi 56+ if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
57+ EOF
58+ if [[ $? -ne 0 ]]; then failed_indexes+=($index ); fi
59+ index=$(( index + 1 ))
60+ done < ssh_list.txt
61+
62+ echo " FAILED_VM_INDEXES=${failed_indexes[*]} " >> " $GITHUB_ENV "
63+ }
64+
65+ function taint_and_reapply() {
66+ if [ -z " ${FAILED_VM_INDEXES:- } " ]; then
67+ echo " ✅ No failed VMs detected"
68+ return
69+ fi
70+
71+ echo " Tainting failed VMs..."
72+ for idx in $FAILED_VM_INDEXES ; do
73+ terraform taint " openstack_compute_instance_v2.lab[$idx ]"
74+ done
75+ terraform apply -auto-approve
76+ }
77+
78+ function post_redeploy_checks() {
79+ echo " Re-testing failed VMs after redeploy..."
80+ mapfile -t ssh_lines < ssh_list.txt
81+ for idx in $FAILED_VM_INDEXES ; do
82+ line=" ${ssh_lines[$idx]} "
83+ ip=$( echo " $line " | awk ' {print $2}' )
84+ name=$( echo " $line " | awk ' {print $3}' )
85+ password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
86+
87+
88+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no " ${LAB_IMAGE_USER} @${ip} " << 'EOF ' || {
89+ terraform destroy -auto-approve
90+ exit 1
91+ }
92+ output=$(sudo virsh list --all)
93+ echo "$output"
94+ if ! echo "$output" | grep -q 'seed.*running'; then exit 1; fi
95+ if ! echo "$output" | grep -q 'compute0.*shut off'; then exit 1; fi
96+ if ! echo "$output" | grep -q 'controller0.*shut off'; then exit 1; fi
97+ if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi 98+ if ! ssh [email protected] 'sudo dnf info openssh' | grep -q 'Repository *: *@System'; then exit 1; fi 99+ if ! tail -n 20 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
100+ EOF
101+ done
102+ }
103+
104+ function run_universe_from_seed() {
105+ if [[ " $AU_FROM_SEED " != " true" ]]; then return ; fi
106+ echo " 🌌 Launching a-universe-from-seed..."
107+ mapfile -t ssh_lines < ssh_list.txt
108+ for i in " ${! ssh_lines[@]} " ; do
109+ line=" ${ssh_lines[$i]} "
110+ ip=$( echo " $line " | awk ' {print $2}' )
111+ name=$( echo " $line " | awk ' {print $3}' )
112+ password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
113+
114+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
115+ " ${LAB_IMAGE_USER} @${ip} " \
116+ " tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
117+ done
118+ }
119+
120+ # === RUN STEPS ===
121+ check_lab_vm_connections
122+ validate_lab_vms
123+ taint_and_reapply
124+ terraform output -json > tf-outputs.json
125+ terraform output -raw labs > ssh_list.txt
126+ post_redeploy_checks
127+ run_universe_from_seed
128+
129+ echo " AUFN Test completed successfully!"
0 commit comments