From 49aac9b640449d7ccc8a56c5774aff9496682109 Mon Sep 17 00:00:00 2001 From: yhaliaw <43424755+yhaliaw@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:38:52 +0800 Subject: [PATCH] Catch openstack auth issues --- src/charm.py | 10 +++++----- src/openstack_cloud/openstack_cloud.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/charm.py b/src/charm.py index c60c62bea..22bea2e57 100755 --- a/src/charm.py +++ b/src/charm.py @@ -134,17 +134,17 @@ def func_with_catch_errors(self: "GithubRunnerCharm", event: EventT) -> None: except TokenError as err: logger.exception("Issue with GitHub token") self.unit.status = BlockedStatus(str(err)) + except OpenStackUnauthorizedError: + logger.exception("Unauthorized OpenStack connection") + self.unit.status = BlockedStatus( + "Unauthorized OpenStack connection. Check credentials." + ) except MissingRunnerBinaryError: logger.exception("Missing runner binary") self.unit.status = MaintenanceStatus( "GitHub runner application not downloaded; the charm will retry download on " "reconcile interval" ) - except OpenStackUnauthorizedError: - logger.exception("Unauthorized OpenStack connection") - self.unit.status = BlockedStatus( - "Unauthorized OpenStack connection. Check credentials." - ) except MissingMongoDBError as err: logger.exception("Missing integration data") self.unit.status = WaitingStatus(str(err)) diff --git a/src/openstack_cloud/openstack_cloud.py b/src/openstack_cloud/openstack_cloud.py index ad21f4d97..33fbc65f8 100644 --- a/src/openstack_cloud/openstack_cloud.py +++ b/src/openstack_cloud/openstack_cloud.py @@ -22,7 +22,7 @@ from openstack.network.v2.security_group import SecurityGroup as OpenstackSecurityGroup from paramiko.ssh_exception import NoValidConnectionsError -from errors import KeyfileError, OpenStackError, SSHError +from errors import KeyfileError, OpenStackError, OpenStackUnauthorizedError, SSHError from utilities import retry logger = logging.getLogger(__name__) @@ -120,7 +120,7 @@ def _get_openstack_connection( # pylint thinks this isn't an exception, but does inherit from Exception class. except openstack.exceptions.HttpException as exc: # pylint: disable=bad-exception-cause logger.exception("OpenStack API call failure") - raise OpenStackError("Failed OpenStack API call") from exc + raise OpenStackUnauthorizedError("Failed OpenStack API call") from exc class OpenstackCloud: