11#! /usr/bin/env bash
22set -euo pipefail
33
4- AU_FROM_SEED=" $1 "
5- OS_IMAGE=" $2 "
4+ # AU_FROM_SEED="false"
5+ # OS_IMAGE="Rocky9"
6+ # TAINT_REBUILD="false"
67
78echo " Starting AUFN test action with:"
89echo " AU_FROM_SEED: $AU_FROM_SEED "
@@ -23,107 +24,123 @@ function check_lab_vm_connections() {
2324 ip=$( echo " $line " | awk ' {print $2}' )
2425 name=$( echo " $line " | awk ' {print $3}' )
2526 password=$( echo " $line " | awk ' {print $5}' )
26- echo " ::add-mask::$password "
2727
28- echo " Connecting to $name at $ip via bastion ..."
28+ echo " Connecting to $name ( $password ) at $ip ..."
2929 sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
30- " ${LAB_IMAGE_USER} @${ip} " ' echo "Connected to $(hostname)"'
30+ " lab @${ip} " ' echo "Connected to $(hostname)"'
3131 done < ssh_list.txt
3232}
3333
3434function validate_lab_vms() {
3535 echo " Validating Lab VMs setup..."
3636 index=0
37- failed_indexes=()
37+ rm -f failed-labs.txt
38+
3839 while IFS= read -r line; do
3940 ip=$( echo " $line " | awk ' {print $2}' )
4041 name=$( echo " $line " | awk ' {print $3}' )
41- password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
42+ password=$( echo " $line " | awk ' {print $5}' )
4243
4344 echo " Validating $name at $ip ..."
4445
45- taint=" false"
46-
47- sshpass -p " $password " ssh -o StrictHostKeyChecking=no " ${LAB_IMAGE_USER} @${ip} " << 'EOF '
46+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
47+ " lab@${ip} " << 'EOF '
4848 output=$(sudo virsh list --all)
4949 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
50+ if ! echo "$output" | grep -q 'seed.*running'; then echo "'seed' not running"; fi
51+ if ! echo "$output" | grep -q 'compute0.*shut off'; then echo "'compute0' not shut off"; fi
52+ if ! echo "$output" | grep -q 'controller0.*shut off'; then echo "'controller0' not shut off"; fi
53+
54+ echo "$(ssh [email protected] 'sudo docker ps')" 55+ if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then echo "Bifrost container isn't deployed"; fi 56+ if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then echo "There was an error in running 'a-seed-from-nothing'"; fi
57+ EOF
58+
59+ set +e
60+
61+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
62+ " lab@${ip} " << 'EOF '
63+ output=$(sudo virsh list --all)
64+ if ! echo "$output" | grep -q 'seed.*running'; then exit 1; fi
65+ if ! echo "$output" | grep -q 'compute0.*shut off'; then exit 1; fi
66+ if ! echo "$output" | grep -q 'controller0.*shut off'; then exit 1; fi
5367
5468 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 5669 if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
70+
71+ exit 0
5772EOF
58- if [[ $? -ne 0 ]]; then failed_indexes+=($index ); fi
73+ taint_res=$?
74+ echo " exit error is -> $taint_res "
75+ if [ $taint_res -gt 0 ]; then echo " $index " >> failed-labs.txt ; fi
5976 index=$(( index + 1 ))
77+ set -euo pipefail
6078 done < ssh_list.txt
61-
62- echo " FAILED_VM_INDEXES=${failed_indexes[*]} " >> " $GITHUB_ENV "
6379}
6480
6581function taint_and_reapply() {
66- if [ -z " ${FAILED_VM_INDEXES :- } " ]; then
67- echo " ✅ No failed VMs detected"
82+ if [ ! -s failed-labs.txt ]; then
83+ echo " No failed VMs detected"
6884 return
6985 fi
7086
7187 echo " Tainting failed VMs..."
72- for idx in $FAILED_VM_INDEXES ; do
73- terraform taint " openstack_compute_instance_v2.lab[$idx ]"
74- done
88+ while IFS= read -r line; do
89+ idx=$( echo " $line " | tr -d ' \r' )
90+ echo " Tainting VM at index $idx "
91+ terraform taint openstack_compute_instance_v2.lab[$idx ]
92+ done < failed-labs.txt
93+ echo " Rebuilding tainted Lab VMs..."
7594 terraform apply -auto-approve
95+ wait
7696}
7797
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- }
98+ # function run_universe_from_seed() {
99+ # if [[ "$AU_FROM_SEED" != "true" ]]; then return; fi
100+ # echo "Launching a-universe-from-seed..."
101+ # mapfile -t ssh_lines < ssh_list.txt
102+ # for i in "${!ssh_lines[@]}"; do
103+ # line="${ssh_lines[$i]}"
104+ # ip=$(echo "$line" | awk '{print $2}')
105+ # name=$(echo "$line" | awk '{print $3}')
106+ # password=$(echo "$line" | awk '{print $5}')
107+
108+ # sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
109+ # "lab@${ip}" \
110+ # "tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
111+ # done
112+ # }
103113
104114function run_universe_from_seed() {
105115 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]} "
116+ echo " Launching a-universe-from-seed..."
117+ while IFS= read -r line; do
110118 ip=$( echo " $line " | awk ' {print $2}' )
111119 name=$( echo " $line " | awk ' {print $3}' )
112- password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
120+ password=$( echo " $line " | awk ' {print $5}' )
113121
114122 sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
115- " ${LAB_IMAGE_USER} @${ip} " \
123+ " lab @${ip} " \
116124 " tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
117- done
125+ done < ssh_list.txt
118126}
119127
120128# === RUN STEPS ===
129+ sleep 90 # Wait for VMs to be ready
130+
121131check_lab_vm_connections
122132validate_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
133+
134+
135+ if [[ " $TAINT_REBUILD " = " true" ]]; then
136+ taint_and_reapply
137+ terraform output -json > tf-outputs.json
138+ terraform output -raw labs > ssh_list.txt
139+ validate_lab_vms
140+ else
141+ echo " Tainting and rebuilding is disabled, skipping..."
142+ fi
143+
127144run_universe_from_seed
128145
129146echo " AUFN Test completed successfully!"
0 commit comments