- Added lock file exclusions for pnpm in .gitignore. - Removed obsolete package-lock.json from the api and portal directories. - Enhanced Cloudflare adapter with additional interfaces for zones and tunnels. - Improved Proxmox adapter error handling and logging for API requests. - Updated Proxmox VM parameters with validation rules in the API schema. - Enhanced documentation for Proxmox VM specifications and examples.
4.9 KiB
4.9 KiB
Testing Guide - Proxmox Provider
This document provides guidance for testing the Crossplane Proxmox provider.
Unit Tests
Running Unit Tests
# Run all unit tests
go test ./pkg/...
# Run tests for specific package
go test ./pkg/utils/...
go test ./pkg/proxmox/...
go test ./pkg/controller/virtualmachine/...
# Run with coverage
go test -cover ./pkg/...
# Generate coverage report
go test -coverprofile=coverage.out ./pkg/...
go tool cover -html=coverage.out
Test Files
pkg/utils/parsing_test.go- Parsing utility testspkg/utils/validation_test.go- Validation function testspkg/proxmox/networks_test.go- Network API testspkg/proxmox/client_tenant_test.go- Tenant tag format testspkg/controller/virtualmachine/errors_test.go- Error categorization tests
Integration Tests
Integration tests require a Proxmox test environment.
Prerequisites
- Proxmox VE cluster with API access
- Valid API credentials
- Test node with available resources
- Test storage pools
- Network bridges configured
Running Integration Tests
# Run integration tests
go test -tags=integration ./pkg/controller/virtualmachine/...
# Skip integration tests (run unit tests only)
go test -short ./pkg/...
Integration Test Scenarios
-
VM Creation with Template Cloning
- Requires: Template VM (VMID 100-999999999)
- Tests: Template clone functionality
-
VM Creation with Cloud Image Import
- Requires: Cloud image in storage, importdisk API support
- Tests: Image import functionality
-
VM Creation with Pre-imported Images
- Requires: Pre-imported image in storage
- Tests: Image reference functionality
-
Multi-Site Deployment
- Requires: Multiple Proxmox sites configured
- Tests: Site selection and validation
-
Network Bridge Validation
- Requires: Network bridges on test nodes
- Tests: Network existence validation
-
Error Recovery
- Tests: Retry logic and error handling
-
Cloud-init Configuration
- Requires: Cloud-init support
- Tests: UserData writing and configuration
Manual Testing
Prerequisites
- Kubernetes cluster with Crossplane installed
- Proxmox provider deployed
- ProviderConfig configured
- Valid credentials
Test Scenarios
1. Tenant Tags
# Create VM with tenant ID
kubectl apply -f - <<EOF
apiVersion: proxmox.sankofa.nexus/v1alpha1
kind: ProxmoxVM
metadata:
name: test-vm-tenant
labels:
tenant-id: "test-tenant-123"
spec:
forProvider:
node: "test-node"
name: "test-vm"
cpu: 2
memory: "4Gi"
disk: "50Gi"
storage: "local-lvm"
network: "vmbr0"
image: "100"
site: "test-site"
providerConfigRef:
name: proxmox-provider-config
EOF
# Verify tenant tag in Proxmox
# Should see tag: tenant_test-tenant-123
2. API Adapter Authentication
Test the TypeScript API adapter authentication:
# Verify authentication header format
# Should use: Authorization: PVEAPIToken ${token}
# NOT: Authorization: PVEAPIToken=${token}
3. Proxmox Version Testing
Test on different Proxmox versions:
- PVE 6.x
- PVE 7.x
- PVE 8.x
Verify importdisk API detection works correctly.
4. Node Configuration Testing
- Test with multiple nodes
- Test node health checks
- Test node parameterization in compositions
5. Error Scenarios
Test various error conditions:
- Node unavailable
- Storage full
- Network bridge missing
- Invalid credentials
- Quota exceeded
Test Data Setup
Creating Test Templates
- Create a VM in Proxmox
- Install OS and configure
- Convert to template
- Note the VMID
Creating Test Images
- Download cloud image (e.g., Ubuntu cloud image)
- Upload to Proxmox storage
- Note the storage and path
Network Bridges
Ensure test nodes have:
vmbr0(default bridge)- Additional bridges for testing
Troubleshooting Tests
Common Issues
-
Authentication Failures
- Verify credentials in ProviderConfig
- Check API token format
- Verify Proxmox API access
-
Network Connectivity
- Verify network bridges exist
- Check node connectivity
- Verify firewall rules
-
Storage Issues
- Verify storage pools exist
- Check available space
- Verify storage permissions
-
Test Environment
- Verify test namespace exists
- Check RBAC permissions
- Verify CRDs are installed
Continuous Integration
Tests should be run in CI/CD pipeline:
# Example CI configuration
test:
unit:
- go test -v -short ./pkg/...
integration:
- go test -v -tags=integration ./pkg/controller/virtualmachine/...
coverage:
- go test -coverprofile=coverage.out ./pkg/...
Best Practices
- Isolation: Use separate test namespaces
- Cleanup: Always clean up test resources
- Idempotency: Tests should be repeatable
- Mocking: Use mocks for external dependencies
- Coverage: Aim for >80% code coverage