""" Deep investigation of the CrossSwitch bug Traces the full path from API to GeViServer and back """ import requests import json BASE_URL = "http://localhost:8000" def authenticate(): response = requests.post(f'{BASE_URL}/api/v1/auth/login', json={ 'username': 'admin', 'password': 'admin123' }) return response.json()['access_token'] def test_step1_check_current_mapping(): """Step 1: Check what the API currently has for TEST_TESTESEN""" print("\n" + "="*80) print("STEP 1: Check current TEST_TESTESEN mapping in API") print("="*80) token = authenticate() headers = {'Authorization': f'Bearer {token}'} response = requests.get( f'{BASE_URL}/api/v1/configuration/action-mappings', headers=headers ) mappings = response.json()['mappings'] test_mapping = None for mapping in mappings: if mapping['name'] == 'TEST_TESTESEN': test_mapping = mapping break if not test_mapping: print("ERROR: TEST_TESTESEN mapping not found!") print(f"Available mappings: {[m['name'] for m in mappings[:10]]}") return None print(f"Found mapping ID: {test_mapping['id']}") print(f"\nOutput actions ({len(test_mapping.get('output_actions', []))}):") for i, action in enumerate(test_mapping.get('output_actions', []), 1): print(f"\nAction {i}:") print(f" action: {action['action']}") print(f" parameters: {json.dumps(action.get('parameters', {}), indent=4)}") return test_mapping def test_step2_download_from_geviserver(): """Step 2: Download configuration from GeViServer via SDK Bridge""" print("\n" + "="*80) print("STEP 2: Download configuration directly from GeViServer") print("="*80) token = authenticate() headers = {'Authorization': f'Bearer {token}'} # Download full configuration response = requests.get( f'{BASE_URL}/api/v1/configuration/download', headers=headers ) if response.status_code != 200: print(f"ERROR: Download failed with status {response.status_code}") print(response.text) return None config = response.json() # Find TEST_TESTESEN in the configuration test_mapping = None for mapping in config.get('actionMappings', {}).get('mappings', []): if mapping.get('name') == 'TEST_TESTESEN': test_mapping = mapping break if not test_mapping: print("ERROR: TEST_TESTESEN not found in GeViServer configuration!") return None print(f"Found TEST_TESTESEN in GeViServer config") print(f"\nRaw data from GeViServer:") print(json.dumps(test_mapping, indent=2)) return test_mapping def test_step3_create_test_mapping(): """Step 3: Create a fresh test mapping with known data""" print("\n" + "="*80) print("STEP 3: Create fresh test mapping with PanLeft actions") print("="*80) token = authenticate() headers = {'Authorization': f'Bearer {token}'} # Delete existing if present response = requests.get( f'{BASE_URL}/api/v1/configuration/action-mappings', headers=headers ) for mapping in response.json()['mappings']: if mapping['name'] == 'BACKEND_TEST_PANLEFT': print(f"Deleting existing BACKEND_TEST_PANLEFT (ID: {mapping['id']})") requests.delete( f"{BASE_URL}/api/v1/configuration/action-mappings/{mapping['id']}", headers=headers ) # Create new mapping with explicit PanLeft action new_mapping = { "name": "BACKEND_TEST_PANLEFT", "input_action": "TestInput", "output_actions": [ { "action": "PanLeft", "parameters": { "GscServer": "gscope-cdx-3", "PTZ head": "101027", "Caption": "GSC PanLeft Test" } } ], "enabled": True } print("\nCreating mapping with data:") print(json.dumps(new_mapping, indent=2)) response = requests.post( f'{BASE_URL}/api/v1/configuration/action-mappings', headers=headers, json=new_mapping ) if response.status_code not in [200, 201]: print(f"ERROR: Failed to create mapping: {response.status_code}") print(response.text) return None result = response.json() print(f"\nMapping created successfully") print(f"Mapping ID: {result.get('mapping', {}).get('id')}") return result def test_step4_verify_after_upload(): """Step 4: Upload to GeViServer and verify what gets stored""" print("\n" + "="*80) print("STEP 4: Upload to GeViServer and check what gets stored") print("="*80) token = authenticate() headers = {'Authorization': f'Bearer {token}'} # Trigger upload print("Uploading configuration to GeViServer...") response = requests.post( f'{BASE_URL}/api/v1/configuration/upload', headers=headers ) if response.status_code != 200: print(f"ERROR: Upload failed: {response.status_code}") print(response.text) return False print("Upload successful") # Now download it back print("\nDownloading back from GeViServer...") response = requests.get( f'{BASE_URL}/api/v1/configuration/download', headers=headers ) config = response.json() # Find our test mapping test_mapping = None for mapping in config.get('actionMappings', {}).get('mappings', []): if mapping.get('name') == 'BACKEND_TEST_PANLEFT': test_mapping = mapping break if not test_mapping: print("ERROR: BACKEND_TEST_PANLEFT not found after upload!") return False print("\nWhat GeViServer stored:") print(json.dumps(test_mapping, indent=2)) # Check if it's CrossSwitch actions = test_mapping.get('actions', []) if actions: first_action = actions[0] print(f"\nFirst output action: {first_action}") if 'CrossSwitch' in str(first_action): print("\n!!! BUG CONFIRMED: Action stored as CrossSwitch !!!") return False elif 'PanLeft' in str(first_action): print("\n[OK] Action correctly stored as PanLeft") return True return False if __name__ == '__main__': try: print("="*80) print("INVESTIGATING CROSSSWITCH BUG") print("="*80) # Run all test steps test_step1_check_current_mapping() test_step2_download_from_geviserver() test_step3_create_test_mapping() test_step4_verify_after_upload() except Exception as e: print(f"\nERROR: {str(e)}") import traceback traceback.print_exc()