CalejoControl/test_discovery_debug.py

56 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Debug test of the discovery service with detailed logging
"""
import asyncio
import sys
import os
import logging
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
# Set up logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
from discovery.protocol_discovery_modified import discovery_service
async def test_discovery_debug():
"""Test discovery service with debug logging"""
print("Starting discovery test with debug logging...")
try:
# Test individual discovery methods
print("\n1. Testing REST API discovery...")
rest_endpoints = await discovery_service._discover_rest_api()
print(f" Found {len(rest_endpoints)} REST endpoints")
print("\n2. Testing Modbus TCP discovery...")
modbus_tcp_endpoints = await discovery_service._discover_modbus_tcp()
print(f" Found {len(modbus_tcp_endpoints)} Modbus TCP endpoints")
print("\n3. Testing Modbus RTU discovery...")
modbus_rtu_endpoints = await discovery_service._discover_modbus_rtu()
print(f" Found {len(modbus_rtu_endpoints)} Modbus RTU endpoints")
print("\n4. Testing OPC UA discovery...")
opcua_endpoints = await discovery_service._discover_opcua()
print(f" Found {len(opcua_endpoints)} OPC UA endpoints")
print("\n5. Testing full discovery...")
result = await discovery_service.discover_all_protocols("test_scan")
print(f"\nDiscovery completed!")
print(f"Total discovered endpoints: {len(result.discovered_endpoints)}")
print(f"Errors: {result.errors}")
for endpoint in result.discovered_endpoints:
print(f" - {endpoint.protocol_type}: {endpoint.address}")
except Exception as e:
print(f"Discovery failed: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(test_discovery_debug())