Skip to content

Commit b78b456

Browse files
committed
fix(charm): disable snap services on teardown, not just stop
stop() leaves the snap services enabled, so a mid-teardown restart of the unit could re-enable them and re-grab the storage mounts before Juju finishes unmounting. stop(disable=True) prevents that. Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
1 parent 333daca commit b78b456

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/charm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,9 @@ def _on_storage_detaching(self, _) -> None:
25762576
self._observer.stop_observer()
25772577
self._rotate_logs.stop_log_rotation()
25782578
try:
2579-
snap.SnapCache()[charm_refresh.snap_name()].stop()
2579+
# Disable too, so a mid-teardown restart of the unit can't re-enable the
2580+
# services and re-grab the storage mounts before Juju finishes unmounting.
2581+
snap.SnapCache()[charm_refresh.snap_name()].stop(disable=True)
25802582
except snap.SnapError:
25812583
logger.exception("Failed to stop charmed-postgresql snap services")
25822584

tests/unit/test_charm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def test_on_storage_detaching(harness):
145145
_selected_snap.stop.assert_not_called()
146146

147147
# Full teardown (no units remain): release the storage by stopping the
148-
# background processes and all the snap services.
148+
# background processes and disabling (so a mid-teardown restart can't
149+
# re-grab the mount) all the snap services.
149150
_planned_units.return_value = 0
150151
for storage_name in ("archive", "data", "logs", "temp"):
151152
_stop_observer.reset_mock()
@@ -157,7 +158,7 @@ def test_on_storage_detaching(harness):
157158

158159
_stop_observer.assert_called_once_with()
159160
_stop_log_rotation.assert_called_once_with()
160-
_selected_snap.stop.assert_called_once_with()
161+
_selected_snap.stop.assert_called_once_with(disable=True)
161162

162163

163164
def test_patroni_scrape_config(harness):

0 commit comments

Comments
 (0)