Skip to content

Commit 82d054d

Browse files
committed
Use composite actions for testing
1 parent 594786e commit 82d054d

File tree

3 files changed

+153
-3
lines changed

3 files changed

+153
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: AUFN Test Action
2+
description: Deploy and validate Lab VMs
3+
4+
inputs:
5+
au_from_seed:
6+
description: Run 'A Universe From Seed'?
7+
default: 'false'
8+
required: false
9+
os_image:
10+
description: Host OS image
11+
required: true
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Run AUFN test logic
17+
shell: bash
18+
run: |
19+
chmod +x "${GITHUB_ACTION_PATH}/run.sh"
20+
"${GITHUB_ACTION_PATH}/run.sh" \
21+
"${{ inputs.au_from_seed }}" \
22+
"${{ inputs.os_image }}"

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

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
function check_lab_vm_connections() {
21+
echo "Checking VM connections..."
22+
while IFS= read -r line; do
23+
ip=$(echo "$line" | awk '{print $2}')
24+
name=$(echo "$line" | awk '{print $3}')
25+
password=$(echo "$line" | awk '{print $5}')
26+
echo "::add-mask::$password"
27+
28+
echo "Connecting to $name at $ip via bastion..."
29+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
30+
"${LAB_IMAGE_USER}@${ip}" 'echo "Connected to $(hostname)"'
31+
done < ssh_list.txt
32+
}
33+
34+
function validate_lab_vms() {
35+
echo "Validating Lab VMs setup..."
36+
index=0
37+
failed_indexes=()
38+
while IFS= read -r line; do
39+
ip=$(echo "$line" | awk '{print $2}')
40+
name=$(echo "$line" | awk '{print $3}')
41+
password=$(echo "$line" | awk '{print $5}') > /dev/null
42+
43+
echo "Validating $name at $ip..."
44+
45+
taint="false"
46+
47+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "${LAB_IMAGE_USER}@${ip}" <<'EOF'
48+
output=$(sudo virsh list --all)
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
53+
54+
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+
if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
57+
EOF
58+
if [[ $? -ne 0 ]]; then failed_indexes+=($index); fi
59+
index=$((index + 1))
60+
done < ssh_list.txt
61+
62+
echo "FAILED_VM_INDEXES=${failed_indexes[*]}" >> "$GITHUB_ENV"
63+
}
64+
65+
function taint_and_reapply() {
66+
if [ -z "${FAILED_VM_INDEXES:-}" ]; then
67+
echo "✅ No failed VMs detected"
68+
return
69+
fi
70+
71+
echo "Tainting failed VMs..."
72+
for idx in $FAILED_VM_INDEXES; do
73+
terraform taint "openstack_compute_instance_v2.lab[$idx]"
74+
done
75+
terraform apply -auto-approve
76+
}
77+
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+
}
103+
104+
function run_universe_from_seed() {
105+
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]}"
110+
ip=$(echo "$line" | awk '{print $2}')
111+
name=$(echo "$line" | awk '{print $3}')
112+
password=$(echo "$line" | awk '{print $5}') > /dev/null
113+
114+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
115+
"${LAB_IMAGE_USER}@${ip}" \
116+
"tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
117+
done
118+
}
119+
120+
# === RUN STEPS ===
121+
check_lab_vm_connections
122+
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
127+
run_universe_from_seed
128+
129+
echo "AUFN Test completed successfully!"

.github/workflows/deploy-aufn.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,11 @@ jobs:
164164
terraform output -raw labs > ssh_list.txt
165165
166166
- name: Run tests on Lab VMs (Test)
167-
uses: ./.github/workflows/AUFN-Test.yml
167+
if: ${{ inputs.deployment_type == 'Test' }}
168+
uses: ./.github/actions/aufn-test
168169
with:
169-
aufn-runner-id: ${{ runner.name }}
170170
au_from_seed: ${{ inputs.au_from_seed }}
171171
os_image: ${{ inputs.os_image }}
172-
if: ${{ inputs.deployment_type == 'Test' }}
173172

174173
- name: Run tests on Lab VMs (Deployment)
175174
uses: ./.github/workflows/AUFN-Deployment.yml

0 commit comments

Comments
 (0)