Skip to content

Commit 5a8c5b7

Browse files
Fix check in relation initialisation (#1061)
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
1 parent f9f9d1f commit 5a8c5b7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/relations/postgresql_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
7777
Generate password and handle user and database creation for the related application.
7878
"""
7979
# Check for some conditions before trying to access the PostgreSQL instance.
80-
if not self.charm.is_cluster_initialised or not self.charm._patroni.member_started:
80+
if not self.charm.is_cluster_initialised or not self.charm._patroni.primary_endpoint_ready:
8181
logger.debug(
8282
"Deferring on_database_requested: Cluster must be initialized before database can be requested"
8383
)

tests/unit/test_postgresql_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ def test_on_database_requested(harness):
7878
patch("charm.PostgresqlOperatorCharm.update_config"),
7979
patch.object(PostgresqlOperatorCharm, "postgresql", Mock()) as postgresql_mock,
8080
patch.object(EventBase, "defer") as _defer,
81-
patch("charm.Patroni.member_started", new_callable=PropertyMock) as _member_started,
81+
patch(
82+
"charm.Patroni.primary_endpoint_ready", new_callable=PropertyMock
83+
) as _primary_endpoint_ready,
8284
patch(
8385
"relations.postgresql_provider.new_password", return_value="test-password"
8486
) as _new_password,
8587
):
8688
rel_id = harness.model.get_relation(RELATION_NAME).id
8789
# Set some side effects to test multiple situations.
88-
_member_started.side_effect = [False, True, True, True, True, True]
90+
_primary_endpoint_ready.side_effect = [False, True, True, True, True, True]
8991
postgresql_mock.create_user = PropertyMock(
9092
side_effect=[None, PostgreSQLCreateUserError, None, None]
9193
)

0 commit comments

Comments
 (0)