1
1
#! /usr/bin/env bash
2
2
set -euo pipefail
3
3
4
- AU_FROM_SEED=" $1 "
5
- OS_IMAGE=" $2 "
4
+ # AU_FROM_SEED="false"
5
+ # OS_IMAGE="Rocky9"
6
+ # TAINT_REBUILD="false"
6
7
7
8
echo " Starting AUFN test action with:"
8
9
echo " AU_FROM_SEED: $AU_FROM_SEED "
@@ -23,107 +24,123 @@ function check_lab_vm_connections() {
23
24
ip=$( echo " $line " | awk ' {print $2}' )
24
25
name=$( echo " $line " | awk ' {print $3}' )
25
26
password=$( echo " $line " | awk ' {print $5}' )
26
- echo " ::add-mask::$password "
27
27
28
- echo " Connecting to $name at $ip via bastion ..."
28
+ echo " Connecting to $name ( $password ) at $ip ..."
29
29
sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
30
- " ${LAB_IMAGE_USER} @${ip} " ' echo "Connected to $(hostname)"'
30
+ " lab @${ip} " ' echo "Connected to $(hostname)"'
31
31
done < ssh_list.txt
32
32
}
33
33
34
34
function validate_lab_vms() {
35
35
echo " Validating Lab VMs setup..."
36
36
index=0
37
- failed_indexes=()
37
+ rm -f failed-labs.txt
38
+
38
39
while IFS= read -r line; do
39
40
ip=$( echo " $line " | awk ' {print $2}' )
40
41
name=$( echo " $line " | awk ' {print $3}' )
41
- password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
42
+ password=$( echo " $line " | awk ' {print $5}' )
42
43
43
44
echo " Validating $name at $ip ..."
44
45
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 '
48
48
output=$(sudo virsh list --all)
49
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
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 stack@192.168.33.5 'sudo docker ps')"
55
+ if ! ssh stack@192.168.33.5 '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
53
67
54
68
if ! ssh stack@192.168.33.5 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi
55
- if ! ssh stack@192.168.33.5 'sudo dnf info openssh' | grep -q 'Repository *: *@System'; then exit 1; fi
56
69
if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
70
+
71
+ exit 0
57
72
EOF
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
59
76
index=$(( index + 1 ))
77
+ set -euo pipefail
60
78
done < ssh_list.txt
61
-
62
- echo " FAILED_VM_INDEXES=${failed_indexes[*]} " >> " $GITHUB_ENV "
63
79
}
64
80
65
81
function 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"
68
84
return
69
85
fi
70
86
71
87
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..."
75
94
terraform apply -auto-approve
95
+ wait
76
96
}
77
97
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 stack@192.168.33.5 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi
98
- if ! ssh stack@192.168.33.5 '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
+ # }
103
113
104
114
function run_universe_from_seed() {
105
115
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
110
118
ip=$( echo " $line " | awk ' {print $2}' )
111
119
name=$( echo " $line " | awk ' {print $3}' )
112
- password=$( echo " $line " | awk ' {print $5}' ) > /dev/null
120
+ password=$( echo " $line " | awk ' {print $5}' )
113
121
114
122
sshpass -p " $password " ssh -o StrictHostKeyChecking=no \
115
- " ${LAB_IMAGE_USER} @${ip} " \
123
+ " lab @${ip} " \
116
124
" tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
117
- done
125
+ done < ssh_list.txt
118
126
}
119
127
120
128
# === RUN STEPS ===
129
+ sleep 90 # Wait for VMs to be ready
130
+
121
131
check_lab_vm_connections
122
132
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
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
+
127
144
run_universe_from_seed
128
145
129
146
echo " AUFN Test completed successfully!"
0 commit comments