Skip to content

Commit

Permalink
Raise errors on unrecoverable problems
Browse files Browse the repository at this point in the history
For:
- snap install or refresh failure
- snap not installed
- snap service not active

These cases are unexpected, the charm cannot recover automatically,
and the user must manually debug the issue.
Therefore, error status is more appropriate.

Partially fixes: #108
  • Loading branch information
samuelallan72 committed Sep 24, 2024
1 parent bed9317 commit 0fc2c62
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,9 @@ def get_resource(self) -> Optional[str]:

def install(self) -> None:
"""Install the necessary resources for the charm."""
try:
snap_install_or_refresh(self.get_resource(), self.model.config["snap_channel"])
except SnapError:
self.model.unit.status = BlockedStatus(
"Failed to remove/install openstack-exporter snap"
)
# If this fails, it's not recoverable.
# So we don't catch the error, instead letting this become a charm error status.
snap_install_or_refresh(self.get_resource(), self.model.config["snap_channel"])

def _configure(self, _: ops.HookEvent) -> None:
"""Configure the charm.
Expand Down Expand Up @@ -227,13 +224,9 @@ def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None:
snap_service = get_installed_snap_service(SNAP_NAME)

if not snap_service.present:
event.add_status(
BlockedStatus("snap service is not installed, please check snap service")
)
raise RuntimeError(f"{SNAP_NAME} snap is not installed")
elif not snap_service.is_active():
event.add_status(
BlockedStatus("snap service is not running, please check snap service")
)
raise RuntimeError(f"{SNAP_NAME} snap service is not active")

event.add_status(ActiveStatus())

Expand Down

0 comments on commit 0fc2c62

Please sign in to comment.