Skip to content

Commit

Permalink
Observe leader elected (#65)
Browse files Browse the repository at this point in the history
* observe leader-elected event

* update unit test
  • Loading branch information
natalian98 authored Aug 16, 2022
1 parent e9e724c commit 6070b93
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build/
__pycache__/
.tox
.idea
3 changes: 2 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, *args):
self.on.config_changed,
self.on.install,
self.on.upgrade_charm,
self.on.leader_elected,
self.on["object-storage"].relation_changed,
self.on["object-storage"].relation_joined,
]:
Expand Down Expand Up @@ -155,7 +156,7 @@ def main(self, event):
def _check_leader(self):
if not self.unit.is_leader():
self.log.info("Not a leader, skipping set_pod_spec")
raise CheckFailed("", ActiveStatus)
raise CheckFailed("Waiting for leadership", WaitingStatus)

def _get_interfaces(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def harness():

def test_not_leader(harness):
harness.begin_with_initial_hooks()
assert harness.charm.model.unit.status == ActiveStatus("")
assert harness.charm.model.unit.status == WaitingStatus("Waiting for leadership")


def test_missing_image(harness):
Expand Down

0 comments on commit 6070b93

Please sign in to comment.