Loading src/tests/ecoc25-f5ga-telemetry/subscribe_telemetry_slice1.py +22 −21 Original line number Diff line number Diff line Loading @@ -13,10 +13,11 @@ # limitations under the License. import requests, websocket import requests from requests.auth import HTTPBasicAuth RESTCONF_ADDRESS = '0.0.0.0' RESTCONF_ADDRESS = '127.0.0.1' RESTCONF_PORT = 80 TARGET_SIMAP_NAME = 'e2e' TARGET_LINK_NAME = 'E2E-L1' Loading @@ -37,23 +38,24 @@ REQUEST = { } def on_open(ws): print('### Opened stream ###') def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws, close_status_code, close_msg): print('### Closed stream ###') def main() -> None: print('[E2E] Subscribe Telemetry slice1...') reply = requests.get(SUBSCRIBE_URL, json=REQUEST, allow_redirects=True) assert reply.is_json headers = {'accept': 'application/json'} auth = HTTPBasicAuth('admin', 'admin') print(SUBSCRIBE_URL) print(REQUEST) reply = requests.post( SUBSCRIBE_URL, headers=headers, json=REQUEST, auth=auth, verify=False, allow_redirects=True, timeout=30 ) content_type = reply.headers.get('Content-Type', '') if 'application/json' not in content_type: raise Exception('Not JSON:', reply.content.decode('UTF-8')) try: reply_data = reply.json() except ValueError as e: str_error = 'Invalid JSON: {:s}'.format(str(reply.content.decode('UTF-8'))) raise Exception(str_error) from e if 'uri' not in reply_data: raise Exception('Unexpected Reply: {:s}'.format(str(reply_data))) Loading @@ -62,10 +64,9 @@ def main() -> None: stream_url = 'http://{:s}:{:d}{:s}'.format(RESTCONF_ADDRESS, RESTCONF_PORT, subscription_uri) print('Opening stream "{:s}" (press Ctrl+C to stop)...'.format(stream_url)) ws = websocket.WebSocketApp( stream_url, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close ) ws.run_forever() with requests.get(stream_url, stream=True) as resp: for line in resp.iter_lines(decode_unicode=True): print(line) if __name__ == '__main__': main() Loading
src/tests/ecoc25-f5ga-telemetry/subscribe_telemetry_slice1.py +22 −21 Original line number Diff line number Diff line Loading @@ -13,10 +13,11 @@ # limitations under the License. import requests, websocket import requests from requests.auth import HTTPBasicAuth RESTCONF_ADDRESS = '0.0.0.0' RESTCONF_ADDRESS = '127.0.0.1' RESTCONF_PORT = 80 TARGET_SIMAP_NAME = 'e2e' TARGET_LINK_NAME = 'E2E-L1' Loading @@ -37,23 +38,24 @@ REQUEST = { } def on_open(ws): print('### Opened stream ###') def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws, close_status_code, close_msg): print('### Closed stream ###') def main() -> None: print('[E2E] Subscribe Telemetry slice1...') reply = requests.get(SUBSCRIBE_URL, json=REQUEST, allow_redirects=True) assert reply.is_json headers = {'accept': 'application/json'} auth = HTTPBasicAuth('admin', 'admin') print(SUBSCRIBE_URL) print(REQUEST) reply = requests.post( SUBSCRIBE_URL, headers=headers, json=REQUEST, auth=auth, verify=False, allow_redirects=True, timeout=30 ) content_type = reply.headers.get('Content-Type', '') if 'application/json' not in content_type: raise Exception('Not JSON:', reply.content.decode('UTF-8')) try: reply_data = reply.json() except ValueError as e: str_error = 'Invalid JSON: {:s}'.format(str(reply.content.decode('UTF-8'))) raise Exception(str_error) from e if 'uri' not in reply_data: raise Exception('Unexpected Reply: {:s}'.format(str(reply_data))) Loading @@ -62,10 +64,9 @@ def main() -> None: stream_url = 'http://{:s}:{:d}{:s}'.format(RESTCONF_ADDRESS, RESTCONF_PORT, subscription_uri) print('Opening stream "{:s}" (press Ctrl+C to stop)...'.format(stream_url)) ws = websocket.WebSocketApp( stream_url, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close ) ws.run_forever() with requests.get(stream_url, stream=True) as resp: for line in resp.iter_lines(decode_unicode=True): print(line) if __name__ == '__main__': main()