Skip to content

Commit 6894efa

Browse files
committed
Add composite workflow for testing
1 parent 82d054d commit 6894efa

File tree

5 files changed

+169
-312
lines changed

5 files changed

+169
-312
lines changed

.github/actions/aufn-test/action.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,33 @@ inputs:
99
os_image:
1010
description: Host OS image
1111
required: true
12+
taint_rebuild:
13+
description: Taint and rebuild failed Lab VMs?
14+
default: 'false'
15+
required: false
16+
working_dir:
17+
description: Working directory for terraform
18+
1219

1320
runs:
1421
using: "composite"
1522
steps:
16-
- name: Run AUFN test logic
23+
# - name: Set up environment variables
24+
# shell: bash
25+
# run: |
26+
# echo "BAS_PWD=${{ inputs.bas_pwd }}" >> $GITHUB_ENV
27+
# echo "AU_FROM_SEED=${{ inputs.au_from_seed }}" >> $GITHUB_ENV
28+
# echo "OS_IMAGE=${{ inputs.os_image }}" >> $GITHUB_ENV
29+
# echo "TAINT_REBUILD=${{ inputs.taint_rebuild }}" >> $GITHUB_ENV
30+
31+
- name: Run AUFN Deployment test logic
1732
shell: bash
1833
run: |
19-
chmod +x "${GITHUB_ACTION_PATH}/run.sh"
20-
"${GITHUB_ACTION_PATH}/run.sh" \
21-
"${{ inputs.au_from_seed }}" \
22-
"${{ inputs.os_image }}"
34+
cd "${{ inputs.working_dir }}"
35+
cp "${GITHUB_ACTION_PATH}/run.sh" .
36+
chmod +x run.sh
37+
./run.sh
38+
env:
39+
AU_FROM_SEED: ${{ inputs.au_from_seed }}
40+
OS_IMAGE: ${{ inputs.os_image }}
41+
TAINT_REBUILD: ${{ inputs.taint_rebuild }}

.github/actions/aufn-test/run.sh

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env bash
22
set -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

78
echo "Starting AUFN test action with:"
89
echo "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

3434
function 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 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
5367
5468
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
5669
if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
70+
71+
exit 0
5772
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
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

6581
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"
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 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+
# }
103113

104114
function 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+
121131
check_lab_vm_connections
122132
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+
127144
run_universe_from_seed
128145

129146
echo "AUFN Test completed successfully!"

0 commit comments

Comments
 (0)