From ee74c4608b1fbfcd23981b935510a6685053472c Mon Sep 17 00:00:00 2001 From: Dragomir Penev <6687393+dragomirp@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:15:01 +0300 Subject: [PATCH] [DPE-5205] Port PVC error test workaround and nodeport fixes (#395) * Bump libs * Nodeport tweaks * Ignore pvc error * Ignore PVC errors --- lib/charms/postgresql_k8s/v0/postgresql.py | 12 +++++++++--- src/charm.py | 2 +- src/relations/db.py | 4 +++- src/relations/pgbouncer_provider.py | 4 ++-- .../pgbouncer_provider/test_pgbouncer_provider.py | 6 +++++- tests/integration/relations/test_backend_database.py | 6 +++++- tests/integration/relations/test_db.py | 4 +++- tests/integration/relations/test_db_admin.py | 2 +- tests/integration/relations/test_peers.py | 6 +++++- tests/integration/test_node_port.py | 2 +- tests/integration/test_tls.py | 2 +- tests/integration/test_trust.py | 4 +++- tests/integration/test_upgrade.py | 5 ++++- tests/integration/test_upgrade_data_integrator.py | 5 ++++- tests/integration/test_upgrade_from_stable.py | 5 ++++- 15 files changed, 51 insertions(+), 18 deletions(-) diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index f7d361b5a..c3412d36d 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -36,7 +36,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 33 +LIBPATCH = 34 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" @@ -425,14 +425,20 @@ def get_postgresql_timezones(self) -> Set[str]: timezones = cursor.fetchall() return {timezone[0] for timezone in timezones} - def get_postgresql_version(self) -> str: + def get_postgresql_version(self, current_host=True) -> str: """Returns the PostgreSQL version. Returns: PostgreSQL version number. """ + if current_host: + host = self.current_host + else: + host = None try: - with self._connect_to_database() as connection, connection.cursor() as cursor: + with self._connect_to_database( + database_host=host + ) as connection, connection.cursor() as cursor: cursor.execute("SELECT version();") # Split to get only the version number. return cursor.fetchone()[0].split(" ")[1] diff --git a/src/charm.py b/src/charm.py index 6fa70e36d..d1223cdb2 100755 --- a/src/charm.py +++ b/src/charm.py @@ -426,7 +426,7 @@ def _on_config_changed(self, event: ConfigChangedEvent) -> None: # This emits relation-changed events to every client relation, so only do it when # necessary self.update_client_connection_info(self.config["listen_port"]) - self.patch_port() + self.patch_port(self.client_relation.external_connectivity()) self.render_pgb_config() try: diff --git a/src/relations/db.py b/src/relations/db.py index 98ae21b85..491e3e37b 100644 --- a/src/relations/db.py +++ b/src/relations/db.py @@ -318,7 +318,9 @@ def _on_relation_changed(self, change_event: RelationChangedEvent): { "allowed-subnets": self.get_allowed_subnets(change_event.relation), "allowed-units": self.get_allowed_units(change_event.relation), - "version": self.charm.backend.postgres.get_postgresql_version(), + "version": self.charm.backend.postgres.get_postgresql_version( + current_host=False + ), "host": self.charm.unit_pod_hostname, "user": user, "password": password, diff --git a/src/relations/pgbouncer_provider.py b/src/relations/pgbouncer_provider.py index 33d99b944..55e486388 100644 --- a/src/relations/pgbouncer_provider.py +++ b/src/relations/pgbouncer_provider.py @@ -171,7 +171,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None: # Set the database name self.database_provides.set_database(rel_id, database) - self.charm.patch_port(self.external_connectivity(event)) + self.charm.patch_port(self.external_connectivity()) self.update_connection_info(event.relation) def _on_relation_departed(self, event: RelationDepartedEvent) -> None: @@ -230,7 +230,7 @@ def update_connection_info(self, relation): # Set the database version. if self.charm.backend.check_backend(): self.database_provides.set_version( - relation.id, self.charm.backend.postgres.get_postgresql_version() + relation.id, self.charm.backend.postgres.get_postgresql_version(current_host=False) ) def update_endpoints(self, relation=None) -> None: diff --git a/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py b/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py index a86ceb61c..9283fc9eb 100644 --- a/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py +++ b/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py @@ -88,7 +88,11 @@ async def test_database_relation_with_charm_libraries(ops_test: OpsTest, pgb_cha async with ops_test.fast_forward(): await ops_test.model.wait_for_idle( - apps=[PGB, PG], status="active", raise_on_blocked=False, timeout=1200 + apps=[PGB, PG], + status="active", + raise_on_blocked=False, + timeout=1200, + raise_on_error=False, ) # Relate the charms and wait for them exchanging some connection data. diff --git a/tests/integration/relations/test_backend_database.py b/tests/integration/relations/test_backend_database.py index 216ae918f..e31cc2ac3 100644 --- a/tests/integration/relations/test_backend_database.py +++ b/tests/integration/relations/test_backend_database.py @@ -75,7 +75,11 @@ async def test_relate_pgbouncer_to_postgres(ops_test: OpsTest, pgb_charm): await asyncio.gather( ops_test.model.wait_for_idle(apps=[PGB], status="blocked", timeout=1000), ops_test.model.wait_for_idle( - apps=[PG], status="active", timeout=1000, wait_for_exact_units=3 + apps=[PG], + status="active", + timeout=1000, + wait_for_exact_units=3, + raise_on_error=False, ), ) diff --git a/tests/integration/relations/test_db.py b/tests/integration/relations/test_db.py index eb4e04740..ac0694872 100644 --- a/tests/integration/relations/test_db.py +++ b/tests/integration/relations/test_db.py @@ -66,7 +66,9 @@ async def test_create_db_legacy_relation(ops_test: OpsTest, pgb_charm): f"{PGB}:backend-database", f"{PG}:database" ) wait_for_relation_joined_between(ops_test, PGB, PG) - await ops_test.model.wait_for_idle(apps=[PG, PGB], status="active", timeout=1000) + await ops_test.model.wait_for_idle( + apps=[PG, PGB], status="active", timeout=1000, raise_on_error=False + ) pgb_user, pgb_password = await get_backend_user_pass(ops_test, backend_relation) await check_database_users_existence( diff --git a/tests/integration/relations/test_db_admin.py b/tests/integration/relations/test_db_admin.py index c2490517b..f18ebd8d9 100644 --- a/tests/integration/relations/test_db_admin.py +++ b/tests/integration/relations/test_db_admin.py @@ -57,7 +57,7 @@ async def test_create_db_admin_legacy_relation(ops_test: OpsTest, pgb_charm): # update pgbouncer port because discourse only likes 5432 await ops_test.model.applications[PGB].set_config({"listen_port": "5432"}) - await ops_test.model.wait_for_idle(apps=[PG, PGB], timeout=1000) + await ops_test.model.wait_for_idle(apps=[PG, PGB], timeout=1000, raise_on_error=False) backend_relation = await ops_test.model.add_relation( f"{PGB}:backend-database", f"{PG}:database" diff --git a/tests/integration/relations/test_peers.py b/tests/integration/relations/test_peers.py index a8d2d18f4..7b4f44d75 100644 --- a/tests/integration/relations/test_peers.py +++ b/tests/integration/relations/test_peers.py @@ -67,7 +67,11 @@ async def test_scaled_relations(ops_test: OpsTest): apps=[PGB], status="blocked", timeout=1000, wait_for_exact_units=3 ), ops_test.model.wait_for_idle( - apps=[PG], status="active", timeout=1000, wait_for_exact_units=3 + apps=[PG], + status="active", + timeout=1000, + wait_for_exact_units=3, + raise_on_error=False, ), ) diff --git a/tests/integration/test_node_port.py b/tests/integration/test_node_port.py index 2d4350c6c..96af44ed8 100644 --- a/tests/integration/test_node_port.py +++ b/tests/integration/test_node_port.py @@ -136,7 +136,7 @@ async def test_build_and_deploy(ops_test: OpsTest, pgb_charm): await ops_test.model.relate(tls_certificates_app_name, POSTGRESQL_APP_NAME) if wait_for_apps: - await ops_test.model.wait_for_idle(status="active", timeout=1200) + await ops_test.model.wait_for_idle(status="active", timeout=1200, raise_on_error=False) @pytest.mark.group(1) diff --git a/tests/integration/test_tls.py b/tests/integration/test_tls.py index 7ac65a20c..00a0b091c 100644 --- a/tests/integration/test_tls.py +++ b/tests/integration/test_tls.py @@ -94,7 +94,7 @@ async def test_build_and_deploy(ops_test: OpsTest, pgb_charm): if wait_for_apps: async with ops_test.fast_forward(): - await ops_test.model.wait_for_idle(status="active", timeout=1200) + await ops_test.model.wait_for_idle(status="active", timeout=1200, raise_on_error=False) @pytest.mark.group(1) diff --git a/tests/integration/test_trust.py b/tests/integration/test_trust.py index 37320a673..30b91b4c2 100644 --- a/tests/integration/test_trust.py +++ b/tests/integration/test_trust.py @@ -116,7 +116,9 @@ async def test_build_and_deploy(ops_test: OpsTest, pgb_charm): config={"profile": "testing"}, ) await ops_test.model.relate(PGB, PG) - await ops_test.model.wait_for_idle(apps=[PGB, PG], status="active", timeout=1200) + await ops_test.model.wait_for_idle( + apps=[PGB, PG], status="active", timeout=1200, raise_on_error=False + ) await ops_test.model.relate(PGB, f"{CLIENT_APP_NAME}:database") await ops_test.model.wait_for_idle(apps=[PGB], status="blocked", timeout=1200) diff --git a/tests/integration/test_upgrade.py b/tests/integration/test_upgrade.py index 8b9224156..a8e02fb0b 100644 --- a/tests/integration/test_upgrade.py +++ b/tests/integration/test_upgrade.py @@ -79,7 +79,10 @@ async def test_deploy_latest(ops_test: OpsTest, pgb_charm) -> None: logger.info("Wait for applications to become active") async with ops_test.fast_forward(): await ops_test.model.wait_for_idle( - apps=[PG, PGB, CLIENT_APP_NAME], status="active", timeout=1200 + apps=[PG, PGB, CLIENT_APP_NAME], + status="active", + timeout=1200, + raise_on_error=False, ) assert len(ops_test.model.applications[PG].units) == 3 assert len(ops_test.model.applications[PGB].units) == 3 diff --git a/tests/integration/test_upgrade_data_integrator.py b/tests/integration/test_upgrade_data_integrator.py index 0134457d7..ac1877130 100644 --- a/tests/integration/test_upgrade_data_integrator.py +++ b/tests/integration/test_upgrade_data_integrator.py @@ -59,7 +59,10 @@ async def test_deploy_stable(ops_test: OpsTest, pgb_charm) -> None: await ops_test.model.add_relation(DATA_INTEGRATOR_APP_NAME, PGB) async with ops_test.fast_forward(): await ops_test.model.wait_for_idle( - apps=[PG, PGB, DATA_INTEGRATOR_APP_NAME], status="active", timeout=1200 + apps=[PG, PGB, DATA_INTEGRATOR_APP_NAME], + status="active", + timeout=1200, + raise_on_error=False, ) assert len(ops_test.model.applications[PG].units) == 3 assert len(ops_test.model.applications[PGB].units) == 2 diff --git a/tests/integration/test_upgrade_from_stable.py b/tests/integration/test_upgrade_from_stable.py index b0fe24b2b..98e4567ec 100644 --- a/tests/integration/test_upgrade_from_stable.py +++ b/tests/integration/test_upgrade_from_stable.py @@ -73,7 +73,10 @@ async def test_deploy_stable(ops_test: OpsTest, pgb_charm) -> None: logger.info("Wait for applications to become active") async with ops_test.fast_forward(): await ops_test.model.wait_for_idle( - apps=[PG, PGB, CLIENT_APP_NAME], status="active", timeout=1200 + apps=[PG, PGB, CLIENT_APP_NAME], + status="active", + timeout=1200, + raise_on_error=False, ) assert len(ops_test.model.applications[PG].units) == 3 assert len(ops_test.model.applications[PGB].units) == 3