fix: logs inspection at the of the test

This commit is contained in:
Roman 2025-03-11 02:38:25 +00:00
parent b1d1518b8b
commit 27f55c3870
No known key found for this signature in database
GPG Key ID: BB3828275C58EFF1
5 changed files with 29 additions and 16 deletions

View File

@ -77,15 +77,18 @@ class NomosCli:
return
def reconstruct(self, decode_only=False):
keywords = ["Reconstructed data"]
keyword = "Reconstructed data"
keywords = [keyword]
log_stream = self._container.logs(stream=True)
matches = self._docker_manager.search_log_for_keywords(self._log_path, keywords, False, log_stream)
assert len(matches) > 0, f"Reconstructed data not found {matches}"
assert len(matches[keyword]) > 0, f"Reconstructed data not found {matches[keyword]}"
logger.debug(f"Reconstructed data match found {matches[keyword]}")
# Use regular expression that captures the byte list after "Reconstructed data"
result = re.sub(r".*Reconstructed data\s*(\[[^\]]+\]).*", r"\1", matches[keywords[0]][0])
result = re.sub(r".*Reconstructed data\s*(\[[^\]]+\]).*", r"\1", matches[keyword][0])
result_bytes = []
try:

View File

@ -142,35 +142,35 @@ class DockerManager:
for keyword in keywords:
if use_regex:
if re.search(keyword, line, re.IGNORECASE):
matches[keyword].append(line.strip())
matches[keyword].append(line)
else:
if keyword.lower() in line.lower():
matches[keyword].append(line.strip())
matches[keyword].append(line)
return matches
def search_log_for_keywords(self, log_path, keywords, use_regex=False, log_stream=None):
matches = {}
matches = {keyword: [] for keyword in keywords}
# Read from stream
if log_stream is not None:
for line in log_stream:
matches = self.find_keywords_in_line(keywords, line.decode("utf-8"), use_regex=use_regex)
line_matches = self.find_keywords_in_line(keywords, line.decode("utf-8"), use_regex=use_regex)
for keyword, result in line_matches.items():
matches[keyword].extend(result)
else:
# Open the log file and search line by line
with open(log_path, "r") as log_file:
for line in log_file:
matches = self.find_keywords_in_line(keywords, line, use_regex=use_regex)
line_matches = self.find_keywords_in_line(keywords, line, use_regex=use_regex)
for keyword, result in line_matches.items():
matches[keyword].extend(result)
# Check if there were any matches
if any(matches[keyword] for keyword in keywords):
for keyword, lines in matches.items():
if lines:
logger.debug(f"Found matches for keyword '{keyword}': {lines}")
if any(matches_list for matches_list in matches.values()):
return matches
else:
logger.debug("No keywords found in the nomos logs.")
return None

View File

@ -142,8 +142,16 @@ class NomosNode:
if whitelist:
keywords = [keyword for keyword in keywords if keyword not in whitelist]
matches = self._docker_manager.search_log_for_keywords(self._log_path, keywords, False)
assert not matches, f"Found errors {matches}"
matches_found = self._docker_manager.search_log_for_keywords(self._log_path, keywords, False)
logger.info(f"Printing log matches for {self.name()}")
if matches_found:
for match in matches_found:
if len(matches_found[match]) != 0:
for log_line in matches_found[match]:
logger.debug(f"Log line matching keyword '{match}': {log_line}")
else:
logger.debug("No keyword matches found in the logs.")
def send_dispersal_request(self, data):
return self._api.send_dispersal_request(data)

View File

@ -23,6 +23,8 @@ LOG_ERROR_KEYWORDS = [
"goexit",
"race condition",
"double free",
"error",
"warn",
]
DATA_TO_DISPERSE = [

View File

@ -97,7 +97,7 @@ def close_open_nodes(attach_logs_on_fail):
@pytest.fixture(scope="function", autouse=True)
def check_nomos_log_errors():
def check_nomos_log_errors(request):
yield
logger.debug(f"Running fixture teardown: {inspect.currentframe().f_code.co_name}")
for node in DS.nomos_nodes: