#50628 Issue 50627 - Add ASAN logs to HTML report
Closed 3 years ago by spichugi. Opened 4 years ago by vashirov.
vashirov/389-ds-base add_xsan_logs_to_html_report  into  master

file modified
+29 -11
@@ -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 @@ 

      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 @@ 

          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

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: ???

rebased onto d41ef93

4 years ago

Pull-Request has been merged by vashirov

4 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3683

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago
Metadata