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
2 changes: 1 addition & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ parts:
source: .
after:
- poetry-deps
poetry-export-extra-args: ['--only', 'main,charm-libs']
poetry-export-extra-args: ['--only', 'main,charm-libs,single-kernel']
build-packages:
- libffi-dev # Needed to build Python dependencies with Rust from source
- libssl-dev # Needed to build Python dependencies with Rust from source
Expand Down
205 changes: 180 additions & 25 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ pysyncobj = "^0.3.15"
charm-refresh = "^3.1.0.2"
charmlibs-snap = "^1.0.1"
charmlibs-systemd = "^1.0.0"
postgresql-charms-single-kernel = {extras = ["postgresql"], version="16.2.2"}

[tool.poetry.group.single-kernel.dependencies]
postgresql-charms-single-kernel = "16.3.0"

[tool.poetry.group.charm-libs.dependencies]
# data_platform_libs/v0/data_models.py
pydantic = "*"
# single-kernel is pinned bare (no extra) in the single-kernel group, so the
# charm build declares the lib's "postgresql"-extra runtime deps that aren't
# already in main (see the library's optional-dependencies for the full set).
httpx = "*"
data-platform-helpers = ">=0.1.7"
charmlibs-pathops = ">=1.0.1"
charmlibs-interfaces-tls-certificates = ">=1.8.3"
charmlibs-rollingops = ">=1.1.1"
tomli = "^2.4.1"

[tool.poetry.group.format]
optional = true
Expand Down Expand Up @@ -52,6 +63,10 @@ tomli-w = "^1.2.0"
optional = true

[tool.poetry.group.integration.dependencies]
# single-kernel itself (bare, no extra) is installed via the shared single-kernel
# group (see tox.ini); the tests only import its pure-stdlib config.literals.
# psycopg2-binary provides the psycopg2 module the tests import without building
# the source psycopg2 the lib's postgresql extra would pull in.
pytest = "^9.1.1"
pytest-operator = "^0.43.2"
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
Expand Down
5 changes: 3 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
SecretRemoveEvent,
main,
)
from single_kernel_postgresql.config.literals import PEER, Substrates
from single_kernel_postgresql.config.enums import Substrates
from single_kernel_postgresql.config.literals import PEER_RELATION
from single_kernel_postgresql.utils import _change_owner

from config import CharmConfig
Expand Down Expand Up @@ -285,7 +286,7 @@ def _peers(self) -> Relation | None:
A:class:`ops.model.Relation` object representing
the peer relation.
"""
return self.model.get_relation(PEER)
return self.model.get_relation(PEER_RELATION)


if __name__ == "__main__":
Expand Down
7 changes: 0 additions & 7 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@

"""File containing constants to be used in the charm."""

API_REQUEST_TIMEOUT = 5
PATRONI_CLUSTER_STATUS_ENDPOINT = "cluster"
PEER = "database-peers"

# Snap constants.
SNAP_COMMON_PATH = "/var/snap/charmed-postgresql/common"

# # Watcher constants
WATCHER_RELATION = "watcher"

RAFT_PORT = 2222
RAFT_PARTNER_PREFIX = "partner_node_status_server_"
5 changes: 3 additions & 2 deletions src/raft_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
)
from jinja2 import Template
from pysyncobj.utility import TcpUtility
from single_kernel_postgresql.config.literals import Substrates
from single_kernel_postgresql.config.enums import Substrates
from single_kernel_postgresql.config.literals import PATRONI_CLUSTER_STATUS_ENDPOINT
from single_kernel_postgresql.utils import (
create_directory,
parallel_patroni_get_request,
Expand All @@ -43,7 +44,7 @@
from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed

from cluster import ClusterMember
from constants import PATRONI_CLUSTER_STATUS_ENDPOINT, RAFT_PARTNER_PREFIX, RAFT_PORT
from constants import RAFT_PARTNER_PREFIX, RAFT_PORT

if TYPE_CHECKING:
from charm import PostgresqlWatcherCharm
Expand Down
8 changes: 3 additions & 5 deletions src/relations/watcher_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,18 @@
UpdateStatusEvent,
WaitingStatus,
)
from single_kernel_postgresql.config.literals import Substrates
from single_kernel_postgresql.config.enums import Substrates
from single_kernel_postgresql.config.literals import WATCHER_RELATION
from single_kernel_postgresql.utils import _change_owner

from constants import RAFT_PORT, SNAP_COMMON_PATH, WATCHER_RELATION
from constants import RAFT_PORT, SNAP_COMMON_PATH
from raft_controller import RaftController, install_service

if typing.TYPE_CHECKING:
from charm import PostgresqlWatcherCharm

logger = logging.getLogger(__name__)

SNAP_NAME = "charmed-postgresql"
SNAP_CHANNEL = "16/edge"


class WatcherRequirerHandler(Object):
"""Handles the watcher requirer relation and watcher-mode lifecycle."""
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import yaml
from juju.model import Model
from pytest_operator.plugin import OpsTest
from single_kernel_postgresql.config.literals import PEER_RELATION
from tenacity import (
retry,
stop_after_attempt,
wait_exponential,
)

from constants import PEER

CHARM_BASE = "ubuntu@22.04"
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
DATABASE_APP_NAME = "postgresql"
Expand Down Expand Up @@ -120,7 +119,7 @@ async def get_password(
Returns:
the user password.
"""
secret = await get_secret_by_label(ops_test, label=f"{PEER}.{database_app_name}.app")
secret = await get_secret_by_label(ops_test, label=f"{PEER_RELATION}.{database_app_name}.app")
password = secret.get(f"{username}-password")

return password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from jubilant import Juju
from jubilant.statustypes import Status, UnitStatus
from pysyncobj.utility import TcpUtility
from single_kernel_postgresql.config.literals import PEER_RELATION
from tenacity import Retrying, stop_after_delay, wait_fixed
from yaml import safe_load

from constants import PEER, RAFT_PARTNER_PREFIX
from constants import RAFT_PARTNER_PREFIX

from ..helpers import execute_queries_on_unit

Expand Down Expand Up @@ -138,7 +139,7 @@ def wait_for_apps_status(jubilant_status_func: JujuAppsStatusFn, *apps: str) ->
def get_user_password(juju: Juju, app_name: str, user: str) -> str | None:
"""Get a system user's password."""
for secret in juju.secrets():
if secret.label == f"{PEER}.{app_name}.app":
if secret.label == f"{PEER_RELATION}.{app_name}.app":
revealed_secret = juju.show_secret(secret.uri, reveal=True)
return revealed_secret.content.get(f"{user}-password")

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_raft_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from jinja2 import Template
from pytest import fixture
from single_kernel_postgresql.config.literals import Substrates
from single_kernel_postgresql.config.enums import Substrates
from tenacity import stop_after_delay, wait_fixed

from constants import RAFT_PARTNER_PREFIX
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ description = Run unit tests
set_env =
{[testenv]set_env}
commands_pre =
poetry install --only main,charm-libs,unit --no-root
poetry install --only main,charm-libs,single-kernel,unit --no-root
commands =
poetry run coverage run --source={[vars]src_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
Expand All @@ -66,6 +66,6 @@ pass_env =
LANDSCAPE_ACCOUNT_NAME
LANDSCAPE_REGISTRATION_KEY
commands_pre =
poetry install --only integration --no-root
poetry install --only integration,single-kernel --no-root
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --ignore={[vars]tests_path}/unit/ {posargs}
Loading