#!/usr/bin/env python3 """ Phase 2 Deployment Verification Script Tests the deployed neuromorphic security and DataOps integration services """ import asyncio import sys import time import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), 'commsops')) from neuromorphic_security import NeuromorphicSecurityAPI from dataops_integration import DataOpsIntegration, create_dataops_integration async def test_neuromorphic_security(): """Test the neuromorphic security service""" print("šŸ”’ Testing Neuromorphic Security Service...") api = NeuromorphicSecurityAPI() # Test various message types test_messages = [ (b'Normal operational data', 'Normal message'), (b'X' * 5000, 'Large payload'), (b'\x00\x01\x02\x03' * 100, 'Binary data'), (b'Potential security threat pattern', 'Suspicious content') ] results = [] for message_data, description in test_messages: result = await api.scan_message(message_data, 'data_ops') results.append({ 'description': description, 'approved': result.approved, 'confidence': result.confidence, 'risk_score': result.risk_score, 'processing_time': result.processing_time_ms }) print(f" {description}: {'āœ…' if result.approved else 'āŒ'} " f"(Risk: {result.risk_score:.2f}, Time: {result.processing_time_ms:.2f}ms)") # Get overall metrics metrics = await api.get_security_metrics() print(f" Total messages scanned: {metrics['total_messages_scanned']}") print(f" Approval rate: {metrics['approval_rate']:.2%}") return all(r['approved'] for r in results if 'Normal' in r['description']) async def test_dataops_integration(): """Test the DataOps integration service""" print("šŸ”— Testing DataOps Integration Service...") integration = create_dataops_integration() # Test storage with security test_data = { 'operation': 'test_storage', 'data': {'sample': 'integration_test', 'value': 42, 'timestamp': time.time()}, 'metadata': {'test_id': 'phase2_verification', 'domain': 'data_ops'} } start_time = time.time() storage_result = await integration.store_with_security(test_data, 'data_ops') storage_time = (time.time() - start_time) * 1000 print(f" Storage operation: {'āœ…' if storage_result.success else 'āŒ'} " f"(Time: {storage_time:.2f}ms)") if storage_result.success: # Test retrieval start_time = time.time() retrieved_data = await integration.retrieve_with_security(storage_result.storage_id) retrieval_time = (time.time() - start_time) * 1000 print(f" Retrieval operation: {'āœ…' if retrieved_data.get('security_valid') else 'āŒ'} " f"(Time: {retrieval_time:.2f}ms)") # Get performance metrics metrics = await integration.get_performance_metrics() print(f" Cross-domain latency: {metrics['integration_metrics']['cross_domain_latency']:.2f}ms") print(f" Data throughput: {metrics['integration_metrics']['data_throughput']:,} ops/s") return storage_result.success async def test_service_connectivity(): """Test that services are running and responsive""" print("šŸ“” Testing Service Connectivity...") # Check if supervisor services are running try: import subprocess result = subprocess.run(['sudo', 'supervisorctl', 'status', 'commsops:'], capture_output=True, text=True, timeout=10) if 'RUNNING' in result.stdout: print(" āœ… Supervisor services: RUNNING") # Parse service status lines = result.stdout.strip().split('\n') for line in lines: if 'commsops:' in line: service_name = line.split()[0] status = line.split()[1] print(f" {service_name}: {status}") return True else: print(" āŒ Supervisor services: NOT RUNNING") return False except Exception as e: print(f" āŒ Service check failed: {e}") return False async def main(): """Main verification routine""" print("šŸš€ Phase 2 Deployment Verification") print("=" * 50) all_tests_passed = True # Test 1: Service connectivity connectivity_ok = await test_service_connectivity() all_tests_passed &= connectivity_ok print() # Test 2: Neuromorphic security if connectivity_ok: security_ok = await test_neuromorphic_security() all_tests_passed &= security_ok print() # Test 3: DataOps integration if connectivity_ok: integration_ok = await test_dataops_integration() all_tests_passed &= integration_ok print() # Final results print("šŸ“Š Verification Results:") print("=" * 50) print(f"Service Connectivity: {'āœ… PASS' if connectivity_ok else 'āŒ FAIL'}") if connectivity_ok: print(f"Neuromorphic Security: {'āœ… PASS' if security_ok else 'āŒ FAIL'}") print(f"DataOps Integration: {'āœ… PASS' if integration_ok else 'āŒ FAIL'}") print(f"\nOverall Status: {'šŸŽ‰ ALL TESTS PASSED' if all_tests_passed else 'āŒ DEPLOYMENT ISSUES'}") if all_tests_passed: print("\nšŸš€ Phase 2 Integration is fully operational and production-ready!") print("Next steps:") print(" - Integrate with monitoring dashboard") print(" - Update alerting systems") print(" - Begin Phase 3 MLOps integration") else: print("\nāš ļø Some tests failed. Check service logs and configuration.") return all_tests_passed if __name__ == "__main__": success = asyncio.run(main()) sys.exit(0 if success else 1)