debian-forge/test/debian/test-debian-composer-workflows.py

419 lines
15 KiB
Python

#!/usr/bin/env python3
"""
Test Debian-Specific Composer Workflows for Debian Forge
This script tests complete Debian-specific composer workflows using all components:
- Repository management
- Package dependency resolution
- Atomic blueprint generation
- OSBuild integration
- Composer client integration
"""
import json
import os
import sys
import tempfile
import time
from pathlib import Path
from datetime import datetime
# Add current directory to Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_debian_component_integration():
"""Test integration between all Debian-specific components"""
print("Testing Debian component integration...")
try:
# Import all Debian-specific components
from debian_repository_manager import DebianRepositoryManager
from debian_package_resolver import DebianPackageResolver
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
print(" ✅ All Debian components imported successfully")
return True
except ImportError as e:
print(f" ❌ Failed to import Debian components: {e}")
return False
def test_repository_workflow():
"""Test complete repository management workflow"""
print("\nTesting repository management workflow...")
try:
from debian_repository_manager import DebianRepositoryManager
with tempfile.TemporaryDirectory() as temp_dir:
manager = DebianRepositoryManager(temp_dir)
# Test repository operations
repos = manager.list_repositories()
if len(repos) == 0:
print(" ❌ No repositories loaded")
return False
# Test mirror operations
mirrors = manager.list_mirrors()
if len(mirrors) == 0:
print(" ❌ No mirrors loaded")
return False
# Test APT configuration generation
apt_config = manager.generate_apt_config("bookworm", proxy="http://192.168.1.101:3142")
if not apt_config or "sources" not in apt_config:
print(" ❌ APT configuration generation failed")
return False
print(" ✅ Repository management workflow works correctly")
return True
except Exception as e:
print(f" ❌ Repository workflow test failed: {e}")
return False
def test_dependency_resolution_workflow():
"""Test complete dependency resolution workflow"""
print("\nTesting dependency resolution workflow...")
try:
from debian_package_resolver import DebianPackageResolver
resolver = DebianPackageResolver()
# Test complex package resolution
packages = ["systemd", "ostree", "nginx"]
resolution = resolver.resolve_package_dependencies(packages)
if not resolution.packages:
print(" ❌ No packages resolved")
return False
if not resolution.install_order:
print(" ❌ No install order generated")
return False
# Check if dependencies are resolved
if "libc6" not in resolution.packages:
print(" ❌ Basic dependencies not resolved")
return False
# Test conflict detection
if not resolution.conflicts:
print(" ⚠️ No conflicts detected (this may be expected)")
print(" ✅ Dependency resolution workflow works correctly")
return True
except Exception as e:
print(f" ❌ Dependency resolution workflow test failed: {e}")
return False
def test_blueprint_generation_workflow():
"""Test complete blueprint generation workflow"""
print("\nTesting blueprint generation workflow...")
try:
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
generator = DebianAtomicBlueprintGenerator()
# Test base blueprint generation
base_blueprint = generator.generate_base_blueprint()
if not base_blueprint or "packages" not in base_blueprint:
print(" ❌ Base blueprint generation failed")
return False
# Test specialized blueprint generation
workstation_blueprint = generator.generate_workstation_blueprint()
if not workstation_blueprint or "packages" not in workstation_blueprint:
print(" ❌ Workstation blueprint generation failed")
return False
# Test OSBuild manifest generation
manifest = generator.generate_osbuild_manifest(base_blueprint)
if not manifest or "pipelines" not in manifest:
print(" ❌ OSBuild manifest generation failed")
return False
# Validate manifest structure
build_pipeline = manifest["pipelines"][0]
if "stages" not in build_pipeline:
print(" ❌ Build pipeline missing stages")
return False
stage_types = [stage["type"] for stage in build_pipeline["stages"]]
expected_stages = ["org.osbuild.debootstrap", "org.osbuild.apt", "org.osbuild.ostree.commit"]
for expected in expected_stages:
if expected not in stage_types:
print(f" ❌ Missing expected stage: {expected}")
return False
print(" ✅ Blueprint generation workflow works correctly")
return True
except Exception as e:
print(f" ❌ Blueprint generation workflow test failed: {e}")
return False
def test_composer_integration_workflow():
"""Test composer integration workflow"""
print("\nTesting composer integration workflow...")
try:
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
from composer_client import ComposerClient, BuildRequest
# Test blueprint to composer request conversion
generator = DebianAtomicBlueprintGenerator()
blueprint = generator.generate_base_blueprint()
# Create build request
build_request = BuildRequest(
blueprint=blueprint["name"],
target="qcow2",
architecture=blueprint.get("arch", "amd64"),
compose_type="debian-atomic"
)
if build_request.blueprint != blueprint["name"]:
print(" ❌ Build request blueprint mismatch")
return False
if build_request.architecture != blueprint.get("arch", "amd64"):
print(" ❌ Build request architecture mismatch")
return False
print(" ✅ Composer integration workflow works correctly")
return True
except ImportError:
print(" ⚠️ Composer client not available, skipping integration test")
return True
except Exception as e:
print(f" ❌ Composer integration workflow test failed: {e}")
return False
def test_end_to_end_debian_workflow():
"""Test complete end-to-end Debian workflow"""
print("\nTesting end-to-end Debian workflow...")
try:
from debian_repository_manager import DebianRepositoryManager
from debian_package_resolver import DebianPackageResolver
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
with tempfile.TemporaryDirectory() as temp_dir:
# 1. Initialize repository manager
repo_manager = DebianRepositoryManager(temp_dir)
# 2. Initialize package resolver
pkg_resolver = DebianPackageResolver()
# 3. Generate blueprint with dependencies
blueprint_gen = DebianAtomicBlueprintGenerator(temp_dir)
blueprint = blueprint_gen.generate_base_blueprint()
# 4. Resolve package dependencies
package_names = [pkg["name"] for pkg in blueprint["packages"]]
resolution = pkg_resolver.resolve_package_dependencies(package_names)
# 5. Generate OSBuild manifest
manifest = blueprint_gen.generate_osbuild_manifest(blueprint)
# 6. Validate complete workflow
if not resolution.packages:
print(" ❌ Package resolution failed in workflow")
return False
if not manifest["pipelines"]:
print(" ❌ Manifest generation failed in workflow")
return False
# Check workflow completeness
workflow_steps = [
"repository_management",
"package_resolution",
"blueprint_generation",
"manifest_generation"
]
print(" ✅ End-to-end Debian workflow completed successfully")
return True
except Exception as e:
print(f" ❌ End-to-end workflow test failed: {e}")
return False
def test_debian_specific_features():
"""Test Debian-specific features and configurations"""
print("\nTesting Debian-specific features...")
try:
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
generator = DebianAtomicBlueprintGenerator()
# Test Debian-specific package sets
base_blueprint = generator.generate_base_blueprint()
base_packages = [pkg["name"] for pkg in base_blueprint["packages"]]
# Check for Debian-specific packages
debian_specific = ["systemd", "ostree", "linux-image-amd64"]
for pkg in debian_specific:
if pkg not in base_packages:
print(f" ❌ Debian-specific package missing: {pkg}")
return False
# Test Debian suite configuration
if base_blueprint.get("distro") != "debian-bookworm":
print(" ❌ Debian suite not configured correctly")
return False
# Test Debian architecture
if base_blueprint.get("arch") != "amd64":
print(" ❌ Debian architecture not configured correctly")
return False
# Test Debian-specific customizations
customizations = base_blueprint.get("customizations", {})
if "kernel" not in customizations:
print(" ❌ Debian kernel customizations missing")
return False
print(" ✅ Debian-specific features work correctly")
return True
except Exception as e:
print(f" ❌ Debian-specific features test failed: {e}")
return False
def test_blueprint_variants():
"""Test different blueprint variants"""
print("\nTesting blueprint variants...")
try:
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
generator = DebianAtomicBlueprintGenerator()
# Test all blueprint variants
variants = [
("base", generator.generate_base_blueprint),
("workstation", generator.generate_workstation_blueprint),
("server", generator.generate_server_blueprint),
("container", generator.generate_container_blueprint),
("minimal", generator.generate_minimal_blueprint)
]
for variant_name, variant_func in variants:
try:
blueprint = variant_func()
if not blueprint or "name" not in blueprint:
print(f"{variant_name} variant generation failed")
return False
if blueprint["name"] != f"debian-atomic-{variant_name}":
print(f"{variant_name} variant name incorrect")
return False
if not blueprint.get("packages"):
print(f"{variant_name} variant has no packages")
return False
except Exception as e:
print(f"{variant_name} variant test failed: {e}")
return False
print(" ✅ All blueprint variants work correctly")
return True
except Exception as e:
print(f" ❌ Blueprint variants test failed: {e}")
return False
def test_workflow_performance():
"""Test workflow performance characteristics"""
print("\nTesting workflow performance...")
try:
from debian_atomic_blueprint_generator import DebianAtomicBlueprintGenerator
generator = DebianAtomicBlueprintGenerator()
# Measure blueprint generation performance
start_time = time.time()
# Generate multiple blueprints
for _ in range(5):
generator.generate_base_blueprint()
end_time = time.time()
duration = end_time - start_time
if duration > 0:
avg_time = duration / 5
print(f" ✅ Workflow performance: {avg_time:.3f}s per blueprint")
return True
else:
print(" ❌ Workflow performance measurement failed")
return False
except Exception as e:
print(f" ❌ Workflow performance test failed: {e}")
return False
def main():
"""Main test function"""
print("Debian-Specific Composer Workflows Test for Debian Forge")
print("=" * 70)
tests = [
("Debian Component Integration", test_debian_component_integration),
("Repository Management Workflow", test_repository_workflow),
("Dependency Resolution Workflow", test_dependency_resolution_workflow),
("Blueprint Generation Workflow", test_blueprint_generation_workflow),
("Composer Integration Workflow", test_composer_integration_workflow),
("End-to-End Debian Workflow", test_end_to_end_debian_workflow),
("Debian-Specific Features", test_debian_specific_features),
("Blueprint Variants", test_blueprint_variants),
("Workflow Performance", test_workflow_performance)
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"{test_name} test failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 70)
print("TEST SUMMARY")
print("=" * 70)
passed = 0
total = len(results)
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{test_name}: {status}")
if result:
passed += 1
print(f"\nOverall: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Debian-specific composer workflows are ready.")
return 0
else:
print("⚠️ Some tests failed. Please review the issues above.")
return 1
if __name__ == '__main__':
sys.exit(main())