ci: Simplify LAVA farm detection

Refactor the LAVA farm detection to use a simpler environment
variable-based approach:
- Remove the complex regex-based farm detection
- Replace LavaFarm enum with a simple string-based farm identification
- Update related tests and job definition logic
- Remove hypothesis testing dependency

Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33888>
This commit is contained in:
Guilherme Gallo 2025-03-04 20:16:56 -03:00 committed by Marge Bot
parent 4a2717c4bd
commit 47659ddf70
8 changed files with 18 additions and 76 deletions

View file

@ -43,7 +43,7 @@ variables:
KERNEL_ROOTFS_TAG: "20250305-vkcts-main"
DEBIAN_PYUTILS_IMAGE: "debian/x86_64_pyutils"
DEBIAN_PYUTILS_TAG: "20250129-lavacli"
DEBIAN_PYUTILS_TAG: "20250303-hypothesis"
ALPINE_X86_64_BUILD_TAG: "20250223-way-prot"
ALPINE_X86_64_LAVA_SSH_TAG: "20250124-spirv-tools"

View file

@ -1,35 +1,16 @@
import logging
import os
import re
from enum import Enum
class LavaFarm(Enum):
"""Enum class representing the different LAVA farms."""
LIMA = 1
COLLABORA = 2
VMWARE = 3
UNKNOWN = 4
LAVA_FARM_RUNNER_PATTERNS: dict[LavaFarm, str] = {
# Lima and VMware patterns come first, since they have the same prefix as the Collabora pattern.
LavaFarm.LIMA: r"^mesa-ci-[\x01-\x7F]+-lava-lima$",
LavaFarm.VMWARE: r"^mesa-ci-[\x01-\x7F]+-lava-vmware$",
LavaFarm.COLLABORA: r"^mesa-ci-[\x01-\x7F]+-lava-[\x01-\x7F]+$",
LavaFarm.UNKNOWN: r"^[\x01-\x7F]+",
}
def get_lava_farm() -> LavaFarm:
def get_lava_farm() -> str:
"""
Returns the LAVA farm based on the RUNNER_TAG environment variable.
Returns the LAVA farm based on the FARM environment variable.
:return: The LAVA farm
"""
runner_tag: str = os.getenv("RUNNER_TAG", "unknown")
farm: str = os.getenv("FARM", "unknown")
for farm, pattern in LAVA_FARM_RUNNER_PATTERNS.items():
if re.match(pattern, runner_tag):
return farm
if farm == "unknown":
logging.warning("FARM environment variable is not set, using unknown")
raise ValueError(f"Unknown LAVA runner tag: {runner_tag}")
return farm.lower()

View file

@ -3,9 +3,9 @@ from typing import TYPE_CHECKING, Any
from ruamel.yaml import YAML
from os import environ, getenv
from os import getenv
from lava.utils.lava_farm import LavaFarm, get_lava_farm
from lava.utils.lava_farm import get_lava_farm
from lava.utils.ssh_job_definition import (
generate_docker_test,
generate_dut_test,
@ -52,7 +52,7 @@ class LAVAJobDefinition:
# which is required to follow the job in a SSH section
current_farm = get_lava_farm()
return current_farm == LavaFarm.COLLABORA
return current_farm == "collabora"
def generate_lava_yaml_payload(self) -> dict[str, Any]:
"""

View file

@ -20,7 +20,7 @@ from typing import Optional, Union
from lava.exceptions import MesaCITimeoutError
from lava.utils.console_format import CONSOLE_LOG
from lava.utils.gitlab_section import GitlabSection
from lava.utils.lava_farm import LavaFarm, get_lava_farm
from lava.utils.lava_farm import get_lava_farm
from lava.utils.lava_log_hints import LAVALogHints
from lava.utils.log_section import (
DEFAULT_GITLAB_SECTION_TIMEOUTS,
@ -43,7 +43,7 @@ class LogFollower:
fallback_timeout: timedelta = FALLBACK_GITLAB_SECTION_TIMEOUT
_buffer: list[str] = field(default_factory=list, init=False)
log_hints: LAVALogHints = field(init=False)
lava_farm: LavaFarm = field(init=False, default=get_lava_farm())
lava_farm: str = field(init=False, default=get_lava_farm())
_merge_next_line: str = field(default_factory=str, init=False)
def __post_init__(self):
@ -261,7 +261,7 @@ class LogFollower:
elif line["lvl"] == "input":
prefix = "$ "
suffix = ""
elif line["lvl"] == "target" and self.lava_farm != LavaFarm.COLLABORA:
elif line["lvl"] == "target" and self.lava_farm != "collabora":
# gl_section_fix_gen will output the stored line if it can't find a
# match for the first split line
# So we can recover it and put it back to the buffer

View file

@ -4,12 +4,9 @@ from unittest.mock import MagicMock, patch
import pytest
import yaml
from freezegun import freeze_time
from hypothesis import settings
from .lava.helpers import generate_testsuite_result, jobs_logs_response
settings.register_profile("ci", max_examples=1000, derandomize=True)
settings.load_profile("ci")
def pytest_configure(config):
config.addinivalue_line(

View file

@ -1,41 +1,6 @@
import re
import pytest
from hypothesis import given
from hypothesis import strategies as st
from lava.utils.lava_farm import LAVA_FARM_RUNNER_PATTERNS, LavaFarm, get_lava_farm
@given(
runner_tag=st.text(
alphabet=st.characters(
min_codepoint=1, max_codepoint=127, blacklist_categories=("C",)
),
min_size=1,
)
)
def test_get_lava_farm_invalid_tags(runner_tag):
with pytest.MonkeyPatch().context() as mp:
mp.setenv("RUNNER_TAG", runner_tag)
assert get_lava_farm() == LavaFarm.UNKNOWN
from lava.utils.lava_farm import get_lava_farm
def test_get_lava_farm_no_tag(monkeypatch):
monkeypatch.delenv("RUNNER_TAG", raising=False)
assert get_lava_farm() == LavaFarm.UNKNOWN
@given(
st.fixed_dictionaries(
{k: st.from_regex(v) for k, v in LAVA_FARM_RUNNER_PATTERNS.items()}
)
)
def test_get_lava_farm_valid_tags(runner_farm_tag: dict):
with pytest.MonkeyPatch().context() as mp:
for farm, tag in runner_farm_tag.items():
try:
mp.setenv("RUNNER_TAG", tag)
except ValueError:
# hypothesis may generate null bytes in the string
continue
assert get_lava_farm() == farm
monkeypatch.delenv("FARM", raising=False)
assert get_lava_farm() == "unknown"

View file

@ -83,7 +83,7 @@ def clear_env_vars(autouse=True):
@pytest.fixture
def mock_collabora_farm(clear_env_vars, monkeypatch):
# Mock a Collabora farm-like device runner tag to enable SSH execution
monkeypatch.setenv("RUNNER_TAG", "mesa-ci-1234-lava-collabora")
monkeypatch.setenv("FARM", "collabora")
@pytest.mark.parametrize("force_uart", [True, False], ids=["SSH", "UART"])

View file

@ -2,7 +2,6 @@
filelock==3.12.4
fire==0.5.0
freezegun==1.5.1
hypothesis==6.67.1
mock==5.1.0
polars==0.19.3
pytest==7.4.2