Skip to content
Merged
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
5 changes: 3 additions & 2 deletions src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ def update_tls_flag(self, tls: str) -> None:
ca = ""

for relation in relations:
self.database_provides.set_tls(relation.id, tls)
self.database_provides.set_tls_ca(relation.id, ca)
if self.database_provides.fetch_relation_field(relation.id, "database"):
self.database_provides.set_tls(relation.id, tls)
self.database_provides.set_tls_ca(relation.id, ca)
Comment on lines +268 to +270
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if the relation is already properly intialised. If not the values should be set by the database_requested hook.


def _check_multiple_endpoints(self) -> bool:
"""Checks if there are relations with other endpoints."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_deploy_stable(ops_test: OpsTest) -> None:
logger.info("Wait for applications to become active")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active", raise_on_error=False
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active"
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3
instances_roles = await get_instances_roles(ops_test)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/ha_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async def test_deploy_latest(ops_test: OpsTest) -> None:
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME],
status="active",
raise_on_error=False,
timeout=1000,
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ha_tests/test_upgrade_from_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def test_deploy_stable(ops_test: OpsTest) -> None:
logger.info("Wait for applications to become active")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active", raise_on_error=False
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active"
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def test_deploy_stable(ops_test: OpsTest) -> None:
logger.info("Wait for applications to become active")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active", raise_on_error=False
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active"
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3
instances_roles = await get_instances_roles(ops_test)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ async def build_and_deploy(
apps=[database_app_name],
status=status,
raise_on_blocked=True,
raise_on_error=False,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ignored this due to early volume mount errors, but it will also hide other errors during start up.

timeout=1000,
wait_for_exact_units=num_units,
)
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/test_postgresql_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

from unittest.mock import Mock, PropertyMock, patch
from unittest.mock import Mock, PropertyMock, patch, sentinel

import pytest
from charms.postgresql_k8s.v0.postgresql import (
Expand Down Expand Up @@ -216,3 +216,27 @@ def test_on_relation_broken(harness):
)
harness.charm.postgresql_client_relation._on_relation_broken(event)
postgresql_mock.delete_user.assert_not_called()


def test_update_tls_flag(harness):
with (
patch("charm.PostgreSQLTLS.get_tls_files", return_value=(None, sentinel.ca, None)),
patch(
"relations.postgresql_provider.new_password", return_value="test-password"
) as _new_password,
patch(
"relations.postgresql_provider.DatabaseProvides.fetch_relation_field",
side_effect=[None, "db"],
),
patch(
"relations.postgresql_provider.DatabaseProvides.set_tls",
) as _set_tls,
patch(
"relations.postgresql_provider.DatabaseProvides.set_tls_ca",
) as _set_tls_ca,
):
with harness.hooks_disabled():
second_rel = harness.add_relation(RELATION_NAME, "second_app")
harness.charm.postgresql_client_relation.update_tls_flag("True")
_set_tls.assert_called_once_with(second_rel, "True")
_set_tls_ca.assert_called_once_with(second_rel, sentinel.ca)