Skip to content

Commit 9a35f36

Browse files
committed
feat: add E2E tests GitHub workflow
- Add comprehensive E2E tests workflow in .github/workflows/test-e2e.yml - Workflow runs the Rust e2e-tests binary with wait-cloud-init test - Includes full environment setup: Rust, LXD, OpenTofu, Ansible - Provides debugging information on failure and proper cleanup - Update README.md to document the new E2E workflow - Add E2E testing to completed features list The workflow will test the complete infrastructure provisioning and validation cycle using the existing e2e-tests binary.
1 parent 28dfb18 commit 9a35f36

File tree

2 files changed

+151
-3
lines changed

2 files changed

+151
-3
lines changed

.github/workflows/test-e2e.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: E2E Tests
2+
3+
# NOTE: This workflow uses CI-specific approaches like 'sudo chmod 666' on the LXD socket
4+
# and 'sudo' with LXD commands. These approaches are NOT recommended for local development.
5+
# For local use, follow the proper group membership approach documented in config/tofu/lxd/README.md
6+
7+
on:
8+
push:
9+
branches: [main, develop]
10+
pull_request:
11+
branches: [main]
12+
workflow_dispatch: # Allow manual triggering
13+
14+
jobs:
15+
e2e-tests:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 20 # Set reasonable timeout for E2E tests
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Install Rust toolchain
24+
uses: actions-rs/toolchain@v1
25+
with:
26+
toolchain: stable
27+
profile: minimal
28+
override: true
29+
30+
- name: Cache Rust dependencies
31+
uses: actions/cache@v3
32+
with:
33+
path: |
34+
~/.cargo/registry
35+
~/.cargo/git
36+
target
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-cargo-
40+
41+
- name: Install and configure LXD
42+
run: |
43+
sudo snap install lxd
44+
45+
# Wait for LXD to fully initialize
46+
echo "Waiting for LXD daemon to start..."
47+
sleep 15
48+
49+
# Initialize LXD with default settings
50+
sudo lxd init --auto
51+
52+
# Add runner to lxd group
53+
sudo usermod -a -G lxd runner
54+
55+
# IMPORTANT: This approach is ONLY for CI environments
56+
# For local development, use proper group membership instead
57+
# Fix socket permissions for CI environment (NOT recommended for local use)
58+
sudo chmod 666 /var/snap/lxd/common/lxd/unix.socket
59+
60+
# Test basic LXD functionality
61+
sudo lxc list
62+
63+
- name: Install OpenTofu
64+
run: |
65+
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
66+
chmod +x install-opentofu.sh
67+
./install-opentofu.sh --install-method deb
68+
69+
- name: Install Ansible
70+
run: |
71+
sudo apt-get update
72+
sudo apt-get install -y ansible
73+
74+
- name: Verify installations
75+
run: |
76+
sudo lxc version
77+
tofu version
78+
ansible --version
79+
cargo --version
80+
81+
- name: Build E2E tests binary
82+
run: |
83+
cargo build --bin e2e-tests --release
84+
85+
- name: Run wait-cloud-init E2E test
86+
run: |
87+
# Run the E2E test with verbose output for better debugging
88+
# Use sudo -E to preserve environment variables for OpenTofu/LXD access
89+
sudo -E cargo run --bin e2e-tests -- wait-cloud-init --verbose
90+
env:
91+
# Preserve environment variables for the E2E test
92+
RUST_LOG: debug
93+
94+
- name: Get test outputs (on success)
95+
if: success()
96+
working-directory: config/tofu/lxd
97+
run: |
98+
echo "=== Infrastructure Outputs ==="
99+
sudo -E tofu output || echo "No outputs available"
100+
101+
echo "=== Container Status ==="
102+
sudo lxc list torrust-vm || echo "Container not found"
103+
104+
echo "=== Container Info ==="
105+
sudo lxc info torrust-vm || echo "Container info not available"
106+
107+
- name: Debug information (on failure)
108+
if: failure()
109+
run: |
110+
echo "=== LXD Status ==="
111+
sudo lxc list || echo "LXC list failed"
112+
113+
echo "=== OpenTofu State ==="
114+
cd config/tofu/lxd
115+
sudo -E tofu show || echo "No state to show"
116+
117+
echo "=== System Resources ==="
118+
df -h
119+
free -h
120+
121+
echo "=== Recent logs ==="
122+
sudo journalctl --since "10 minutes ago" --no-pager | tail -50 || echo "Journal logs not available"
123+
124+
- name: Cleanup infrastructure (always run)
125+
if: always()
126+
working-directory: config/tofu/lxd
127+
run: |
128+
echo "Cleaning up test infrastructure..."
129+
# Use sudo for CI environment cleanup
130+
# NOTE: For local development, use "sg lxd -c 'tofu destroy'" instead
131+
sudo -E tofu destroy -auto-approve || echo "Destroy command failed or nothing to destroy"
132+
sudo lxc delete torrust-vm --force || echo "Container deletion failed or container doesn't exist"
133+
134+
- name: Final verification
135+
if: always()
136+
run: |
137+
echo "Verifying final cleanup..."
138+
sudo lxc list
139+
140+
echo "=== Test Summary ==="
141+
echo "E2E test workflow completed"
142+
if [ "${{ job.status }}" = "success" ]; then
143+
echo "✅ All tests passed successfully"
144+
else
145+
echo "❌ Some tests failed - check logs above"
146+
fi

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ lxc exec torrust-vm -- docker-compose --version
178178

179179
## 🧪 Testing in GitHub Actions
180180

181-
Both configurations include GitHub Actions workflows for CI testing:
181+
The repository includes comprehensive GitHub Actions workflows for CI testing:
182182

183-
- **`.github/workflows/test-multipass-provision.yml`** - Tests Multipass VMs
184-
- **`.github/workflows/test-lxd-provision.yml`** - Tests LXD containers
183+
- **`.github/workflows/test-e2e.yml`** - **End-to-End Tests** - Runs automated E2E tests using the Rust binary
184+
- **`.github/workflows/test-lxd-provision.yml`** - Tests LXD container provisioning
185+
- **`.github/workflows/test-multipass-provision.yml`** - Tests Multipass VM provisioning
185186

186187
## 📊 Current Status
187188

@@ -196,6 +197,7 @@ Both configurations include GitHub Actions workflows for CI testing:
196197
- [x] Docker installation playbook
197198
- [x] Docker Compose installation playbook
198199
- [x] Automated testing workflows
200+
- [x] End-to-End (E2E) testing infrastructure and workflows
199201

200202
### 🔄 In Progress
201203

0 commit comments

Comments
 (0)