11#! /usr/bin/env bash
22set -euo pipefail
33
4- AU_FROM_SEED=" true"
4+ # AU_FROM_SEED="true"
55# OS_IMAGE="Rocky9"
6- TAINT_REBUILD=" true"
6+ # TAINT_REBUILD="true"
77
88echo " Starting AUFN test action with:"
99echo " AU_FROM_SEED: $AU_FROM_SEED "
8888# echo >> failed-labs.txt
8989}
9090
91+ function validate_universe_from_seed() {
92+ echo && echo
93+ echo " Validating Lab VMs setup..."
94+ index=0
95+ rm -f failed-labs.txt
96+
97+ while IFS= read -r line; do
98+ ip=$( echo " $line " | awk ' {print $3}' )
99+ name=$( echo " $line " | awk ' {print $2}' )
100+ password=$( echo " $line " | awk ' {print $5}' )
101+
102+ echo && echo
103+ echo " Validating $name at $ip ..." && echo
104+
105+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no\
106+ " lab@${ip} " << 'EOF '
107+ output=$(sudo virsh list --all)
108+ echo "$output"
109+ if ! echo "$output" | grep -q 'seed.*running'; then echo "'seed' not running"; fi
110+ if ! echo "$output" | grep -q 'compute0.*running'; then echo "'compute0' not running"; fi
111+ if ! echo "$output" | grep -q 'controller0.*running'; then echo "'controller0' not running"; fi
112+
113+ echo && echo
114+ echo "$(ssh [email protected] 'sudo docker ps')" 115+ if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then echo "Bifrost container isn't deployed"; fi 116+ if ! tail -n 10 a-universe-from-seed.out | grep -q 'PLAY RECAP.*failed=0'; then echo "There was an error in running 'a-universe-from-seed'"; fi
117+ EOF
118+
119+ set +e
120+
121+ sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
122+ " lab@${ip} " << 'EOF '
123+ output=$(sudo virsh list --all)
124+ if ! echo "$output" | grep -q 'seed.*running'; then exit 1; fi
125+ if ! echo "$output" | grep -q 'compute0.*running'; then exit 1; fi
126+ if ! echo "$output" | grep -q 'controller0.*running'; then exit 1; fi
127+
128+ if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi 129+ if ! tail -n 10 a-universe-from-seed.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
130+
131+ exit 0
132+ EOF
133+ taint_res=$?
134+ echo " exit error is -> $taint_res "
135+ if [ $taint_res -gt 0 ]; then echo " $index " >> failed-labs.txt ; fi
136+ index=$(( index + 1 ))
137+ set -euo pipefail
138+ done < ssh_list.txt
139+ # echo >> failed-labs.txt
140+ }
141+
142+
91143function taint_and_reapply() {
92144 if [ ! -s failed-labs.txt ]; then
93145 echo " No failed VMs detected"
@@ -107,50 +159,44 @@ function taint_and_reapply() {
107159
108160# function run_universe_from_seed() {
109161# if [[ "$AU_FROM_SEED" != "true" ]]; then return; fi
110- # echo "Launching a-universe-from-seed..."
111- # mapfile -t ssh_lines < ssh_list.txt
112- # for i in "${!ssh_lines[@]}"; do
113- # line="${ssh_lines[$i]}"
162+ # echo "Running a-universe-from-seed..."
163+ # while IFS= read -r line; do
114164# ip=$(echo "$line" | awk '{print $3}')
115165# name=$(echo "$line" | awk '{print $2}')
116166# password=$(echo "$line" | awk '{print $5}')
117167
118168# sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
119169# "lab@${ip}" \
120170# "tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
121- # done
171+ # done < ssh_list.txt
122172# }
123173
124- function run_universe_from_seed() {
125- if [[ " $AU_FROM_SEED " != " true" ]]; then return ; fi
126- echo " Launching a-universe-from-seed..."
127- while IFS= read -r line; do
128- ip=$( echo " $line " | awk ' {print $3}' )
129- name=$( echo " $line " | awk ' {print $2}' )
130- password=$( echo " $line " | awk ' {print $5}' )
131174
132- sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
133- " lab@${ip} " \
134- " tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
135- done < ssh_list.txt
136- }
137175
138176# === RUN STEPS ===
139177sleep 90 # Wait for VMs to be ready
140178
141179check_lab_vm_connections
142- validate_lab_vms
143180
181+ if [[ " $AU_FROM_SEED " = " false" ]]; then
182+ validate_lab_vms
183+ else
184+ validate_universe_from_seed
185+ fi
144186
145187if [[ " $TAINT_REBUILD " = " true" && ! -s failed-labs.txt ]]; then
146188 taint_and_reapply
147189 terraform output -json > tf-outputs.json
148190 terraform output -raw labs > ssh_list.txt
149- validate_lab_vms
191+
192+ if [[ " $AU_FROM_SEED " = " false" ]]; then
193+ validate_lab_vms
194+ else
195+ validate_universe_from_seed
196+ fi
197+
150198else
151199 echo " Tainting and rebuilding is disabled, skipping..."
152200fi
153201
154- run_universe_from_seed
155-
156202echo " AUFN Test completed successfully!"
0 commit comments