Skip to content

Commit ef94d6c

Browse files
authored
Ignore alias error in case alias is already existing (#637)
1 parent a8024fd commit ef94d6c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/charm.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from charms.rolling_ops.v0.rollingops import RollingOpsManager, RunWithLock
3333
from charms.tempo_k8s.v1.charm_tracing import trace_charm
3434
from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer
35-
from ops import JujuVersion
35+
from ops import JujuVersion, main
3636
from ops.charm import (
3737
ActionEvent,
3838
HookEvent,
@@ -42,7 +42,6 @@
4242
StartEvent,
4343
)
4444
from ops.framework import EventBase
45-
from ops.main import main
4645
from ops.model import (
4746
ActiveStatus,
4847
BlockedStatus,
@@ -883,8 +882,14 @@ def _on_install(self, event: InstallEvent) -> None:
883882

884883
cache = snap.SnapCache()
885884
postgres_snap = cache[POSTGRESQL_SNAP_NAME]
886-
postgres_snap.alias("patronictl")
887-
postgres_snap.alias("psql")
885+
try:
886+
postgres_snap.alias("patronictl")
887+
except snap.SnapError:
888+
logger.warning("Unable to create patronictl alias")
889+
try:
890+
postgres_snap.alias("psql")
891+
except snap.SnapError:
892+
logger.warning("Unable to create psql alias")
888893

889894
# Create the user home directory for the snap_daemon user.
890895
# This is needed due to https://bugs.launchpad.net/snapd/+bug/2011581.

0 commit comments

Comments
 (0)