This guide explains the mandatory local testing requirements for contributing to the Qubinode KVM Host Setup Collection, based on ADR-0011.
Ensure code quality and prevent CI/CD failures by:
- Running comprehensive local tests before pushing code
- Following mandatory testing procedures
- Implementing proper pre-commit validation
- Maintaining ADR compliance
- Completed Set Up Development Environment
- Molecule testing framework configured
- Understanding of project quality standards
- Familiarity with Git workflows
Code CANNOT be pushed to CI/CD unless:
- ✅ Local testing script exists:
scripts/test-local-molecule.sh - ✅ Script is executable:
chmod +x scripts/test-local-molecule.sh - ✅ All local Molecule tests pass before commit
- ✅ ADR-0012 compliance: Only init containers used in Molecule configurations
- ✅ Architectural rules compliance satisfied
- Rule ID:
mandatory-local-testing-before-push - Severity:
CRITICAL - Enforcement:
BLOCKING - Source: ADR-0011 (Local Molecule Testing Validation Before CI/CD)
# Run automated setup (first time only)
./scripts/setup-local-testing.sh
# Verify setup
./scripts/check-compliance.sh# Activate for each development session
source scripts/activate-molecule-env.sh
# Verify activation
molecule --version
which molecule# MANDATORY: Run before every commit
./scripts/test-local-molecule.sh
# Test specific roles only (if needed)
./scripts/test-local-molecule.sh kvmhost_base kvmhost_networking# Install pre-commit hook
./scripts/install-pre-commit-hook.sh
# Manual setup if script not available
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
echo "🧪 Running mandatory local tests..."
source scripts/activate-molecule-env.sh
./scripts/test-local-molecule.sh
if [ $? -ne 0 ]; then
echo "❌ Local tests failed. Commit blocked."
exit 1
fi
echo "✅ Local tests passed. Proceeding with commit."
EOF
chmod +x .git/hooks/pre-commit# 1. Update from upstream
git fetch upstream
git checkout main
git merge upstream/main
# 2. Activate testing environment
source scripts/activate-molecule-env.sh
# 3. Create feature branch
git checkout -b feature/your-feature# Test individual roles as you work
cd roles/modified_role
molecule test --scenario-name default
# Quick syntax check
ansible-lint roles/modified_role/
yamllint roles/modified_role/# MANDATORY: Run full test suite
./scripts/test-local-molecule.sh
# Additional quality checks
ansible-lint .
yamllint .
./scripts/check-compliance.sh- Modified Roles: All roles you've changed must pass tests
- Integration Tests: Test role interactions if multiple roles modified
- Lint Checks: All linting must pass without errors
- Compliance: All ADR compliance checks must pass
# Full test suite
./scripts/test-local-molecule.sh
# Security scanning
./scripts/enhanced-security-scan.sh
# Performance validation
./scripts/performance-test.sh
# Documentation validation
./scripts/validate-documentation.sh- Individual Role Tests: < 5 minutes per role
- Full Test Suite: < 30 minutes total
- Lint Checks: < 2 minutes
- Compliance Checks: < 1 minute
- Memory: 4GB+ available for container testing
- CPU: 2+ cores for parallel testing
- Storage: 10GB+ free space for container images
- Network: Stable connection for image downloads
# Clean environment before testing
podman system prune -f
docker system prune -f # if using Docker
# Set unique test directory
export MOLECULE_EPHEMERAL_DIRECTORY=/tmp/molecule-$(date +%s)
# Run tests in isolation
./scripts/test-local-molecule.sh- Do NOT push code - Fix issues locally first
- Analyze failure logs - Understand what went wrong
- Fix the issues - Address root causes, not symptoms
- Re-run tests - Verify fixes work
- Only then commit - After all tests pass
Lint Failures
# Fix Ansible lint issues
ansible-lint --fix .
# Fix YAML formatting
yamllint . --format parsable | while read line; do
# Address each issue manually
doneMolecule Test Failures
# Debug failed tests
cd roles/failing_role
molecule test --debug
# Interactive debugging
molecule create
molecule login
# Debug inside containerCompliance Failures
# Check specific compliance issues
./scripts/check-compliance.sh --verbose
# Fix ADR compliance issues
./scripts/fix-adr-compliance.sh- Parallel Execution: Run independent tests in parallel
- Caching: Use container image caching
- Selective Testing: Test only changed components when appropriate
# Track test execution times
./scripts/test-local-molecule.sh --timing
# Monitor resource usage
htop # During test execution
# Check test coverage
./scripts/generate-test-coverage.sh- Write tests first - TDD approach for new features
- Test edge cases - Don't just test happy paths
- Use realistic data - Test with production-like configurations
- Document test scenarios - Explain what each test validates
- Use local images - Cache container images locally
- Parallel testing - Run independent tests concurrently
- Resource monitoring - Watch memory and CPU usage
- Clean up regularly - Remove unused containers and images
- Consistent environments - Use same test setup across team
- Reproducible results - Tests should be deterministic
- Clear failure messages - Make test failures easy to understand
- Regular maintenance - Keep test infrastructure updated
- Setup: Set Up Development Environment
- Testing: Run Molecule Tests
- Migration: Migrate Molecule Tests
- ADR: ADR-0011 Local Testing
This guide established mandatory testing requirements. For understanding the testing philosophy, see the explanations section. For specific testing procedures, check the testing guides.