conftest.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import pytest
  2. import subprocess
  3. pkgs = ['389-ds-base', 'nss', 'nspr', 'openldap', 'cyrus-sasl']
  4. def get_rpm_version(pkg):
  5. try:
  6. result = subprocess.check_output(['rpm', '-q', '--queryformat',
  7. '%{VERSION}-%{RELEASE}', pkg])
  8. except:
  9. result = b"not installed"
  10. return result.decode('utf-8')
  11. def is_fips():
  12. # Are we running in FIPS mode?
  13. with open('/proc/sys/crypto/fips_enabled', 'r') as f:
  14. return f.readline()
  15. @pytest.fixture(autouse=True)
  16. def _environment(request):
  17. if "_metadata" in dir(request.config):
  18. for pkg in pkgs:
  19. request.config._metadata[pkg] = get_rpm_version(pkg)
  20. request.config._metadata['FIPS'] = is_fips()
  21. def pytest_report_header(config):
  22. header = ""
  23. for pkg in pkgs:
  24. header += pkg + ": " + get_rpm_version(pkg) + "\n"
  25. header += "FIPS: " + is_fips()
  26. return header
  27. @pytest.mark.optionalhook
  28. def pytest_html_results_table_header(cells):
  29. cells.pop()
  30. @pytest.mark.optionalhook
  31. def pytest_html_results_table_row(report, cells):
  32. cells.pop()