ci/lava: Fix LAVA logs issues for Collabora jobs
Since the Collabora LAVA update related to the downtime from https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21119, the LAVA logs from Collabora continued to use the hack for older versions which digested some control characters, such as carriage returns acting as newlines, which made it necessary to recover from split lines to make Gitlab sections work in job logs as expected. Collabora's LAVA instance now gives a more raw log output. It is necessary to pay attention to newlines at the end of each log message, which may cause double newlines when printed with Python built-in `print` function. I decided to remove the repeating `\n` from the received log messages to make them transparent to LogFollower users. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8242 Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21325>
This commit is contained in:
committed by
Marge Bot
parent
c85f3fbbb7
commit
eba566c854
@@ -20,6 +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_log_hints import LAVALogHints
|
||||
from lava.utils.log_section import (
|
||||
DEFAULT_GITLAB_SECTION_TIMEOUTS,
|
||||
@@ -38,6 +39,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())
|
||||
|
||||
def __post_init__(self):
|
||||
section_is_created = bool(self.current_section)
|
||||
@@ -124,6 +126,17 @@ class LogFollower:
|
||||
|
||||
return False
|
||||
|
||||
def remove_trailing_whitespace(self, line: dict[str, str]) -> None:
|
||||
msg: Optional[str] = line.get("msg")
|
||||
if not msg:
|
||||
return
|
||||
|
||||
messages = [msg] if isinstance(msg, str) else msg
|
||||
|
||||
for message in messages:
|
||||
# LAVA logs brings raw messages, which includes newlines characters.
|
||||
line["msg"]: str = message.rstrip("\n")
|
||||
|
||||
def feed(self, new_lines: list[dict[str, str]]) -> bool:
|
||||
"""Input data to be processed by LogFollower instance
|
||||
Returns true if the DUT (device under test) seems to be alive.
|
||||
@@ -135,6 +148,8 @@ class LogFollower:
|
||||
is_job_healthy = False
|
||||
|
||||
for line in new_lines:
|
||||
self.remove_trailing_whitespace(line)
|
||||
|
||||
if self.detect_kernel_dump_line(line):
|
||||
continue
|
||||
|
||||
@@ -166,7 +181,7 @@ class LogFollower:
|
||||
elif line["lvl"] == "input":
|
||||
prefix = "$ "
|
||||
suffix = ""
|
||||
elif line["lvl"] == "target":
|
||||
elif line["lvl"] == "target" and self.lava_farm != LavaFarm.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
|
||||
@@ -211,7 +226,7 @@ def fix_lava_gitlab_section_log():
|
||||
|
||||
|
||||
|
||||
def print_log(msg):
|
||||
def print_log(msg: str) -> None:
|
||||
# Reset color from timestamp, since `msg` can tint the terminal color
|
||||
print(f"{CONSOLE_LOG['RESET']}{datetime.now()}: {msg}")
|
||||
|
||||
|
||||
@@ -201,6 +201,22 @@ def test_fix_lava_gitlab_section_log(expected_message, messages):
|
||||
assert expected_message in fixed_messages
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"expected_message, messages",
|
||||
GITLAB_SECTION_SPLIT_SCENARIOS.values(),
|
||||
ids=GITLAB_SECTION_SPLIT_SCENARIOS.keys(),
|
||||
)
|
||||
def test_lava_gitlab_section_log_collabora(expected_message, messages, monkeypatch):
|
||||
"""Check if LogFollower does not change the message if we are running in Collabora farm."""
|
||||
monkeypatch.setenv("RUNNER_TAG", "mesa-ci-x86_64-lava-test")
|
||||
lf = LogFollower()
|
||||
for message in messages:
|
||||
lf.feed([create_lava_yaml_msg(msg=message)])
|
||||
new_messages = lf.flush()
|
||||
new_messages = tuple(new_messages) if len(new_messages) > 1 else new_messages[0]
|
||||
assert new_messages == expected_message
|
||||
|
||||
|
||||
WATCHDOG_SCENARIOS = {
|
||||
"1 second before timeout": ({"seconds": -1}, does_not_raise()),
|
||||
"1 second after timeout": ({"seconds": 1}, pytest.raises(MesaCITimeoutError)),
|
||||
|
||||
Reference in New Issue
Block a user