220 lines
7.0 KiB
Python
220 lines
7.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple test script for the host reconciliation feature.
|
|
|
|
This script performs basic verification of the reconciliation implementation.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add the project root to the path
|
|
sys.path.insert(0, '/home/ubuntu/Downloads/code/theapi')
|
|
|
|
def test_imports():
|
|
"""Test that all required modules can be imported"""
|
|
print("🔍 Testing Module Imports")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
# Test WebSocket server imports
|
|
from websocket_server.worker_manager import (
|
|
update_host_status,
|
|
get_expected_containers_for_host,
|
|
send_pod_update_tasks,
|
|
send_reconcile_and_delete_task,
|
|
handle_reconcile_and_delete_completion
|
|
)
|
|
print("✅ WebSocket server worker_manager imports successful")
|
|
|
|
# Test task assignment imports
|
|
from websocket_server.task_assigner import assign_task_to_worker
|
|
print("✅ Task assigner imports successful")
|
|
|
|
# Test ACK handler imports
|
|
from websocket_server.events.ack import handle_ack
|
|
print("✅ ACK handler imports successful")
|
|
|
|
# Test worker client imports
|
|
from worker.workerClient import WorkerClient
|
|
print("✅ Worker client imports successful")
|
|
|
|
# Test container task imports
|
|
from worker.worker_tasks.container import ContainerTask
|
|
print("✅ Container task imports successful")
|
|
|
|
return True
|
|
|
|
except ImportError as e:
|
|
print(f"❌ Import failed: {e}")
|
|
return False
|
|
|
|
def test_task_types():
|
|
"""Test that the new task type is recognized"""
|
|
print("\n🔍 Testing Task Type Recognition")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
# Test that the new task type is handled in worker client
|
|
from worker.workerClient import WorkerClient
|
|
import inspect
|
|
|
|
# Get the handle_task method source
|
|
source = inspect.getsource(WorkerClient.handle_task)
|
|
|
|
# Check if reconcile_and_delete is handled
|
|
if 'reconcile_and_delete' in source:
|
|
print("✅ Worker client handles reconcile_and_delete task type")
|
|
else:
|
|
print("❌ Worker client missing reconcile_and_delete task handling")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Task type test failed: {e}")
|
|
return False
|
|
|
|
def test_container_task_method():
|
|
"""Test that the container task has the reconciliation method"""
|
|
print("\n🔍 Testing Container Task Method")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
from worker.worker_tasks.container import ContainerTask
|
|
|
|
# Check if the method exists
|
|
if hasattr(ContainerTask, 'handle_reconcile_and_delete'):
|
|
print("✅ ContainerTask has handle_reconcile_and_delete method")
|
|
else:
|
|
print("❌ ContainerTask missing handle_reconcile_and_delete method")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Container task method test failed: {e}")
|
|
return False
|
|
|
|
def test_task_prioritization():
|
|
"""Test that task prioritization logic exists"""
|
|
print("\n🔍 Testing Task Prioritization")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
from websocket_server.task_assigner import assign_task_to_worker
|
|
import inspect
|
|
|
|
# Get the assign_task_to_worker method source
|
|
source = inspect.getsource(assign_task_to_worker)
|
|
|
|
# Check if prioritization logic exists
|
|
if 'reconcile_and_delete' in source and 'sort' in source:
|
|
print("✅ Task prioritization logic includes reconcile_and_delete")
|
|
else:
|
|
print("❌ Task prioritization missing reconcile_and_delete handling")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Task prioritization test failed: {e}")
|
|
return False
|
|
|
|
def test_ack_handling():
|
|
"""Test that ACK handling includes reconciliation completion"""
|
|
print("\n🔍 Testing ACK Handling")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
from websocket_server.events.ack import handle_ack
|
|
import inspect
|
|
|
|
# Get the handle_ack method source
|
|
source = inspect.getsource(handle_ack)
|
|
|
|
# Check if reconciliation completion is handled
|
|
if 'reconcile_and_delete' in source and 'handle_reconcile_and_delete_completion' in source:
|
|
print("✅ ACK handling includes reconciliation completion")
|
|
else:
|
|
print("❌ ACK handling missing reconciliation completion")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ ACK handling test failed: {e}")
|
|
return False
|
|
|
|
def test_workflow_functions():
|
|
"""Test that workflow functions exist and are callable"""
|
|
print("\n🔍 Testing Workflow Functions")
|
|
print("-" * 30)
|
|
|
|
try:
|
|
from websocket_server.worker_manager import (
|
|
start_host_reconciliation,
|
|
update_host_status,
|
|
get_expected_containers_for_host,
|
|
send_pod_update_tasks,
|
|
send_reconcile_and_delete_task,
|
|
handle_reconcile_and_delete_completion
|
|
)
|
|
|
|
# Check that all functions are callable
|
|
functions = [
|
|
('start_host_reconciliation', start_host_reconciliation),
|
|
('update_host_status', update_host_status),
|
|
('get_expected_containers_for_host', get_expected_containers_for_host),
|
|
('send_pod_update_tasks', send_pod_update_tasks),
|
|
('send_reconcile_and_delete_task', send_reconcile_and_delete_task),
|
|
('handle_reconcile_and_delete_completion', handle_reconcile_and_delete_completion)
|
|
]
|
|
|
|
for name, func in functions:
|
|
if callable(func):
|
|
print(f"✅ {name} is callable")
|
|
else:
|
|
print(f"❌ {name} is not callable")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Workflow functions test failed: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""Run all tests"""
|
|
print("🚀 Host Reconciliation Feature Verification")
|
|
print("=" * 50)
|
|
|
|
tests = [
|
|
test_imports,
|
|
test_task_types,
|
|
test_container_task_method,
|
|
test_task_prioritization,
|
|
test_ack_handling,
|
|
test_workflow_functions
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test in tests:
|
|
if test():
|
|
passed += 1
|
|
|
|
print("\n" + "=" * 50)
|
|
print(f"📊 Test Results: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All tests passed! Host reconciliation feature is properly implemented.")
|
|
return True
|
|
else:
|
|
print("⚠️ Some tests failed. Please review the implementation.")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1) |