Skip to content

Commit f2873a9

Browse files
authored
[DPE-7678] Enable disable extensions afrer restore (#1025)
* Enable disable extensions afrer restore * Update libs
1 parent c8a49ae commit f2873a9

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 47
334+
LIBPATCH = 49
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -3527,16 +3527,20 @@ def __init__(
35273527
self.consumer_group_prefix = consumer_group_prefix or ""
35283528
self.mtls_cert = mtls_cert
35293529

3530+
@staticmethod
3531+
def is_topic_value_acceptable(topic_value: str) -> bool:
3532+
"""Check whether the given Kafka topic value is acceptable."""
3533+
return "*" not in topic_value[:3]
3534+
35303535
@property
35313536
def topic(self):
35323537
"""Topic to use in Kafka."""
35333538
return self._topic
35343539

35353540
@topic.setter
35363541
def topic(self, value):
3537-
# Avoid wildcards
3538-
if value == "*":
3539-
raise ValueError(f"Error on topic '{value}', cannot be a wildcard.")
3542+
if not self.is_topic_value_acceptable(value):
3543+
raise ValueError(f"Error on topic '{value}', unacceptable value.")
35403544
self._topic = value
35413545

35423546
def set_mtls_cert(self, relation_id: int, mtls_cert: str) -> None:
@@ -3760,6 +3764,10 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
37603764
event.relation, app=event.app, unit=event.unit
37613765
)
37623766

3767+
def _on_secret_changed_event(self, event: SecretChangedEvent) -> None:
3768+
"""Event emitted when the relation data has changed."""
3769+
pass
3770+
37633771

37643772
class OpenSearchProvides(OpenSearchProvidesData, OpenSearchProvidesEventHandlers):
37653773
"""Provider-side of the OpenSearch relation."""

lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ def _remove_stale_otel_sdk_packages():
313313

314314
import opentelemetry
315315
import ops
316-
from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import (
316+
from opentelemetry.exporter.otlp.proto.common._internal.trace_encoder import ( # type: ignore
317317
encode_spans # type: ignore
318318
)
319-
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
319+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter # type: ignore
320320
from opentelemetry.sdk.resources import Resource
321321
from opentelemetry.sdk.trace import ReadableSpan, Span, TracerProvider
322322
from opentelemetry.sdk.trace.export import (
@@ -348,7 +348,7 @@ def _remove_stale_otel_sdk_packages():
348348
# Increment this PATCH version before using `charmcraft publish-lib` or reset
349349
# to 0 if you are raising the major API version
350350

351-
LIBPATCH = 8
351+
LIBPATCH = 9
352352

353353
PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"]
354354

src/charm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,8 @@ def _was_restore_successful(self) -> bool:
19611961
logger.debug("Restore check early exit: can't get current wal timeline")
19621962
return False
19631963

1964+
self.enable_disable_extensions()
1965+
19641966
# Remove the restoring backup flag and the restore stanza name.
19651967
self.app_peer_data.update({
19661968
"restoring-backup": "",

tests/unit/test_charm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ def test_on_update_status_after_restore_operation(harness):
908908
patch("charm.PostgresqlOperatorCharm.update_config") as _update_config,
909909
patch("charm.Patroni.member_started", new_callable=PropertyMock) as _member_started,
910910
patch("charm.Patroni.get_member_status") as _get_member_status,
911+
patch(
912+
"charm.PostgresqlOperatorCharm.enable_disable_extensions"
913+
) as _enable_disable_extensions,
911914
):
912915
_get_current_timeline.return_value = "2"
913916
rel_id = harness.model.get_relation(PEER).id
@@ -926,6 +929,7 @@ def test_on_update_status_after_restore_operation(harness):
926929
_oversee_users.assert_not_called()
927930
_update_relation_endpoints.assert_not_called()
928931
_set_primary_status_message.assert_not_called()
932+
_enable_disable_extensions.assert_not_called()
929933
assert isinstance(harness.charm.unit.status, BlockedStatus)
930934

931935
# Test when the restore operation hasn't finished yet.
@@ -938,6 +942,7 @@ def test_on_update_status_after_restore_operation(harness):
938942
_oversee_users.assert_not_called()
939943
_update_relation_endpoints.assert_not_called()
940944
_set_primary_status_message.assert_not_called()
945+
_enable_disable_extensions.assert_not_called()
941946
assert isinstance(harness.charm.unit.status, ActiveStatus)
942947

943948
# Assert that the backup id is still in the application relation databag.
@@ -956,6 +961,7 @@ def test_on_update_status_after_restore_operation(harness):
956961
_oversee_users.assert_called_once()
957962
_update_relation_endpoints.assert_called_once()
958963
_set_primary_status_message.assert_called_once()
964+
_enable_disable_extensions.assert_called_once_with()
959965
assert isinstance(harness.charm.unit.status, ActiveStatus)
960966

961967
# Assert that the backup id is not in the application relation databag anymore.

0 commit comments

Comments
 (0)