Skip to content

[DPE-7603][DPE-6990] Fix check in relation initialisation #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
Generate password and handle user and database creation for the related application.
"""
# Check for some conditions before trying to access the PostgreSQL instance.
if not self.charm.is_cluster_initialised or not self.charm._patroni.member_started:
if not self.charm.is_cluster_initialised or not self.charm._patroni.primary_endpoint_ready:
logger.debug(
"Deferring on_database_requested: Cluster must be initialized before database can be requested"
)
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ def test_on_database_requested(harness):
patch("charm.PostgresqlOperatorCharm.update_config"),
patch.object(PostgresqlOperatorCharm, "postgresql", Mock()) as postgresql_mock,
patch.object(EventBase, "defer") as _defer,
patch("charm.Patroni.member_started", new_callable=PropertyMock) as _member_started,
patch(
"charm.Patroni.primary_endpoint_ready", new_callable=PropertyMock
) as _primary_endpoint_ready,
patch(
"relations.postgresql_provider.new_password", return_value="test-password"
) as _new_password,
):
rel_id = harness.model.get_relation(RELATION_NAME).id
# Set some side effects to test multiple situations.
_member_started.side_effect = [False, True, True, True, True, True]
_primary_endpoint_ready.side_effect = [False, True, True, True, True, True]
postgresql_mock.create_user = PropertyMock(
side_effect=[None, PostgreSQLCreateUserError, None, None]
)
Expand Down