Skip to content

Commit 7d2b5fb

Browse files
Stabilize integration tests; avoid using equality for comparison of units and compare unit names instead (#508)
* Avoid using equality for comparison of units and compare unit names instead * Add check for None value for unit_excluded * More deterministically determine if node functional after network restore * Fix lint warnings + update outdated charm libs
1 parent c9dce61 commit 7d2b5fb

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

lib/charms/tempo_k8s/v1/charm_tracing.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ def _remove_stale_otel_sdk_packages():
224224

225225
_remove_stale_otel_sdk_packages()
226226

227-
228227
import functools
229228
import inspect
230229
import logging
@@ -271,7 +270,7 @@ def _remove_stale_otel_sdk_packages():
271270
# Increment this PATCH version before using `charmcraft publish-lib` or reset
272271
# to 0 if you are raising the major API version
273272

274-
LIBPATCH = 14
273+
LIBPATCH = 15
275274

276275
PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"]
277276

@@ -281,7 +280,6 @@ def _remove_stale_otel_sdk_packages():
281280
# set this to 0 if you are debugging/developing this library source
282281
dev_logger.setLevel(logging.CRITICAL)
283282

284-
285283
_CharmType = Type[CharmBase] # the type CharmBase and any subclass thereof
286284
_C = TypeVar("_C", bound=_CharmType)
287285
_T = TypeVar("_T", bound=type)
@@ -333,9 +331,22 @@ def _get_tracer() -> Optional[Tracer]:
333331
try:
334332
return tracer.get()
335333
except LookupError:
334+
# fallback: this course-corrects for a user error where charm_tracing symbols are imported
335+
# from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...)
336336
try:
337337
ctx: Context = copy_context()
338338
if context_tracer := _get_tracer_from_context(ctx):
339+
logger.warning(
340+
"Tracer not found in `tracer` context var. "
341+
"Verify that you're importing all `charm_tracing` symbols from the same module path. \n"
342+
"For example, DO"
343+
": `from charms.lib...charm_tracing import foo, bar`. \n"
344+
"DONT: \n"
345+
" \t - `from charms.lib...charm_tracing import foo` \n"
346+
" \t - `from lib...charm_tracing import bar` \n"
347+
"For more info: https://python-notes.curiousefficiency.org/en/latest/python"
348+
"_concepts/import_traps.html#the-double-import-trap"
349+
)
339350
return context_tracer.get()
340351
else:
341352
return None

tests/integration/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ async def get_primary_unit_wrapper(ops_test: OpsTest, app_name: str, unit_exclud
486486
units = ops_test.model.applications[app_name].units
487487

488488
for unit in units:
489-
if unit == unit_excluded:
489+
if unit_excluded and unit.name == unit_excluded.name:
490490
continue
491491
try:
492492
primary_unit = await get_primary_unit(ops_test, unit, app_name)

tests/integration/high_availability/test_self_healing.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ async def test_network_cut(ops_test: OpsTest, highly_available_cluster, continuo
153153
logger.info(f"Unit {primary_unit.name} it's on machine {primary_hostname} ✅")
154154

155155
primary_unit_ip = await get_unit_ip(ops_test, primary_unit.name)
156+
cluster_admin_password = await get_system_user_password(primary_unit, CLUSTER_ADMIN_USERNAME)
156157

157158
config = {
158159
"username": CLUSTER_ADMIN_USERNAME,
159-
"password": await get_system_user_password(primary_unit, CLUSTER_ADMIN_USERNAME),
160+
"password": cluster_admin_password,
160161
"host": primary_unit_ip,
161162
}
162163

@@ -193,10 +194,22 @@ async def test_network_cut(ops_test: OpsTest, highly_available_cluster, continuo
193194
# ensure continuous writes still incrementing for all units
194195
async with ops_test.fast_forward():
195196
# wait for the unit to be ready
196-
logger.info(f"Waiting for {primary_unit.name} to enter maintenance")
197-
await ops_test.model.block_until(
198-
lambda: primary_unit.workload_status in ["maintenance"], timeout=30 * 60
199-
)
197+
for attempt in Retrying(stop=stop_after_attempt(60), wait=wait_fixed(10)):
198+
with attempt:
199+
new_unit_ip = await get_unit_ip(ops_test, primary_unit.name)
200+
new_unit_config = {
201+
"username": CLUSTER_ADMIN_USERNAME,
202+
"password": cluster_admin_password,
203+
"host": new_unit_ip,
204+
}
205+
206+
logger.debug(
207+
f"Waiting until connection possible after network restore on {new_unit_ip}"
208+
)
209+
assert is_connection_possible(
210+
new_unit_config
211+
), "❌ Connection is not possible after network restore"
212+
200213
logger.info(f"Waiting for {primary_unit.name} to enter active")
201214
await ops_test.model.block_until(
202215
lambda: primary_unit.workload_status == "active", timeout=40 * 60

0 commit comments

Comments
 (0)