From d41ef935b98811ab715018900b08c9891d3351e6 Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Sep 26 2019 07:59:15 +0000 Subject: Issue 50627 - Add ASAN logs to HTML report Bug Description: ASAN-enabled server generates error logs, it would be nice to collect them and identify tests that caused the error. Fix Description: Add a hook for pytest-html plugin to add logs generated by ASAN to the html report. After test is done, these logs will be rotated. Fixes: https://pagure.io/389-ds-base/issue/50627 Reviewed by: mreynolds (Thanks!) --- diff --git a/dirsrvtests/conftest.py b/dirsrvtests/conftest.py index 70a6d5a..8c0d65f 100644 --- a/dirsrvtests/conftest.py +++ b/dirsrvtests/conftest.py @@ -1,12 +1,15 @@ import subprocess import logging import pytest +import shutil +import glob import os from lib389.paths import Paths from enum import Enum pkgs = ['389-ds-base', 'nss', 'nspr', 'openldap', 'cyrus-sasl'] +p = Paths() class FIPSState(Enum): ENABLED = 'enabled' @@ -62,19 +65,8 @@ def pytest_report_header(config): return header -@pytest.mark.optionalhook -def pytest_html_results_table_header(cells): - cells.pop() - - -@pytest.mark.optionalhook -def pytest_html_results_table_row(report, cells): - cells.pop() - - @pytest.fixture(scope="function", autouse=True) def log_test_name_to_journald(request): - p = Paths() if p.with_systemd: def log_current_test(): subprocess.Popen("echo $PYTEST_CURRENT_TEST | systemd-cat -t pytest", stdin=subprocess.PIPE, shell=True) @@ -82,3 +74,29 @@ def log_test_name_to_journald(request): log_current_test() request.addfinalizer(log_current_test) return log_test_name_to_journald + + +@pytest.fixture(scope="function", autouse=True) +def rotate_xsan_logs(request): + if p.asan_enabled: + xsan_logs_dir = f'{p.run_dir}/bak' + if not os.path.exists(xsan_logs_dir): + os.mkdir(xsan_logs_dir) + else: + for f in glob.glob(f'{p.run_dir}/ns-slapd-*san*'): + shutil.move(f, xsan_logs_dir) + return rotate_xsan_logs + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_makereport(item, call): + pytest_html = item.config.pluginmanager.getplugin('html') + outcome = yield + report = outcome.get_result() + extra = getattr(report, 'extra', []) + if report.when == 'call': + for f in glob.glob(f'{p.run_dir}/ns-slapd-*san*'): + with open(f) as asan_report: + text = asan_report.read() + extra.append(pytest_html.extras.text(text, name=os.path.basename(f))) + report.extra = extra