Skip to content

Commit 2c0f64b

Browse files
authored
[MISC] Handle on start secret exception and remove stale test (#550)
* Handle on start secret exception and remove stale test * Bump libs
1 parent f24a48a commit 2c0f64b

File tree

4 files changed

+21
-61
lines changed

4 files changed

+21
-61
lines changed

lib/charms/tempo_k8s/v2/tracing.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(self, *args):
107107

108108
# Increment this PATCH version before using `charmcraft publish-lib` or reset
109109
# to 0 if you are raising the major API version
110-
LIBPATCH = 7
110+
LIBPATCH = 8
111111

112112
PYDEPS = ["pydantic"]
113113

@@ -116,14 +116,13 @@ def __init__(self, *args):
116116
DEFAULT_RELATION_NAME = "tracing"
117117
RELATION_INTERFACE_NAME = "tracing"
118118

119+
# Supported list rationale https://github.com/canonical/tempo-coordinator-k8s-operator/issues/8
119120
ReceiverProtocol = Literal[
120121
"zipkin",
121-
"kafka",
122-
"opencensus",
123-
"tempo_http",
124-
"tempo_grpc",
125122
"otlp_grpc",
126123
"otlp_http",
124+
"jaeger_grpc",
125+
"jaeger_thrift_http",
127126
]
128127

129128
RawReceiver = Tuple[ReceiverProtocol, str]
@@ -141,14 +140,12 @@ class TransportProtocolType(str, enum.Enum):
141140
grpc = "grpc"
142141

143142

144-
receiver_protocol_to_transport_protocol = {
143+
receiver_protocol_to_transport_protocol: Dict[ReceiverProtocol, TransportProtocolType] = {
145144
"zipkin": TransportProtocolType.http,
146-
"kafka": TransportProtocolType.http,
147-
"opencensus": TransportProtocolType.http,
148-
"tempo_http": TransportProtocolType.http,
149-
"tempo_grpc": TransportProtocolType.grpc,
150145
"otlp_grpc": TransportProtocolType.grpc,
151146
"otlp_http": TransportProtocolType.http,
147+
"jaeger_thrift_http": TransportProtocolType.http,
148+
"jaeger_grpc": TransportProtocolType.grpc,
152149
}
153150
"""A mapping between telemetry protocols and their corresponding transport protocol.
154151
"""

src/charm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,11 @@ def _on_start(self, event: StartEvent) -> None:
10631063
if not self._can_start(event):
10641064
return
10651065

1066-
postgres_password = self._get_password()
1066+
try:
1067+
postgres_password = self._get_password()
1068+
except ModelError:
1069+
logger.debug("_on_start: secrets not yet available")
1070+
postgres_password = None
10671071
# If the leader was not elected (and the needed passwords were not generated yet),
10681072
# the cluster cannot be bootstrapped yet.
10691073
if not postgres_password or not self._replication_password:

tests/integration/test_tls.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Copyright 2022 Canonical Ltd.
33
# See LICENSE file for licensing details.
44
import logging
5-
import os
65

76
import pytest as pytest
87
from pytest_operator.plugin import OpsTest
@@ -25,7 +24,6 @@
2524
get_primary,
2625
get_unit_address,
2726
primary_changed,
28-
restart_machine,
2927
run_command_on_unit,
3028
)
3129
from .juju_ import juju_major_version
@@ -188,50 +186,3 @@ async def test_tls_enabled(ops_test: OpsTest) -> None:
188186
for unit in ops_test.model.applications[DATABASE_APP_NAME].units:
189187
assert await check_tls(ops_test, unit.name, enabled=False)
190188
assert await check_tls_patroni_api(ops_test, unit.name, enabled=False)
191-
192-
193-
@pytest.mark.group(1)
194-
@pytest.mark.skipif(
195-
not os.environ.get("RESTART_MACHINE_TEST"),
196-
reason="RESTART_MACHINE_TEST environment variable not set",
197-
)
198-
async def test_restart_machine(ops_test: OpsTest) -> None:
199-
async with ops_test.fast_forward():
200-
# Relate it to the PostgreSQL to enable TLS.
201-
await ops_test.model.relate(DATABASE_APP_NAME, tls_certificates_app_name)
202-
await ops_test.model.wait_for_idle(status="active", timeout=1000)
203-
204-
# Wait for all units enabling TLS.
205-
for unit in ops_test.model.applications[DATABASE_APP_NAME].units:
206-
assert await check_tls(ops_test, unit.name, enabled=True)
207-
assert await check_tls_patroni_api(ops_test, unit.name, enabled=True)
208-
209-
unit_name = "postgresql/0"
210-
issue_found = False
211-
for attempt in Retrying(stop=stop_after_attempt(10)):
212-
with attempt:
213-
# Restart the machine of the unit.
214-
logger.info(f"restarting {unit_name}")
215-
await restart_machine(ops_test, unit_name)
216-
217-
# Check whether the issue happened (the storage wasn't mounted).
218-
logger.info(
219-
f"checking whether storage was mounted - attempt {attempt.retry_state.attempt_number}"
220-
)
221-
result = await run_command_on_unit(ops_test, unit_name, "lsblk")
222-
if "/var/lib/postgresql/data" not in result:
223-
issue_found = True
224-
225-
assert (
226-
issue_found
227-
), "Couldn't reproduce the issue from https://bugs.launchpad.net/juju/+bug/1999758"
228-
229-
# Wait for the unit to be ready again. Some errors in the start hook may happen due
230-
# to rebooting in the middle of a hook.
231-
await ops_test.model.wait_for_idle(status="active", timeout=1000, raise_on_error=False)
232-
233-
# Wait for the unit enabling TLS again.
234-
logger.info(f"checking TLS on {unit_name}")
235-
assert await check_tls(ops_test, "postgresql/0", enabled=True)
236-
logger.info(f"checking TLS on Patroni API from {unit_name}")
237-
assert await check_tls_patroni_api(ops_test, "postgresql/0", enabled=True)

tests/unit/test_charm.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ActiveStatus,
2222
BlockedStatus,
2323
MaintenanceStatus,
24+
ModelError,
2425
RelationDataTypeError,
2526
WaitingStatus,
2627
)
@@ -590,7 +591,7 @@ def test_on_start(harness):
590591
patch("upgrade.PostgreSQLUpgrade.idle", return_value=True) as _idle,
591592
patch(
592593
"charm.PostgresqlOperatorCharm._is_storage_attached",
593-
side_effect=[False, True, True, True, True],
594+
side_effect=[False, True, True, True, True, True],
594595
) as _is_storage_attached,
595596
):
596597
_get_postgresql_version.return_value = "14.0"
@@ -606,7 +607,14 @@ def test_on_start(harness):
606607
_bootstrap_cluster.assert_not_called()
607608
assert isinstance(harness.model.unit.status, WaitingStatus)
608609

610+
# ModelError in get password
611+
_get_password.side_effect = ModelError
612+
harness.charm.on.start.emit()
613+
_bootstrap_cluster.assert_not_called()
614+
assert isinstance(harness.model.unit.status, WaitingStatus)
615+
609616
# Mock the passwords.
617+
_get_password.side_effect = None
610618
_get_password.return_value = "fake-operator-password"
611619
_replication_password.return_value = "fake-replication-password"
612620

0 commit comments

Comments
 (0)