Skip to content

Commit

Permalink
Merge branch 'main' into dpe-5827-all-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Nov 29, 2024
2 parents f88c956 + d8f8226 commit 2d5ab35
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 273 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
lint:
name: Lint
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v23.1.0

unit-test:
name: Unit test charm
Expand All @@ -45,7 +45,7 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.1.0
with:
cache: true

Expand All @@ -59,7 +59,7 @@ jobs:
allure_on_amd64: false
- agent: 3.4.6 # renovate: juju-agent-pin-minor
allure_on_amd64: true
- snap_channel: 3.6/candidate
- snap_channel: 3.6/stable
allure_on_amd64: false
architecture:
- amd64
Expand All @@ -69,15 +69,15 @@ jobs:
allure_on_amd64: true
architecture: arm64
- juju:
snap_channel: 3.6/candidate
snap_channel: 3.6/stable
allure_on_amd64: false
architecture: arm64
name: Integration | ${{ matrix.juju.agent || matrix.juju.snap_channel }} | ${{ matrix.architecture }}
needs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v23.1.0
with:
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
architecture: ${{ matrix.architecture }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.1.0

release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v23.1.0
with:
channel: 14/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
sync-docs:
name: Sync docs from Discourse
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v23.0.5
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v23.1.0
with:
reviewers: a-velasco
permissions:
Expand Down
7 changes: 4 additions & 3 deletions lib/charms/postgresql_k8s/v0/postgresql_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
)
from ops.charm import ActionEvent, RelationBrokenEvent
from ops.framework import Object
from ops.pebble import ConnectionError, PathError, ProtocolError
from ops.pebble import ConnectionError as PebbleConnectionError
from ops.pebble import PathError, ProtocolError
from tenacity import RetryError

# The unique Charmhub library identifier, never change it
Expand All @@ -44,7 +45,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version.
LIBPATCH = 9
LIBPATCH = 10

logger = logging.getLogger(__name__)
SCOPE = "unit"
Expand Down Expand Up @@ -143,7 +144,7 @@ def _on_certificate_available(self, event: CertificateAvailableEvent) -> None:
logger.debug("Cannot push TLS certificates at this moment")
event.defer()
return
except (ConnectionError, PathError, ProtocolError, RetryError) as e:
except (PebbleConnectionError, PathError, ProtocolError, RetryError) as e:
logger.error("Cannot push TLS certificates: %r", e)
event.defer()
return
Expand Down
415 changes: 206 additions & 209 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package-mode = false
[tool.poetry.dependencies]
python = "^3.10"
ops = "^2.17.0"
cryptography = "^43.0.3"
boto3 = "^1.35.66"
cryptography = "^44.0.0"
boto3 = "^1.35.70"
pgconnstr = "^1.0.1"
requests = "^2.32.3"
tenacity = "^9.0.0"
cosl = "^0.0.43"
cosl = "^0.0.45"
pydantic = "^1.10.19"
poetry-core = "^1.9.1"
jsonschema = "^4.23.0"
Expand All @@ -39,7 +39,7 @@ opentelemetry-exporter-otlp-proto-http = "1.21.0"
optional = true

[tool.poetry.group.format.dependencies]
ruff = "^0.7.4"
ruff = "^0.8.0"

[tool.poetry.group.lint]
optional = true
Expand All @@ -51,7 +51,7 @@ codespell = "^2.3.0"
optional = true

[tool.poetry.group.unit.dependencies]
coverage = {extras = ["toml"], version = "^7.6.7"}
coverage = {extras = ["toml"], version = "^7.6.8"}
pydantic = "^1.10.19"
pytest = "^8.3.3"
pytest-mock = "^3.14.0"
Expand All @@ -64,15 +64,15 @@ optional = true
[tool.poetry.group.integration.dependencies]
lightkube = "^0.15.5"
pytest = "^8.3.3"
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.0", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator = "^0.38.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.0", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
juju = "<=3.5.2.1"
psycopg2-binary = "^2.9.10"
boto3 = "^1.35.66"
boto3 = "^1.35.70"
tenacity = "^9.0.0"
allure-pytest = "^2.13.5"

Expand Down
27 changes: 15 additions & 12 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ def _get_nearest_timeline(self, timestamp: str) -> tuple[str, str] | None:
(stanza, timeline) of the nearest timeline or backup. None, if there are no matches.
"""
timelines = self._list_backups(show_failed=False) | self._list_timelines()
if timestamp == "latest":
return max(timelines.items())[1] if len(timelines) > 0 else None
filtered_timelines = [
(timeline_key, timeline_object)
for timeline_key, timeline_object in timelines.items()
Expand Down Expand Up @@ -600,8 +602,6 @@ def check_stanza(self) -> bool:
# for that or else the s3 initialization sequence will fail.
for attempt in Retrying(stop=stop_after_attempt(6), wait=wait_fixed(10), reraise=True):
with attempt:
if self.charm._patroni.member_started:
self.charm._patroni.reload_patroni_configuration()
self._execute_command(["pgbackrest", f"--stanza={self.stanza_name}", "check"])
self.charm._set_active_status()
except Exception as e:
Expand Down Expand Up @@ -640,9 +640,6 @@ def coordinate_stanza_fields(self) -> None:
})

self.charm.update_config()
if self.charm._patroni.member_started:
self.charm._patroni.reload_patroni_configuration()

break

@property
Expand Down Expand Up @@ -737,8 +734,6 @@ def _on_s3_credential_changed(self, event: CredentialsChangedEvent) -> bool | No

def _on_s3_credential_changed_primary(self, event: HookEvent) -> bool:
self.charm.update_config()
if self.charm._patroni.member_started:
self.charm._patroni.reload_patroni_configuration()

try:
self._create_bucket_if_not_exists()
Expand Down Expand Up @@ -967,6 +962,17 @@ def _on_restore_action(self, event): # noqa: C901
elif is_backup_id_timeline:
restore_stanza_timeline = timelines[backup_id]
else:
backups_list = list(self._list_backups(show_failed=False).values())
timelines_list = self._list_timelines()
if (
restore_to_time == "latest"
and timelines_list is not None
and max(timelines_list.values() or [backups_list[0]]) not in backups_list
):
error_message = "There is no base backup created from the latest timeline"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return
restore_stanza_timeline = self._get_nearest_timeline(restore_to_time)
if not restore_stanza_timeline:
error_message = f"Can't find the nearest timeline before timestamp {restore_to_time} to restore"
Expand Down Expand Up @@ -1100,11 +1106,8 @@ def _pre_restore_checks(self, event: ActionEvent) -> bool:
event.fail(validation_message)
return False

if not event.params.get("backup-id") and event.params.get("restore-to-time") in (
None,
"latest",
):
error_message = "Missing backup-id or non-latest restore-to-time parameter to be able to do restore"
if not event.params.get("backup-id") and event.params.get("restore-to-time") is None:
error_message = "Either backup-id or restore-to-time parameters need to be provided to be able to do restore"
logger.error(f"Restore failed: {error_message}")
event.fail(error_message)
return False
Expand Down
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
ServiceInfo,
ServiceStatus,
)
from requests import ConnectionError
from requests import ConnectionError as RequestsConnectionError
from tenacity import RetryError, Retrying, stop_after_attempt, stop_after_delay, wait_fixed

from backups import CANNOT_RESTORE_PITR, S3_BLOCK_MESSAGES, PostgreSQLBackups
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def _set_active_status(self):
self.unit.status = ActiveStatus("Standby")
elif self._patroni.member_started:
self.unit.status = ActiveStatus()
except (RetryError, ConnectionError) as e:
except (RetryError, RequestsConnectionError) as e:
logger.error(f"failed to get primary with error {e}")

def _initialize_cluster(self, event: WorkloadEvent) -> bool:
Expand Down
1 change: 1 addition & 0 deletions templates/patroni.yml.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bootstrap:
dcs:
synchronous_mode: true
failsafe_mode: true
synchronous_node_count: {{ synchronous_node_count }}
postgresql:
use_pg_rewind: true
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/ha_tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.

import asyncio
import logging
import os
from asyncio import TimeoutError

import pytest
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -212,7 +212,7 @@ async def test_app_resources_conflicts(ops_test: OpsTest):
await ops_test.model.wait_for_idle(
apps=[DUP_DATABASE_APP_NAME], timeout=500, status="blocked"
)
except TimeoutError:
except asyncio.TimeoutError:
logger.info("Application is not in blocked state. Checking logs...")

# Since application have postgresql db in storage from external application it should not be able to connect due to new password
Expand Down
Loading

0 comments on commit 2d5ab35

Please sign in to comment.