From 9de7b1209d70f6925aecd34d6044721c316caf2d Mon Sep 17 00:00:00 2001 From: Guillaume Boutry Date: Tue, 26 Nov 2024 15:53:11 +0100 Subject: [PATCH] [ops] consider model error as relation not ready When removing relations / applications, identity relations lose access to secrets. Consider ModelError as relation no longer ready. Treafik route access to relation data is also forbidden during shutdown. Change-Id: If91fbadeb8b2d81e20ab278ee0d9e499edd55c4c Signed-off-by: Guillaume Boutry --- ops-sunbeam/ops_sunbeam/relation_handlers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ops-sunbeam/ops_sunbeam/relation_handlers.py b/ops-sunbeam/ops_sunbeam/relation_handlers.py index 35da32d2..223e158d 100644 --- a/ops-sunbeam/ops_sunbeam/relation_handlers.py +++ b/ops-sunbeam/ops_sunbeam/relation_handlers.py @@ -33,6 +33,9 @@ import ops.framework import ops_sunbeam.compound_status as compound_status import ops_sunbeam.interfaces as sunbeam_interfaces import ops_sunbeam.tracing as sunbeam_tracing +from ops import ( + ModelError, +) from ops.model import ( ActiveStatus, BlockedStatus, @@ -587,7 +590,7 @@ class IdentityServiceRequiresHandler(RelationHandler): """Whether handler is ready for use.""" try: return bool(self.interface.service_password) - except (AttributeError, KeyError): + except (AttributeError, KeyError, ModelError): return False @@ -1373,7 +1376,7 @@ class IdentityCredentialsRequiresHandler(RelationHandler): """Whether handler is ready for use.""" try: return bool(self.interface.password) - except (AttributeError, KeyError): + except (AttributeError, KeyError, ModelError): return False @@ -2194,7 +2197,10 @@ class TraefikRouteHandler(RelationHandler): def ready(self) -> bool: """Whether the handler is ready for use.""" if self.charm.unit.is_leader(): - return bool(self.interface.external_host) + try: + return bool(self.interface.external_host) + except ModelError: + return False else: return self.interface.is_ready()