From 92ce076ca614f6be35bb20ebafbb2b9201c7b798 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:47:53 +0200 Subject: [PATCH] Update charm libraries (#257) * chore: update charm libraries * Fix unit tests * fix linting --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: arturo-seijas <102022572+arturo-seijas@users.noreply.github.com> Co-authored-by: Arturo Seijas --- lib/charms/rolling_ops/v0/rollingops.py | 3 ++- tests/unit/test_charm.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/charms/rolling_ops/v0/rollingops.py b/lib/charms/rolling_ops/v0/rollingops.py index 37eb595f..57aa9bf3 100644 --- a/lib/charms/rolling_ops/v0/rollingops.py +++ b/lib/charms/rolling_ops/v0/rollingops.py @@ -88,7 +88,7 @@ def _on_trigger_restart(self, event): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 6 +LIBPATCH = 7 class LockNoRelationError(Exception): @@ -318,6 +318,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable): self.framework.observe(charm.on[self.name].acquire_lock, self._on_acquire_lock) self.framework.observe(charm.on[self.name].run_with_lock, self._on_run_with_lock) self.framework.observe(charm.on[self.name].process_locks, self._on_process_locks) + self.framework.observe(charm.on.leader_elected, self._on_process_locks) def _callback(self: CharmBase, event: EventBase) -> None: """Placeholder for the function that actually runs our event. diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 5865b653..83fe905b 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -458,7 +458,11 @@ def exec_handler(args: ops.testing.ExecArgs) -> None: for call in exec_calls: harness.handle_exec(SERVICE_NAME, call, handler=exec_handler) + # The leader-elected event will cause rollingops to fail because the RollingOpsManager has not + # yet been initialised in the charm's __init__ method. + harness.disable_hooks() harness.set_leader(True) + harness.enable_hooks() harness.container_pebble_ready(SERVICE_NAME) # A few events are not emitted, like config_changed. harness.charm.on.start.emit()