Add idempotency verification to the OPNsense VM integration example: - Extract verify_state() that queries all entity counts via typed API (uses DNatApi, FilterApi, SourceNatApi, VipSettingsApi) - Extract build_all_scores() for reuse across runs - Run all Scores twice, assert entity counts are unchanged on 2nd run - This catches duplicate creation in VLAN, LAGG, firewall rules, etc. Add build/opnsense-e2e.sh — CI-friendly script that: - Checks prerequisites (libvirtd, user groups) - Boots OPNsense VM via KVM (idempotent — skips if running) - Runs full Score suite with idempotency verification - Supports --download, --clean flags
55 lines
1.4 KiB
Bash
Executable File
55 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# OPNsense end-to-end integration test.
|
|
#
|
|
# Boots an OPNsense VM via KVM, runs all Harmony OPNsense Scores twice,
|
|
# and verifies idempotency (second run produces zero duplicates).
|
|
#
|
|
# Requirements:
|
|
# - libvirtd running (systemctl start libvirtd)
|
|
# - User in libvirt group (see examples/opnsense_vm_integration/setup-libvirt.sh)
|
|
# - OPNsense nano image downloaded (--download flag on first run)
|
|
#
|
|
# Usage:
|
|
# ./build/opnsense-e2e.sh # full test (boot if needed + run)
|
|
# ./build/opnsense-e2e.sh --download # download OPNsense image first
|
|
# ./build/opnsense-e2e.sh --clean # tear down VM after testing
|
|
set -e
|
|
cd "$(dirname "$0")/.."
|
|
|
|
PKG="opnsense-vm-integration"
|
|
|
|
echo "=== OPNsense E2E Integration Test ==="
|
|
echo ""
|
|
|
|
# Handle --download flag
|
|
if [ "$1" = "--download" ]; then
|
|
echo "--- Downloading OPNsense image ---"
|
|
cargo run -p "$PKG" -- --download
|
|
echo ""
|
|
fi
|
|
|
|
# Handle --clean flag
|
|
if [ "$1" = "--clean" ]; then
|
|
echo "--- Cleaning up VM ---"
|
|
cargo run -p "$PKG" -- --clean
|
|
echo "=== Clean complete ==="
|
|
exit 0
|
|
fi
|
|
|
|
# Check prerequisites
|
|
echo "--- Checking prerequisites ---"
|
|
cargo run -p "$PKG" -- --check
|
|
echo ""
|
|
|
|
# Boot VM if not already running
|
|
echo "--- Ensuring VM is running ---"
|
|
cargo run -p "$PKG" -- --boot
|
|
echo ""
|
|
|
|
# Run integration tests (includes idempotency verification)
|
|
echo "--- Running integration tests ---"
|
|
cargo run -p "$PKG"
|
|
echo ""
|
|
|
|
echo "=== OPNsense E2E Integration Test PASSED ==="
|