Skip to content

Commit

Permalink
use similar approar as bots, clone the testinspector inside
Browse files Browse the repository at this point in the history
  • Loading branch information
jscotka committed Jan 31, 2024
1 parent 3e3fc92 commit f64dd64
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
4 changes: 3 additions & 1 deletion test/common/pywrap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ top_srcdir="${realpath%/*}/../.."

# Check out the bots if required
test -d "${top_srcdir}/bots" || "${top_srcdir}/test/common/make-bots"
# Check out the test inspector if required
test -d "$(dirname $realpath)/testinsp" || "$(dirname $realpath)/make-testinsp"

# Prepend the path
PYTHONPATH="${top_srcdir}/test/common:${top_srcdir}/bots:${top_srcdir}/bots/machine${PYTHONPATH:+:${PYTHONPATH}}"
PYTHONPATH="${top_srcdir}/test/common/testinsp:${top_srcdir}/test/common:${top_srcdir}/bots:${top_srcdir}/bots/machine${PYTHONPATH:+:${PYTHONPATH}}"
export PYTHONPATH

# Run the script
Expand Down
11 changes: 11 additions & 0 deletions test/common/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,18 @@ class Test:
for line in lines[:-1]:
if line.startswith(b"WARNING:"):
write_line(line)
# print test inspector log
ti_start = False
for line in lines:
if b"RESULTS OF TEST INSPECTOR" in line:
ti_start = True
continue
if b"END OF TEST INSPECTOR" in line:
break
if ti_start:
write_line(b"WARNING: TI -> " + line)
write_line(lines[-1])

else:
for line in lines:
write_line(line)
Expand Down
44 changes: 25 additions & 19 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
import unittest
from time import sleep
from typing import Any, Callable, Dict, List, Optional, Union
from pprint import pprint

import cdp
import testvm
from lcov import write_lcov
from lib.constants import OSTREE_IMAGES
from testinsp import RunChecks

try:
from PIL import Image
Expand Down Expand Up @@ -1508,6 +1510,29 @@ def nonDestructiveSetup(self):

m = self.machine

# run TestInspector as last cleanup action
def test_inspector_check():
print(" ---------- RESULTS OF TEST INSPECTOR ---------- ")
inspected_data = self.test_inspecor.check()
for k, v in inspected_data.items():
if v:
pprint(f">> Test Inspector FAIL - ({k}):")
pprint(v)
print(" ---------- END OF TEST INSPECTOR ---------- ")
exclude_dict=dict()
exclude_dict["ListEtcDir"] = ["/etc/systemd/system/cockpit.service.d/notls.conf"]
exclude_dict["ServiceInfo"] = ["cockpit",
"user@",
"packagekit",
"rhsm",
"realmd",
"systemd-timedated",
"systemd-hostnamed",
"systemd-logind.service"]
self.test_inspecor = RunChecks(external_executor=m.execute, exclude_dict=exclude_dict)
self.test_inspecor.init()
self.addCleanup(test_inspector_check)

# helps with mapping journal output to particular tests
name = "%s.%s" % (self.__class__.__name__, self._testMethodName)
m.execute("logger -p user.info 'COCKPITTEST: start %s'" % name)
Expand Down Expand Up @@ -1607,24 +1632,6 @@ def terminate_sessions():
"for f in *; do [ $f -le 500 ] || rm $f; done")

self.addCleanup(terminate_sessions)
if opts.testinspector:
from testinsp import RunChecks
from pprint import pprint
def test_inspector_check():
print(" ---------- RESULT OF TEST INSPECTOR ---------- ")
inspected_data = self.test_inspecor.check()
for k, v in inspected_data.items():
if v:
pprint(f">> TI FAIL ({k}):")
pprint(v)
else:
pprint(f">> TI PASS ({k}):")
exclude_dict=dict()
exclude_dict["ListEtcDir"] = ["/etc/systemd/system/cockpit.service.d/notls.conf"]
exclude_dict["ServiceInfo"] = ["cockpit", "user@", "packagekit", "rhsm", "realmd", "systemd-timedated", "systemd-hostnamed"]
self.test_inspecor = RunChecks(external_executor=m.execute, exclude_dict=exclude_dict)
self.test_inspecor.init()
self.addCleanup(test_inspector_check)

def tearDown(self):
error = self.getError()
Expand Down Expand Up @@ -2508,7 +2515,6 @@ def arg_parser(enable_sit=True):
parser.add_argument('--coverage', action='store_true',
help="Collect code coverage data")
parser.add_argument("-l", "--list", action="store_true", help="Print the list of tests that would be executed")
parser.add_argument("--testinspector", action="store_true", help="Run test inspector for nondestructive tests (install https://github.com/jscotka/testinsp/)")
# TMT compatibility, pass testnames as whitespace separated list
parser.add_argument('tests', nargs='*', default=os.getenv("TEST_NAMES").split() if os.getenv("TEST_NAMES") else [])

Expand Down

0 comments on commit f64dd64

Please sign in to comment.