|
|
|
@ -1,63 +1,64 @@ |
|
|
|
#!/usr/bin/env bats |
|
|
|
#!/usr/bin/env bats |
|
|
|
|
|
|
|
|
|
|
|
VMPREFIX=batstestvm |
|
|
|
|
|
|
|
TESTDIR=~/virt/.tests |
|
|
|
TESTDIR=~/virt/.tests |
|
|
|
|
|
|
|
|
|
|
|
setup() { |
|
|
|
|
|
|
|
# Create test directory |
|
|
|
|
|
|
|
mkdir -p "${TESTDIR}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
teardown() { |
|
|
|
teardown() { |
|
|
|
# Clean up any created VMs |
|
|
|
# Clean up specific VMs that THIS test might have created |
|
|
|
|
|
|
|
# (Global cleanup will catch anything we miss) |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-rocky 2>/dev/null || true |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-rocky 2>/dev/null || true |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-fresh 2>/dev/null || true |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-fresh 2>/dev/null || true |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-invalid 2>/dev/null || true |
|
|
|
./kvm-install-vm remove "${VMPREFIX}"-remote-invalid 2>/dev/null || true |
|
|
|
|
|
|
|
|
|
|
|
# Clean up downloaded images from tests |
|
|
|
|
|
|
|
rm -f ~/virt/images/Rocky-9-GenericCloud.latest.x86_64.qcow2 2>/dev/null || true |
|
|
|
|
|
|
|
rm -f ~/virt/images/invalid-file.txt 2>/dev/null || true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Remote Rocky Linux image download and VM creation" { |
|
|
|
@test "Remote Rocky Linux image download and VM creation" { |
|
|
|
# Use the real Rocky Linux 9 image URL for testing |
|
|
|
# Use the real Rocky Linux 8 image URL for testing |
|
|
|
ROCKY_URL="https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud.latest.x86_64.qcow2" |
|
|
|
ROCKY_URL="https://dl.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2" |
|
|
|
|
|
|
|
|
|
|
|
# Test download detection and VM creation (use -n to assume no, preventing actual VM creation) |
|
|
|
# Use short timeout to test download start, not completion |
|
|
|
run timeout 30 ./kvm-install-vm create -n -i "${ROCKY_URL}" "${VMPREFIX}"-remote-rocky |
|
|
|
run timeout 10 ./kvm-install-vm create -i "${ROCKY_URL}" "${VMPREFIX}"-remote-rocky |
|
|
|
|
|
|
|
|
|
|
|
# Check that it recognizes it as a remote image |
|
|
|
# Should show remote image detection |
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
[[ "${output}" =~ "format: qcow2" ]] |
|
|
|
[[ "${output}" =~ "format: qcow2" ]] |
|
|
|
|
|
|
|
|
|
|
|
# Should either download or use existing image |
|
|
|
# Should show download activity or timeout (both prove download functionality works) |
|
|
|
|
|
|
|
if [ "$status" -eq 124 ]; then |
|
|
|
|
|
|
|
# Timeout occurred - check if download actually started |
|
|
|
|
|
|
|
IMAGE_FILE="$HOME/virt/images/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2" |
|
|
|
|
|
|
|
[[ -f "$IMAGE_FILE.part" ]] || [[ -f "$IMAGE_FILE" ]] |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
# Command completed - should show download activity or existing image |
|
|
|
[[ "${output}" =~ "Downloading image from" ]] || [[ "${output}" =~ "Image already exists" ]] |
|
|
|
[[ "${output}" =~ "Downloading image from" ]] || [[ "${output}" =~ "Image already exists" ]] |
|
|
|
|
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Remote image fresh download" { |
|
|
|
@test "Remote image fresh download" { |
|
|
|
# Use a specific test URL to ensure fresh download |
|
|
|
ROCKY_URL="https://dl.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2" |
|
|
|
ROCKY_URL="https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud.latest.x86_64.qcow2" |
|
|
|
IMAGE_FILE="$HOME/virt/images/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2" |
|
|
|
IMAGE_FILE="~/virt/images/Rocky-9-GenericCloud.latest.x86_64.qcow2" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Clean up any existing image to force fresh download |
|
|
|
# Clean up any existing image to force fresh download |
|
|
|
rm -f "${IMAGE_FILE}" 2>/dev/null || true |
|
|
|
rm -f "$IMAGE_FILE" 2>/dev/null || true |
|
|
|
rm -f "${IMAGE_FILE}.part" 2>/dev/null || true |
|
|
|
rm -f "$IMAGE_FILE.part" 2>/dev/null || true |
|
|
|
|
|
|
|
|
|
|
|
# Test actual download (use -n to prevent VM creation) |
|
|
|
# Use short timeout to test download start, not completion |
|
|
|
run timeout 60 ./kvm-install-vm create -n -i "${ROCKY_URL}" "${VMPREFIX}"-remote-fresh |
|
|
|
run timeout 10 ./kvm-install-vm create -i "${ROCKY_URL}" "${VMPREFIX}"-remote-fresh |
|
|
|
|
|
|
|
|
|
|
|
# Should show download activity |
|
|
|
# Should show download activity or timeout (both prove download functionality works) |
|
|
|
|
|
|
|
if [ "$status" -eq 124 ]; then |
|
|
|
|
|
|
|
# Timeout occurred - check if download actually started |
|
|
|
|
|
|
|
[[ -f "$IMAGE_FILE.part" ]] || [[ -f "$IMAGE_FILE" ]] |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
# Command completed - should show download activity |
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
[[ "${output}" =~ "Downloading image from" ]] |
|
|
|
[[ "${output}" =~ "Downloading image from" ]] |
|
|
|
|
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Remote image URL validation - unsupported format" { |
|
|
|
@test "Remote image URL validation - unsupported format" { |
|
|
|
# Test with an unsupported file extension |
|
|
|
|
|
|
|
INVALID_URL="https://example.com/invalid-file.txt" |
|
|
|
INVALID_URL="https://example.com/invalid-file.txt" |
|
|
|
|
|
|
|
|
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${INVALID_URL}" "${VMPREFIX}"-remote-invalid |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${INVALID_URL}" "${VMPREFIX}"-remote-invalid |
|
|
|
|
|
|
|
|
|
|
|
# Should fail with unsupported format error |
|
|
|
|
|
|
|
[ "$status" -eq 2 ] |
|
|
|
[ "$status" -eq 2 ] |
|
|
|
[[ "${output}" =~ "Unsupported remote image format" ]] |
|
|
|
[[ "${output}" =~ "Unsupported remote image format" ]] |
|
|
|
} |
|
|
|
} |
|
|
|
@ -66,46 +67,39 @@ teardown() { |
|
|
|
QCOW2_URL="https://example.com/test.qcow2" |
|
|
|
QCOW2_URL="https://example.com/test.qcow2" |
|
|
|
|
|
|
|
|
|
|
|
# This should pass format validation but fail on download (which is expected) |
|
|
|
# This should pass format validation but fail on download (which is expected) |
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${QCOW2_URL}" "${VMPREFIX}"-format-test |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${QCOW2_URL}" "${VMPREFIX}"-format-test |
|
|
|
|
|
|
|
|
|
|
|
# Should show qcow2 format detection before failing on download |
|
|
|
[[ "${output}" =~ "format: qcow2" ]] |
|
|
|
[[ "${output}" =~ "format: qcow2" ]] || [[ "${output}" =~ "Could not download" ]] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Remote image format detection - raw" { |
|
|
|
@test "Remote image format detection - raw" { |
|
|
|
RAW_URL="https://example.com/test.raw" |
|
|
|
RAW_URL="https://example.com/test.raw" |
|
|
|
|
|
|
|
|
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${RAW_URL}" "${VMPREFIX}"-format-test |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${RAW_URL}" "${VMPREFIX}"-format-test |
|
|
|
|
|
|
|
|
|
|
|
# Should show raw format detection |
|
|
|
[[ "${output}" =~ "format: raw" ]] |
|
|
|
[[ "${output}" =~ "format: raw" ]] || [[ "${output}" =~ "Could not download" ]] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Remote image format detection - vhd" { |
|
|
|
@test "Remote image format detection - vhd" { |
|
|
|
VHD_URL="https://example.com/test.vhd" |
|
|
|
VHD_URL="https://example.com/test.vhd" |
|
|
|
|
|
|
|
|
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${VHD_URL}" "${VMPREFIX}"-format-test |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${VHD_URL}" "${VMPREFIX}"-format-test |
|
|
|
|
|
|
|
|
|
|
|
# Should show vpc format detection (vhd maps to vpc) |
|
|
|
[[ "${output}" =~ "format: vpc" ]] |
|
|
|
[[ "${output}" =~ "format: vpc" ]] || [[ "${output}" =~ "Could not download" ]] |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "URL detection function" { |
|
|
|
@test "URL detection function" { |
|
|
|
# Test HTTPS URL detection |
|
|
|
|
|
|
|
HTTPS_URL="https://example.com/test.qcow2" |
|
|
|
HTTPS_URL="https://example.com/test.qcow2" |
|
|
|
|
|
|
|
|
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${HTTPS_URL}" "${VMPREFIX}"-url-test |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${HTTPS_URL}" "${VMPREFIX}"-url-test |
|
|
|
|
|
|
|
|
|
|
|
# Should be detected as remote image |
|
|
|
|
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
[[ "${output}" =~ "Using remote image" ]] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@test "Non-URL path handling" { |
|
|
|
@test "Non-URL path handling" { |
|
|
|
# Test that local paths still work as before |
|
|
|
|
|
|
|
LOCAL_PATH="/nonexistent/local/file.qcow2" |
|
|
|
LOCAL_PATH="/nonexistent/local/file.qcow2" |
|
|
|
|
|
|
|
|
|
|
|
run timeout 5 ./kvm-install-vm create -n -i "${LOCAL_PATH}" "${VMPREFIX}"-local-test |
|
|
|
run timeout $TIMEOUT ./kvm-install-vm create -i "${LOCAL_PATH}" "${VMPREFIX}"-local-test |
|
|
|
|
|
|
|
|
|
|
|
# Should show local file handling and fail because file doesn't exist |
|
|
|
|
|
|
|
[[ "${output}" =~ "Custom image file not found" ]] |
|
|
|
[[ "${output}" =~ "Custom image file not found" ]] |
|
|
|
} |
|
|
|
} |