File size: 5,989 Bytes
38c314f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/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)