From 67fde957dd3da77b2f1845ace750f8c78d42df82 Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Mon, 21 Oct 2024 09:02:15 +1030 Subject: [PATCH 1/4] Enter blocked status if resource and snap_channel When a resource is used, the `snap_channel` config option is ignored. In this case, the snap is installed directly from the resource file, so a "channel" doesn't make sense. If `snap_channel` is set and a resource is being used, it may indicate a confusion situation, such as the user changing the `snap_channel` and wondering why the snap isn't being updated. So the charm can alert the user to this situation via a message and blocked status. Fixes: #113 --- charmcraft.yaml | 5 +++-- src/charm.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 1b36f5c..2125996 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -69,7 +69,7 @@ config: The charmed-openstack-exporter snap is by default installed from the latest/stable channel. This option allows the selection of a different channel. - In case the openStack-exporter resource has been attached, this option has no effect. + If the snap file has been attached via the openstack-exporter resource, this option has no effect. links: @@ -92,4 +92,5 @@ resources: ignore an empty file resource and normally install the snap from the snap store, but a custom snap can also be provided here if needed. - This resource has top priority. If the resource is present, the snap_channel option will have no effect. + This resource has priority: if this resource is present, + the snap will be installed from the resource, and the snap_channel option will have no effect. diff --git a/src/charm.py b/src/charm.py index 8671a05..e9a90aa 100755 --- a/src/charm.py +++ b/src/charm.py @@ -223,6 +223,15 @@ def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None: snap_service = get_installed_snap_service(SNAP_NAME) + # The snap_channel config option is ignored if there is a snap resource, + # so warn the user. + if self.model.config["snap_channel"] != "latest/stable" and self.get_resource(): + event.add_status( + BlockedStatus( + "Unset snap_channel option: it is unused when snap resource is provided." + ) + ) + if not snap_service.present: event.add_status( BlockedStatus( From c23cbbd5fa7ffa3332c72d8e472a9de140e4dad0 Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Mon, 21 Oct 2024 16:31:03 +1030 Subject: [PATCH 2/4] Include instructions for how to unset --- src/charm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/charm.py b/src/charm.py index e9a90aa..2177068 100755 --- a/src/charm.py +++ b/src/charm.py @@ -228,7 +228,8 @@ def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None: if self.model.config["snap_channel"] != "latest/stable" and self.get_resource(): event.add_status( BlockedStatus( - "Unset snap_channel option: it is unused when snap resource is provided." + "The snap_channel option is unused when snap resource is provided. " + f"Please unset it: juju config {self.app.name} --unset snap_channel" ) ) From f8d27275519fd2d759da7238a1bfff0859d04c74 Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Tue, 22 Oct 2024 10:46:32 +1030 Subject: [PATCH 3/4] Fix juju command, make message more consise --- src/charm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index 2177068..b387581 100755 --- a/src/charm.py +++ b/src/charm.py @@ -228,8 +228,8 @@ def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None: if self.model.config["snap_channel"] != "latest/stable" and self.get_resource(): event.add_status( BlockedStatus( - "The snap_channel option is unused when snap resource is provided. " - f"Please unset it: juju config {self.app.name} --unset snap_channel" + "snap_channel is unused when snap resource provided; " + f"please unset it: juju config {self.app.name} --reset snap_channel" ) ) From 8c313f8003178596d0345227af01547e3b29254c Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Tue, 22 Oct 2024 10:56:36 +1030 Subject: [PATCH 4/4] improve wording for clarity --- src/charm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index b387581..a653004 100755 --- a/src/charm.py +++ b/src/charm.py @@ -228,8 +228,8 @@ def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None: if self.model.config["snap_channel"] != "latest/stable" and self.get_resource(): event.add_status( BlockedStatus( - "snap_channel is unused when snap resource provided; " - f"please unset it: juju config {self.app.name} --reset snap_channel" + "Snap resource provided, so snap_channel is unused. " + f"Please unset it: juju config {self.app.name} --reset snap_channel" ) )