Find critical pattern in system logs

Signed-off-by: Vladimir Avdeev <v.avdeev@yadro.com>
This commit is contained in:
Vladimir Avdeev 2022-11-15 11:39:07 +03:00
parent 431902c118
commit 72d30c7e06

View file

@ -1,5 +1,6 @@
import logging
import os
import re
import shutil
import uuid
from datetime import datetime
@ -100,6 +101,24 @@ def collect_logs(prepare_tmp_dir, hosting: Hosting):
logs_zip_file_path = shutil.make_archive(logs_dir, "zip", logs_dir)
allure.attach.file(logs_zip_file_path, name="logs.zip", extension="zip")
problem_pattern = r"\Wpanic\W|\Woom\W"
log_file_paths = []
for directory_path, _, file_names in os.walk(logs_dir):
log_file_paths += [
os.path.join(directory_path, file_name)
for file_name in file_names
if re.match(r"\.(txt|log)", os.path.splitext(file_name)[-1], flags=re.IGNORECASE)
]
logs_with_problem = []
for file_path in log_file_paths:
with open(file_path, "r") as log_file:
if re.search(problem_pattern, log_file.read(), flags=re.IGNORECASE):
logs_with_problem.append(file_path)
if logs_with_problem:
raise RuntimeError(f"System logs {', '.join(logs_with_problem)} contain critical errors")
@pytest.fixture(scope="session", autouse=True)
@allure.title("Run health check for all storage nodes")