Skip to content

Commit dd2f30a

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

File tree

3 files changed

+157
-3
lines changed

3 files changed

+157
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.aufn-runner-id }}" \
22+
"${{ inputs.au_from_seed }}" \
23+
"${{ inputs.os_image }}"

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
# Your full logic from the workflow begins here.
21+
# To keep it simple, we’ll break it into functions for clarity.
22+
23+
function check_lab_vm_connections() {
24+
echo "Checking VM connections..."
25+
while IFS= read -r line; do
26+
ip=$(echo "$line" | awk '{print $2}')
27+
name=$(echo "$line" | awk '{print $3}')
28+
password=$(echo "$line" | awk '{print $5}')
29+
echo "::add-mask::$password"
30+
31+
echo "Connecting to $name at $ip via bastion..."
32+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
33+
"${LAB_IMAGE_USER}@${ip}" 'echo "Connected to $(hostname)"'
34+
done < ssh_list.txt
35+
}
36+
37+
function validate_lab_vms() {
38+
echo "Validating Lab VMs setup..."
39+
index=0
40+
failed_indexes=()
41+
while IFS= read -r line; do
42+
ip=$(echo "$line" | awk '{print $2}')
43+
name=$(echo "$line" | awk '{print $3}')
44+
password=$(echo "$line" | awk '{print $5}') > /dev/null
45+
46+
echo "Validating $name at $ip..."
47+
48+
taint="false"
49+
50+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "${LAB_IMAGE_USER}@${ip}" <<'EOF'
51+
output=$(sudo virsh list --all)
52+
echo "$output"
53+
if ! echo "$output" | grep -q 'seed.*running'; then echo "'seed' not running"; exit 1; fi
54+
if ! echo "$output" | grep -q 'compute0.*shut off'; then echo "'compute0' not shut off"; exit 1; fi
55+
if ! echo "$output" | grep -q 'controller0.*shut off'; then echo "'controller0' not shut off"; exit 1; fi
56+
57+
if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi
58+
if ! ssh [email protected] 'sudo dnf info openssh' | grep -q 'Repository *: *@System'; then exit 1; fi
59+
if ! tail -n 10 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
60+
EOF
61+
if [[ $? -ne 0 ]]; then failed_indexes+=($index); fi
62+
index=$((index + 1))
63+
done < ssh_list.txt
64+
65+
echo "FAILED_VM_INDEXES=${failed_indexes[*]}" >> "$GITHUB_ENV"
66+
}
67+
68+
function taint_and_reapply() {
69+
if [ -z "${FAILED_VM_INDEXES:-}" ]; then
70+
echo "✅ No failed VMs detected"
71+
return
72+
fi
73+
74+
echo "Tainting failed VMs..."
75+
for idx in $FAILED_VM_INDEXES; do
76+
terraform taint "openstack_compute_instance_v2.lab[$idx]"
77+
done
78+
terraform apply -auto-approve
79+
}
80+
81+
function post_redeploy_checks() {
82+
echo "Re-testing failed VMs after redeploy..."
83+
mapfile -t ssh_lines < ssh_list.txt
84+
for idx in $FAILED_VM_INDEXES; do
85+
line="${ssh_lines[$idx]}"
86+
ip=$(echo "$line" | awk '{print $2}')
87+
name=$(echo "$line" | awk '{print $3}')
88+
password=$(echo "$line" | awk '{print $5}') > /dev/null
89+
90+
91+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no "${LAB_IMAGE_USER}@${ip}" <<'EOF' || {
92+
terraform destroy -auto-approve
93+
exit 1
94+
}
95+
output=$(sudo virsh list --all)
96+
echo "$output"
97+
if ! echo "$output" | grep -q 'seed.*running'; then exit 1; fi
98+
if ! echo "$output" | grep -q 'compute0.*shut off'; then exit 1; fi
99+
if ! echo "$output" | grep -q 'controller0.*shut off'; then exit 1; fi
100+
if ! ssh [email protected] 'sudo docker ps' | grep -q bifrost_deploy; then exit 1; fi
101+
if ! ssh [email protected] 'sudo dnf info openssh' | grep -q 'Repository *: *@System'; then exit 1; fi
102+
if ! tail -n 20 a-seed-from-nothing.out | grep -q 'PLAY RECAP.*failed=0'; then exit 1; fi
103+
EOF
104+
done
105+
}
106+
107+
function run_universe_from_seed() {
108+
if [[ "$AU_FROM_SEED" != "true" ]]; then return; fi
109+
echo "🌌 Launching a-universe-from-seed..."
110+
mapfile -t ssh_lines < ssh_list.txt
111+
for i in "${!ssh_lines[@]}"; do
112+
line="${ssh_lines[$i]}"
113+
ip=$(echo "$line" | awk '{print $2}')
114+
name=$(echo "$line" | awk '{print $3}')
115+
password=$(echo "$line" | awk '{print $5}') > /dev/null
116+
117+
sshpass -p "$password" ssh -o StrictHostKeyChecking=no \
118+
"${LAB_IMAGE_USER}@${ip}" \
119+
"tmux new-session -d -s aus-run './a-universe-from-seed.sh'"
120+
done
121+
}
122+
123+
# === RUN THE STEPS ===
124+
check_lab_vm_connections
125+
validate_lab_vms
126+
taint_and_reapply
127+
terraform output -json > tf-outputs.json
128+
terraform output -raw labs > ssh_list.txt
129+
post_redeploy_checks
130+
run_universe_from_seed
131+
132+
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)