Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def _on_peer_relation_changed(self, event: HookEvent):
# Update the members of the cluster in the Patroni configuration on this unit.
self.update_config()
except RetryError:
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
self.set_unit_status(MaintenanceStatus("pending update cluster members on member"))
return
except ValueError as e:
self.set_unit_status(BlockedStatus("Configuration Error. Please check the logs"))
Expand Down Expand Up @@ -1412,9 +1412,9 @@ def add_cluster_member(self, member: str) -> None:
try:
self.update_config()
except RetryError:
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
self.set_unit_status(MaintenanceStatus("pending update cluster members on member"))
else:
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
self.set_unit_status(WaitingStatus("pending update cluster members on member"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using WaitingStatus here as a flag to recognize RetryError==MaintenanceStatus.
Should I sync all to the same status?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have something like WaitingStatus("waiting for peer IP") here and MaintenanceStatus("updating cluster members") in L1415 and L1196 to make the status messages correspond to each state?


def _get_unit_ip(self, unit: Unit, relation_name: str = PEER) -> str | None:
"""Get the IP address of a specific unit.
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2233,11 +2233,12 @@ def test_on_peer_relation_changed(harness):
_update_config.assert_called_once()
_start_patroni.assert_not_called()
_update_new_unit_status.assert_not_called()
assert isinstance(harness.model.unit.status, BlockedStatus)
assert isinstance(harness.model.unit.status, MaintenanceStatus)

# Test event is early exiting when in blocked status.
_update_config.side_effect = None
_member_started.return_value = False
harness.model.unit.status = BlockedStatus()
harness.charm._on_peer_relation_changed(mock_event)
_start_patroni.assert_not_called()

Expand Down Expand Up @@ -2526,8 +2527,8 @@ def test_add_cluster_member(harness):
_update_config.side_effect = RetryError(last_attempt=None)
harness.charm.add_cluster_member("postgresql-0")
_update_config.assert_called_once_with()
assert isinstance(harness.charm.unit.status, BlockedStatus)
assert harness.charm.unit.status.message == "failed to update cluster members on member"
assert isinstance(harness.charm.unit.status, MaintenanceStatus | WaitingStatus)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to assert the exact status we are expecting here.

assert harness.charm.unit.status.message == "pending update cluster members on member"
_update_config.reset_mock()

# Not ready error if not all members are ready
Expand Down
Loading