Skip to content

Commit

Permalink
[DPE-5205] Port PVC error test workaround and nodeport fixes (#395)
Browse files Browse the repository at this point in the history
* Bump libs

* Nodeport tweaks

* Ignore pvc error

* Ignore PVC errors
  • Loading branch information
dragomirp authored Aug 30, 2024
1 parent be8192c commit ee74c46
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 18 deletions.
12 changes: 9 additions & 3 deletions lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/relations/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/relations/pgbouncer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/relations/test_backend_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/integration/relations/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relations/test_db_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/relations/test_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_node_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_upgrade_data_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_upgrade_from_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee74c46

Please sign in to comment.