From 74fa5cadac73b40c08a06de61d49dbb195666444 Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Wed, 3 Jul 2024 11:43:55 +0200 Subject: [PATCH 1/3] Flag broken updater on every refresh attempt --- src/howitz/endpoints.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/howitz/endpoints.py b/src/howitz/endpoints.py index d74be60..1e7e3c1 100644 --- a/src/howitz/endpoints.py +++ b/src/howitz/endpoints.py @@ -131,9 +131,9 @@ def connect_to_updatehandler(): if current_app.event_manager.is_authenticated: # is zino authenticated current_app.updater = UpdateHandler(current_app.event_manager, autoremove=current_app.zino_config.autoremove) current_app.updater.connect() - current_app.logger.debug('UpdateHandler %s', current_app.updater) - return True - return False + current_app.logger.debug('Connected to UpdateHandler: %s', current_app.updater) + return + raise AuthenticationError('Session not authenticated, cannot connect to UpdateHandler') def connect_to_zino(username, token): @@ -196,10 +196,13 @@ def get_sorted_table_event_list(events: dict): def update_events(): updated_ids = set() - if current_app.updater is None: - return updated_ids while True: + if current_app.updater is None: + try: + connect_to_updatehandler() + except AuthenticationError as e: + raise LostConnectionError("Could not establish connection to UpdateHandler") from e updated = current_app.updater.get_event_update() if not updated: break @@ -210,9 +213,10 @@ def update_events(): def refresh_current_events(): if current_app.updater is None: - updates_ok = connect_to_updatehandler() - if not updates_ok: - raise LostConnectionError("Could not establish connection to UpdateHandler") + try: + connect_to_updatehandler() + except AuthenticationError as e: + raise LostConnectionError("Could not establish connection to UpdateHandler") from e event_ids = update_events() current_app.logger.debug('UPDATED EVENT IDS %s', event_ids) From 60b55db5dca3a03462169eb545dd92af797b19ef Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Wed, 3 Jul 2024 14:36:13 +0200 Subject: [PATCH 2/3] fixup --- src/howitz/endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/howitz/endpoints.py b/src/howitz/endpoints.py index 1e7e3c1..3e5ccc3 100644 --- a/src/howitz/endpoints.py +++ b/src/howitz/endpoints.py @@ -133,7 +133,7 @@ def connect_to_updatehandler(): current_app.updater.connect() current_app.logger.debug('Connected to UpdateHandler: %s', current_app.updater) return - raise AuthenticationError('Session not authenticated, cannot connect to UpdateHandler') + raise NotConnectedError('Session not authenticated, cannot connect to UpdateHandler') def connect_to_zino(username, token): From a0492952aa3c093462aa13d45937610f63846531 Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Thu, 4 Jul 2024 09:38:12 +0200 Subject: [PATCH 3/3] fixup --- src/howitz/endpoints.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/howitz/endpoints.py b/src/howitz/endpoints.py index 3e5ccc3..ed3bd7f 100644 --- a/src/howitz/endpoints.py +++ b/src/howitz/endpoints.py @@ -18,7 +18,8 @@ from datetime import datetime, timezone, timedelta from werkzeug.exceptions import BadRequest, InternalServerError, MethodNotAllowed -from zinolib.controllers.zino1 import Zino1EventManager, RetryError, EventClosedError, UpdateHandler, LostConnectionError +from zinolib.controllers.zino1 import Zino1EventManager, UpdateHandler +from zinolib.controllers.zino1 import RetryError, EventClosedError, LostConnectionError, NotConnectedError from zinolib.event_types import Event, AdmState, PortState, BFDState, ReachabilityState, LogEntry, HistoryEntry from zinolib.compat import StrEnum from zinolib.ritz import AuthenticationError @@ -201,7 +202,7 @@ def update_events(): if current_app.updater is None: try: connect_to_updatehandler() - except AuthenticationError as e: + except NotConnectedError as e: raise LostConnectionError("Could not establish connection to UpdateHandler") from e updated = current_app.updater.get_event_update() if not updated: @@ -215,7 +216,7 @@ def refresh_current_events(): if current_app.updater is None: try: connect_to_updatehandler() - except AuthenticationError as e: + except NotConnectedError as e: raise LostConnectionError("Could not establish connection to UpdateHandler") from e event_ids = update_events()