From 777c0502514a435e738e561ef6c929980c45860d Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 11 Aug 2025 14:02:05 -0300 Subject: [PATCH 1/3] Fix check in relation initialisation Signed-off-by: Marcelo Henrique Neppel --- poetry.lock | 4 +--- src/relations/postgresql_provider.py | 2 +- tests/unit/test_postgresql_provider.py | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index d23472a9b3..641c666ee7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. [[package]] name = "allure-pytest" @@ -1595,7 +1595,6 @@ files = [ {file = "psycopg2-2.9.10-cp311-cp311-win_amd64.whl", hash = "sha256:0435034157049f6846e95103bd8f5a668788dd913a7c30162ca9503fdf542cb4"}, {file = "psycopg2-2.9.10-cp312-cp312-win32.whl", hash = "sha256:65a63d7ab0e067e2cdb3cf266de39663203d38d6a8ed97f5ca0cb315c73fe067"}, {file = "psycopg2-2.9.10-cp312-cp312-win_amd64.whl", hash = "sha256:4a579d6243da40a7b3182e0430493dbd55950c493d8c68f4eec0b302f6bbf20e"}, - {file = "psycopg2-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2"}, {file = "psycopg2-2.9.10-cp39-cp39-win32.whl", hash = "sha256:9d5b3b94b79a844a986d029eee38998232451119ad653aea42bb9220a8c5066b"}, {file = "psycopg2-2.9.10-cp39-cp39-win_amd64.whl", hash = "sha256:88138c8dedcbfa96408023ea2b0c369eda40fe5d75002c0964c78f46f11fa442"}, {file = "psycopg2-2.9.10.tar.gz", hash = "sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11"}, @@ -1656,7 +1655,6 @@ files = [ {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:bb89f0a835bcfc1d42ccd5f41f04870c1b936d8507c6df12b7737febc40f0909"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:f0c2d907a1e102526dd2986df638343388b94c33860ff3bbe1384130828714b1"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:f8157bed2f51db683f31306aa497311b560f2265998122abe1dce6428bd86567"}, - {file = "psycopg2_binary-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:27422aa5f11fbcd9b18da48373eb67081243662f9b46e6fd07c3eb46e4535142"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-macosx_12_0_x86_64.whl", hash = "sha256:eb09aa7f9cecb45027683bb55aebaaf45a0df8bf6de68801a6afdc7947bb09d4"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b73d6d7f0ccdad7bc43e6d34273f70d587ef62f824d7261c4ae9b8b1b6af90e8"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ce5ab4bf46a211a8e924d307c1b1fcda82368586a19d0a24f8ae166f5c784864"}, diff --git a/src/relations/postgresql_provider.py b/src/relations/postgresql_provider.py index 84ba570b3f..b0a44ac480 100644 --- a/src/relations/postgresql_provider.py +++ b/src/relations/postgresql_provider.py @@ -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" ) diff --git a/tests/unit/test_postgresql_provider.py b/tests/unit/test_postgresql_provider.py index b74463cabe..864d8e2e0d 100644 --- a/tests/unit/test_postgresql_provider.py +++ b/tests/unit/test_postgresql_provider.py @@ -78,14 +78,14 @@ 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] ) From 66978dd710162d1db87e772f6bc28a50aee2a93d Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 11 Aug 2025 14:04:02 -0300 Subject: [PATCH 2/3] Revert changes to poetry.lock Signed-off-by: Marcelo Henrique Neppel --- poetry.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 641c666ee7..d23472a9b3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. [[package]] name = "allure-pytest" @@ -1595,6 +1595,7 @@ files = [ {file = "psycopg2-2.9.10-cp311-cp311-win_amd64.whl", hash = "sha256:0435034157049f6846e95103bd8f5a668788dd913a7c30162ca9503fdf542cb4"}, {file = "psycopg2-2.9.10-cp312-cp312-win32.whl", hash = "sha256:65a63d7ab0e067e2cdb3cf266de39663203d38d6a8ed97f5ca0cb315c73fe067"}, {file = "psycopg2-2.9.10-cp312-cp312-win_amd64.whl", hash = "sha256:4a579d6243da40a7b3182e0430493dbd55950c493d8c68f4eec0b302f6bbf20e"}, + {file = "psycopg2-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2"}, {file = "psycopg2-2.9.10-cp39-cp39-win32.whl", hash = "sha256:9d5b3b94b79a844a986d029eee38998232451119ad653aea42bb9220a8c5066b"}, {file = "psycopg2-2.9.10-cp39-cp39-win_amd64.whl", hash = "sha256:88138c8dedcbfa96408023ea2b0c369eda40fe5d75002c0964c78f46f11fa442"}, {file = "psycopg2-2.9.10.tar.gz", hash = "sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11"}, @@ -1655,6 +1656,7 @@ files = [ {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:bb89f0a835bcfc1d42ccd5f41f04870c1b936d8507c6df12b7737febc40f0909"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:f0c2d907a1e102526dd2986df638343388b94c33860ff3bbe1384130828714b1"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:f8157bed2f51db683f31306aa497311b560f2265998122abe1dce6428bd86567"}, + {file = "psycopg2_binary-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:27422aa5f11fbcd9b18da48373eb67081243662f9b46e6fd07c3eb46e4535142"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-macosx_12_0_x86_64.whl", hash = "sha256:eb09aa7f9cecb45027683bb55aebaaf45a0df8bf6de68801a6afdc7947bb09d4"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b73d6d7f0ccdad7bc43e6d34273f70d587ef62f824d7261c4ae9b8b1b6af90e8"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ce5ab4bf46a211a8e924d307c1b1fcda82368586a19d0a24f8ae166f5c784864"}, From 39eb2b93a013dc550284a4b9a865446f49bad309 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Mon, 11 Aug 2025 14:05:59 -0300 Subject: [PATCH 3/3] Fix linting Signed-off-by: Marcelo Henrique Neppel --- tests/unit/test_postgresql_provider.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_postgresql_provider.py b/tests/unit/test_postgresql_provider.py index 864d8e2e0d..0a4c2522ff 100644 --- a/tests/unit/test_postgresql_provider.py +++ b/tests/unit/test_postgresql_provider.py @@ -78,7 +78,9 @@ 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.primary_endpoint_ready", new_callable=PropertyMock) as _primary_endpoint_ready, + 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,