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