1from __future__ import annotations 2 3import re 4from dataclasses import dataclass, field 5from typing import TYPE_CHECKING, Any, Sequence 6 7if TYPE_CHECKING: 8 from lava.utils import LogFollower 9 10from lava.exceptions import MesaCIKnownIssueException 11from lava.utils.console_format import CONSOLE_LOG 12from lava.utils.constants import ( 13 KNOWN_ISSUE_R8152_MAX_CONSECUTIVE_COUNTER, 14 LOG_DEBUG_FEEDBACK_NOISE, 15 KNOWN_ISSUE_R8152_PATTERNS, 16) 17from lava.utils.log_section import LogSectionType 18 19 20def search_known_issue_patterns(patterns: Sequence[str], line: str) -> str: 21 for pattern in patterns: 22 if re.search(pattern, line): 23 return pattern 24 return "" 25 26 27@dataclass 28class LAVALogHints: 29 log_follower: LogFollower 30 r8152_issue_consecutive_counter: int = field(default=0, init=False) 31 reboot_counter: int = field(default=0, init=False) 32 33 def raise_known_issue(self, message) -> None: 34 raise MesaCIKnownIssueException( 35 "Found known issue: " 36 f"{CONSOLE_LOG['FG_MAGENTA']}" 37 f"{message}" 38 f"{CONSOLE_LOG['RESET']}" 39 ) 40 41 def detect_failure(self, new_lines: list[dict[str, Any]]): 42 for line in new_lines: 43 if line["msg"] == LOG_DEBUG_FEEDBACK_NOISE: 44 continue 45 self.detect_r8152_issue(line) 46 self.detect_forced_reboot(line) 47 48 def detect_r8152_issue(self, line): 49 if self.log_follower.phase in ( 50 LogSectionType.LAVA_BOOT, 51 LogSectionType.TEST_CASE, 52 ) and line["lvl"] in ("feedback", "target"): 53 if search_known_issue_patterns(KNOWN_ISSUE_R8152_PATTERNS, line["msg"]): 54 if ( 55 self.r8152_issue_consecutive_counter 56 < KNOWN_ISSUE_R8152_MAX_CONSECUTIVE_COUNTER 57 ): 58 self.r8152_issue_consecutive_counter += 1 59 return 60 61 self.raise_known_issue( 62 "Probable network issue failure encountered, retrying the job" 63 ) 64 65 # Reset the status, as the `nfs... still trying` complaint was not detected 66 self.r8152_issue_consecutive_counter = 0 67 68 def detect_forced_reboot(self, line: dict[str, Any]) -> None: 69 if ( 70 self.log_follower.phase == LogSectionType.TEST_CASE 71 and line["lvl"] == "feedback" 72 ): 73 if re.search(r"^Reboot requested", line["msg"]): 74 self.reboot_counter += 1 75 76 if self.reboot_counter > 0: 77 self.raise_known_issue( 78 "Forced reboot detected during test phase, failing the job..." 79 ) 80