From ef94d6c2a67232aa7c1ce253ed21255111659af2 Mon Sep 17 00:00:00 2001 From: Dragomir Penev <6687393+dragomirp@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:44:57 +0300 Subject: [PATCH] Ignore alias error in case alias is already existing (#637) --- src/charm.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index 19916df374..80852333fb 100755 --- a/src/charm.py +++ b/src/charm.py @@ -32,7 +32,7 @@ from charms.rolling_ops.v0.rollingops import RollingOpsManager, RunWithLock from charms.tempo_k8s.v1.charm_tracing import trace_charm from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer -from ops import JujuVersion +from ops import JujuVersion, main from ops.charm import ( ActionEvent, HookEvent, @@ -42,7 +42,6 @@ StartEvent, ) from ops.framework import EventBase -from ops.main import main from ops.model import ( ActiveStatus, BlockedStatus, @@ -883,8 +882,14 @@ def _on_install(self, event: InstallEvent) -> None: cache = snap.SnapCache() postgres_snap = cache[POSTGRESQL_SNAP_NAME] - postgres_snap.alias("patronictl") - postgres_snap.alias("psql") + try: + postgres_snap.alias("patronictl") + except snap.SnapError: + logger.warning("Unable to create patronictl alias") + try: + postgres_snap.alias("psql") + except snap.SnapError: + logger.warning("Unable to create psql alias") # Create the user home directory for the snap_daemon user. # This is needed due to https://bugs.launchpad.net/snapd/+bug/2011581.