Initial commit: Sparrowdo Testing Orchestrator framework

- Add VM provisioning, cleanup, and setup scripts
- Add Jenkins pipeline with parameterized builds
- Add comprehensive documentation
- Support for parallel test execution with QCOW2 linked clones
This commit is contained in:
Stephen Simpson
2025-11-25 15:35:04 -06:00
commit 3cbd4525a0
6 changed files with 996 additions and 0 deletions

25
scripts/cleanup_vm.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
set -e
VM_NAME="$1"
if [ -z "$VM_NAME" ]; then
echo "Usage: $0 <vm_name>"
exit 1
fi
echo "[Cleanup] Starting cleanup for VM: $VM_NAME"
# Force stop VM
echo "[Cleanup] Destroying VM..."
sudo virsh destroy "$VM_NAME" 2>/dev/null || echo "[Cleanup] VM was not running"
# Remove VM definition
echo "[Cleanup] Undefining VM..."
sudo virsh undefine "$VM_NAME" 2>/dev/null || echo "[Cleanup] VM definition already removed"
# Remove disk image
echo "[Cleanup] Removing disk image..."
sudo rm -f "/var/lib/libvirt/images/${VM_NAME}.qcow2" || echo "[Cleanup] Disk already removed"
echo "[Cleanup] Complete for $VM_NAME"

64
scripts/provision_vm.sh Executable file
View File

@@ -0,0 +1,64 @@
#!/bin/bash
set -e
VM_NAME="$1"
GOLDEN_IMAGE="$2"
MAX_WAIT="${3:-30}"
if [ -z "$VM_NAME" ] || [ -z "$GOLDEN_IMAGE" ]; then
echo "Usage: $0 <vm_name> <golden_image_path> [max_wait_seconds]"
exit 1
fi
echo "[Provision] Creating VM: $VM_NAME"
# Create linked clone (very fast - just a pointer to base)
VM_DISK="/var/lib/libvirt/images/${VM_NAME}.qcow2"
echo "[Provision] Creating overlay disk: $VM_DISK"
sudo qemu-img create -f qcow2 -b "$GOLDEN_IMAGE" -F qcow2 "$VM_DISK" 2>/dev/null
# Define and start VM
echo "[Provision] Starting VM with virt-install..."
sudo virt-install \
--name "$VM_NAME" \
--memory 2048 \
--vcpus 2 \
--disk path="$VM_DISK",format=qcow2 \
--import \
--os-variant rocky9-unknown \
--network network=default \
--noautoconsole \
--wait 0 \
--transient \
2>&1 | grep -v "WARNING" || true
# Wait for IP address
echo "[Provision] Waiting for VM to obtain IP address (max ${MAX_WAIT}s)..."
COUNTER=0
while [ $COUNTER -lt $MAX_WAIT ]; do
# Try to get IP from DHCP lease
IP=$(sudo virsh domifaddr "$VM_NAME" --source lease 2>/dev/null | awk '/ipv4/ {print $4}' | cut -d/ -f1 | head -1)
if [ -n "$IP" ] && [ "$IP" != "0.0.0.0" ]; then
echo "[Provision] IP obtained: $IP"
echo "$IP"
exit 0
fi
sleep 2
((COUNTER++))
# Show progress every 5 iterations
if [ $((COUNTER % 5)) -eq 0 ]; then
echo "[Provision] Still waiting... (${COUNTER}/${MAX_WAIT}s)"
fi
done
echo "[Provision] ERROR: Could not obtain IP for $VM_NAME after $MAX_WAIT seconds"
echo "[Provision] Destroying failed VM..."
sudo virsh destroy "$VM_NAME" 2>/dev/null || true
sudo virsh undefine "$VM_NAME" 2>/dev/null || true
sudo rm -f "$VM_DISK"
echo "ERROR"
exit 1

65
scripts/setup_base.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
set -e
# Signature: ./setup_base.sh <qcow2_path> <prep_script_path> <output_golden_image> <ssh_pub_key>
QCOW2_PATH="$1"
PREP_SCRIPT_PATH="$2"
GOLDEN_IMAGE="$3"
SSH_PUB_KEY="$4"
if [ -z "$QCOW2_PATH" ] || [ -z "$GOLDEN_IMAGE" ] || [ -z "$SSH_PUB_KEY" ]; then
echo "Usage: $0 <qcow2_path> <prep_script_path> <output_golden_image> <ssh_pub_key>"
exit 1
fi
echo "=========================================="
echo "Setting up golden image"
echo "=========================================="
echo "Source QCOW2: $QCOW2_PATH"
echo "Output Golden: $GOLDEN_IMAGE"
echo "Prep Script: $PREP_SCRIPT_PATH"
echo "SSH Key: $SSH_PUB_KEY"
# Ensure libvirt is running
sudo systemctl is-active --quiet libvirtd || sudo systemctl start libvirtd
sleep 2
# Copy original to golden
echo "[Step 1/3] Copying base image to golden image..."
cp "$QCOW2_PATH" "$GOLDEN_IMAGE"
# Apply custom preparation script if provided
if [ -f "$PREP_SCRIPT_PATH" ]; then
echo "[Step 2/3] Applying custom preparation script..."
export LIBGUESTFS_BACKEND=direct
# Run the prep script inside the image
sudo virt-customize -a "$GOLDEN_IMAGE" \
--run "$PREP_SCRIPT_PATH" \
--ssh-inject root:file:"$SSH_PUB_KEY" \
--root-password password:rockytesting \
--selinux-relabel 2>&1 || {
echo "ERROR: virt-customize failed"
exit 1
}
else
echo "[Step 2/3] No custom prep script provided, applying defaults..."
export LIBGUESTFS_BACKEND=direct
sudo virt-customize -a "$GOLDEN_IMAGE" \
--ssh-inject root:file:"$SSH_PUB_KEY" \
--root-password password:rockytesting \
--install perl,git,wget,tar,openssh-server \
--run-command 'systemctl enable sshd' \
--selinux-relabel 2>&1 || {
echo "ERROR: virt-customize failed"
exit 1
}
fi
echo "[Step 3/3] Verifying golden image..."
qemu-img info "$GOLDEN_IMAGE" | head -5
echo "=========================================="
echo "Golden image ready: $GOLDEN_IMAGE"
echo "=========================================="