Skip to content

Commit eddf95e

Browse files
[DPE-10454] Use better status instead of blocked for transient update failures (#1795)
* [DPE-10454] Use better status instead of blocked for transient update failures Use maintenance/waiting status instead of blocked one. The 'failed to update cluster members on member' BlockedStatus was misleading: these are transient, self-recovering conditions (a RetryError from update_config(), or a peer IP not yet published) rather than states needing operator intervention. Replace them with MaintenanceStatus / WaitingStatus and a 'updating cluster members' message. Update test_on_peer_relation_changed accordingly, and set an explicit BlockedStatus before exercising the early-exit guard so that path stays covered. Assisted-by: Claude:claude-5-fable * [DPE-10454] Apply comments from review
1 parent 61d8adb commit eddf95e

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/charm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ def _on_peer_relation_changed(self, event: HookEvent):
12541254
# Update the members of the cluster in the Patroni configuration on this unit.
12551255
self.update_config()
12561256
except RetryError:
1257-
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
1257+
self.set_unit_status(MaintenanceStatus("cluster member update failed, retrying"))
12581258
return
12591259
except ValueError as e:
12601260
self.set_unit_status(BlockedStatus("Configuration Error. Please check the logs"))
@@ -1473,9 +1473,9 @@ def add_cluster_member(self, member: str) -> None:
14731473
try:
14741474
self.update_config()
14751475
except RetryError:
1476-
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
1476+
self.set_unit_status(MaintenanceStatus("cluster member update failed, retrying"))
14771477
else:
1478-
self.set_unit_status(BlockedStatus("failed to update cluster members on member"))
1478+
self.set_unit_status(WaitingStatus("waiting for peer IP"))
14791479

14801480
def _get_unit_ip(self, unit: Unit, relation_name: str = PEER_RELATION) -> str | None:
14811481
"""Get the IP address of a specific unit.

tests/unit/test_charm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,11 +2246,12 @@ def test_on_peer_relation_changed(harness):
22462246
_update_config.assert_called_once()
22472247
_start_patroni.assert_not_called()
22482248
_update_new_unit_status.assert_not_called()
2249-
assert isinstance(harness.model.unit.status, BlockedStatus)
2249+
assert isinstance(harness.model.unit.status, MaintenanceStatus)
22502250

22512251
# Test event is early exiting when in blocked status.
22522252
_update_config.side_effect = None
22532253
_member_started.return_value = False
2254+
harness.model.unit.status = BlockedStatus()
22542255
harness.charm._on_peer_relation_changed(mock_event)
22552256
_start_patroni.assert_not_called()
22562257

@@ -2524,12 +2525,11 @@ def test_add_cluster_member(harness):
25242525
_update_config.assert_called_once_with()
25252526
_update_config.reset_mock()
25262527

2527-
# Charm blocks when update_config fails
2528+
# Charm goes into maintenance when update_config fails
25282529
_update_config.side_effect = RetryError(last_attempt=None)
25292530
harness.charm.add_cluster_member("postgresql-0")
25302531
_update_config.assert_called_once_with()
2531-
assert isinstance(harness.charm.unit.status, BlockedStatus)
2532-
assert harness.charm.unit.status.message == "failed to update cluster members on member"
2532+
assert isinstance(harness.charm.unit.status, MaintenanceStatus | WaitingStatus)
25332533
_update_config.reset_mock()
25342534

25352535
# Not ready error if not all members are ready

0 commit comments

Comments
 (0)