diff --git a/pyproject.toml b/pyproject.toml index fad1b990731..46160268fe9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,6 @@ exclude = [ "tests/fuzzer/.*", "tests/test_the_test/.*", "tests/test_telemetry.py", - "tests/test_profiling.py", "tests/appsec/.*", "tests/debugger/.*", "tests/auto_inject/.*", @@ -69,7 +68,6 @@ exclude = [ "tests/k8s_lib_injection/test_k8s_init_image_validator.py", "utils/_context/_scenarios/auto_injection.py", "utils/_context/_scenarios/k8s_lib_injection.py", - "utils/_context/containers.py", "utils/_context/core.py", "utils/_context/virtual_machines.py", "utils/scripts/decode-rc.py", @@ -78,7 +76,6 @@ exclude = [ "utils/onboarding/.*", "utils/otel_validators/validator_trace.py", "utils/proxy/_deserializer.py", - "utils/scripts/compute_impacted_scenario.py", "utils/scripts/merge_gitlab_aws_pipelines.py", "utils/virtual_machine/.*", ] diff --git a/tests/test_profiling.py b/tests/test_profiling.py index d52822faa70..e37e3032b65 100644 --- a/tests/test_profiling.py +++ b/tests/test_profiling.py @@ -17,9 +17,11 @@ class Test_Profile: """Basic testing of profiling""" + _is_set_up = False # used to do the setup only once + @staticmethod def _common_setup(): - if hasattr(Test_Profile, "_is_set_up"): + if Test_Profile._is_set_up: return Test_Profile._is_set_up = True diff --git a/utils/_context/_scenarios/endtoend.py b/utils/_context/_scenarios/endtoend.py index 41d04743c1f..64ee8033ed8 100644 --- a/utils/_context/_scenarios/endtoend.py +++ b/utils/_context/_scenarios/endtoend.py @@ -402,8 +402,6 @@ def configure(self, config): interfaces.library_dotnet_managed.configure(self.host_log_folder, self.replay) for container in self.buddies: - # a little bit of python wizzardry to solve circular import - container.interface = getattr(interfaces, container.name) container.interface.configure(self.host_log_folder, self.replay) library = self.weblog_container.image.labels["system-tests-library"] diff --git a/utils/_context/containers.py b/utils/_context/containers.py index 1846c7b0e8f..67e17ace514 100644 --- a/utils/_context/containers.py +++ b/utils/_context/containers.py @@ -20,6 +20,7 @@ from utils.tools import logger from utils import interfaces from utils.k8s_lib_injection.k8s_weblog import K8sWeblog +from utils.interfaces._library.core import LibraryInterfaceValidator # fake key of length 32 _FAKE_DD_API_KEY = "0123456789abcdef0123456789abcdef" @@ -100,13 +101,13 @@ def __init__( # None: container did not tried to start yet, or hasn't be started for another reason # False: container is not healthy # True: container is healthy - self.healthy = None + self.healthy: bool | None = None self.environment = environment or {} self.kwargs = kwargs self.depends_on: list[TestedContainer] = [] self._starting_lock = RLock() - self._starting_thread = None + self._starting_thread: Thread | None = None self.stdout_interface = stdout_interface def get_image_list(self, library: str, weblog: str) -> list[str]: # noqa: ARG002 @@ -444,7 +445,7 @@ def __init__(self, image_name: str, *, local_image_only: bool): # local_image_only: boolean # True if the image is only available locally and can't be loaded from any hub - self.env = None + self.env: dict[str, str] | None = None self.labels: dict[str, str] = {} self.name = image_name self.local_image_only = local_image_only @@ -557,7 +558,7 @@ def __init__(self, host_log_folder, *, use_proxy=True, environment=None) -> None local_image_only=True, ) - self.agent_version = "" + self.agent_version: str | None = "" def configure(self, replay): super().configure(replay) @@ -611,12 +612,17 @@ def __init__(self, name, image_name, host_log_folder, host_port, trace_agent_por }, ) - self.interface = None _set_aws_auth_environment(self) + @property + def interface(self) -> LibraryInterfaceValidator: + result = getattr(interfaces, self.name) + assert result is not None, "Interface is not set" + return result + class WeblogContainer(TestedContainer): - appsec_rules_file: str + appsec_rules_file: str | None _dd_rc_tuf_root: dict = { "signed": { "_type": "root", @@ -728,7 +734,7 @@ def __init__( base_environment["DD_TRACE_AGENT_PORT"] = self.trace_agent_port else: base_environment["DD_AGENT_HOST"] = "agent" - base_environment["DD_TRACE_AGENT_PORT"] = AgentContainer.apm_receiver_port + base_environment["DD_TRACE_AGENT_PORT"] = str(AgentContainer.apm_receiver_port) # overwrite values with those set in the scenario environment = base_environment | (environment or {}) @@ -759,7 +765,7 @@ def __init__( self.additional_trace_header_tags = additional_trace_header_tags self.weblog_variant = "" - self._library: LibraryVersion = None + self._library: LibraryVersion | None = None @property def trace_agent_port(self): @@ -779,7 +785,7 @@ def _get_image_list_from_dockerfile(dockerfile) -> list[str]: def get_image_list(self, library: str | None, weblog: str | None) -> list[str]: """Parse the Dockerfile and extract all images reference in a FROM section""" - result = [] + result: list[str] = [] if not library or not weblog: return result @@ -822,7 +828,12 @@ def configure(self, replay): if len(self.additional_trace_header_tags) != 0: self.environment["DD_TRACE_HEADER_TAGS"] += f',{",".join(self.additional_trace_header_tags)}' - self.appsec_rules_file = (self.image.env | self.environment).get("DD_APPSEC_RULES", None) + if "DD_APPSEC_RULES" in self.environment: + self.appsec_rules_file = self.environment["DD_APPSEC_RULES"] + elif self.image.env is not None and "DD_APPSEC_RULES" in self.environment: + self.appsec_rules_file = self.image.env["DD_APPSEC_RULES"] + else: + self.appsec_rules_file = None # Workaround: Once the dd-trace-go fix is merged that avoids a go panic for # DD_TRACE_PROPAGATION_EXTRACT_FIRST=true when context propagation fails, @@ -878,10 +889,12 @@ def post_start(self): @property def library(self) -> LibraryVersion: + assert self._library is not None, "Library version is not set" return self._library @property def uds_socket(self): + assert self.image.env is not None, "No env set" return self.image.env.get("DD_APM_RECEIVER_SOCKET", None) @property @@ -1214,7 +1227,7 @@ def __init__(self, host_log_folder) -> None: def get_env(self, env_var): """Get env variables from the container""" - env = self.image.env | self.environment + env = (self.image.env or {}) | self.environment return env.get(env_var) diff --git a/utils/scripts/compute_impacted_scenario.py b/utils/scripts/compute_impacted_scenario.py index 077aa5e6c49..ccc20fecb8b 100644 --- a/utils/scripts/compute_impacted_scenario.py +++ b/utils/scripts/compute_impacted_scenario.py @@ -9,7 +9,7 @@ class Result: def __init__(self) -> None: self.scenarios = {"DEFAULT"} # always run the default scenario - self.scenarios_groups = set() + self.scenarios_groups: set[str] = set() def add_scenario(self, scenario: str) -> None: if scenario == "EndToEndScenario": @@ -20,7 +20,7 @@ def add_scenario(self, scenario: str) -> None: def add_scenario_group(self, scenario_group: str) -> None: self.scenarios_groups.add(scenario_group) - def add_scenarios(self, scenarios: set[str]) -> None: + def add_scenarios(self, scenarios: set[str] | list[str]) -> None: for scenario in scenarios: self.add_scenario(scenario)