Skip to content

Commit 0d5cea0

Browse files
committed
Fix mypy: narrow scenario type via get_library_init_image() helper
context.scenario is typed as the base Scenario; access the init image through a helper that asserts isinstance(K8sScenario) (mirrors get_cluster_info's narrowing).
1 parent d887e80 commit 0d5cea0

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

tests/k8s_lib_injection/test_k8s_lib_injection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from utils import scenarios, features, context, bug, logger
2-
from tests.k8s_lib_injection.utils import get_dev_agent_traces, get_cluster_info, run_https_probe_pod
2+
from tests.k8s_lib_injection.utils import (
3+
get_dev_agent_traces,
4+
get_cluster_info,
5+
get_library_init_image,
6+
run_https_probe_pod,
7+
)
38
from utils.onboarding.weblog_interface import make_get_request, warmup_weblog
49
from utils.onboarding.backend_interface import wait_backend_trace_id
510
from utils.onboarding.wait_for_tcp_port import wait_for_port
@@ -27,7 +32,7 @@ def test_k8s_init_container_https_egress(self):
2732
pod from the init image doing `curl -fsS https://...` (verification on) and asserts it
2833
succeeds; a missing or broken cert store makes curl exit non-zero.
2934
"""
30-
image = context.scenario.test_weblog.library_init_image
35+
image = get_library_init_image()
3136
phase, logs = run_https_probe_pod(get_cluster_info(), image, "https://app.datadoghq.com")
3237
if phase != "Succeeded":
3338
logger.error(f"[HTTPS probe] init image {image} failed HTTPS egress; pod logs:\n{logs}")

tests/k8s_lib_injection/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from utils import logger, context
77
from utils.k8s_lib_injection.k8s_cluster_provider import K8sClusterInfo
8-
from utils._context._scenarios.k8s_lib_injection import K8sScenarioWithClusterProvider
8+
from utils._context._scenarios.k8s_lib_injection import K8sScenario, K8sScenarioWithClusterProvider
99

1010

1111
def get_dev_agent_traces(k8s_cluster_info: K8sClusterInfo, retry: int = 10) -> list:
@@ -28,6 +28,13 @@ def get_cluster_info() -> K8sClusterInfo:
2828
return context.scenario.k8s_cluster_provider.get_cluster_info()
2929

3030

31+
def get_library_init_image() -> str:
32+
"""Return the init image under test (the image the scenario deploys as the init container)."""
33+
assert isinstance(context.scenario, K8sScenario)
34+
35+
return context.scenario.test_weblog.library_init_image
36+
37+
3138
def run_https_probe_pod(
3239
k8s_cluster_info: K8sClusterInfo, image: str, url: str, *, namespace: str = "default", timeout: int = 120
3340
) -> tuple[str | None, str]:

0 commit comments

Comments
 (0)