Skip to content

Commit 2d2f284

Browse files
committedDec 5, 2023
testing: vmcore: Stop printing logs
The gitlab tests have reached their limit of log size (500K). It's very difficult to look through the tests and see what failed. Rectify this by logging test data to the JUnit XML format. Produces a combined log for all vmcore tests. You can pretty easily browse the output in less (though it is XML formatted). Gitlab will also understand the logs! In the process, I've also ensured that vmcore tests always run to completion (something they didn't do before), and that the end of the test log contains a brief summary of the vmcores which succeeded and failed. Signed-off-by: Stephen Brennan <[email protected]>
1 parent 1fe97b5 commit 2d2f284

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ deploy_dev.sh
1212
drgntools-fio.dat
1313
testdata
1414
test.log
15+
vmcore.xml

‎.gitlab-ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ vmtest:
66
- tox -e runner -- python -m testing.vmcore test --core-directory /var/drgn-tools/vmcores
77
- mkdir -p tmp/overlays tmp/info
88
- tox -e runner -- python -m testing.heavyvm.runner --image-dir /var/drgn-tools/images --vm-info-dir tmp/info --overlay-dir tmp/overlays --tarball archive.tar.gz
9+
artifacts:
10+
reports:
11+
junit: vmcore.xml

‎testing/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ oci-cli
44
paramiko
55
rich
66
types-paramiko
7+
junitparser==3.1.0

‎testing/vmcore.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Tuple
1919

2020
import oci.config
21+
from junitparser import JUnitXml
2122
from oci.exceptions import ConfigFileNotFound
2223
from oci.object_storage import ObjectStorageClient
2324
from oci.object_storage import UploadManager
@@ -247,6 +248,11 @@ def should_run_vmcore(name: str) -> bool:
247248
return True
248249
return False
249250

251+
failed = []
252+
passed = []
253+
xml = JUnitXml()
254+
xml_run = Path("test.xml")
255+
250256
for path in CORE_DIR.iterdir():
251257
core_name = path.name
252258
if not should_run_vmcore(core_name):
@@ -256,17 +262,37 @@ def should_run_vmcore(name: str) -> bool:
256262
f"Running tests on vmcore {core_name}",
257263
collapsed=True,
258264
):
259-
subprocess.run(
265+
if xml_run.exists():
266+
xml_run.unlink()
267+
res = subprocess.run(
260268
[
261269
"tox",
262270
"--",
263271
"--vmcore",
264272
core_name,
265273
"--vmcore-dir",
266274
str(CORE_DIR),
275+
"--junitxml=test.xml",
276+
"-o",
277+
"junit_logging=all",
267278
],
268-
check=True,
269279
)
280+
run_data = JUnitXml.fromfile(str(xml_run))
281+
xml += run_data
282+
if res.returncode != 0:
283+
failed.append(core_name)
284+
else:
285+
passed.append(core_name)
286+
287+
xml_run.unlink()
288+
xml.write("vmcore.xml")
289+
print("Complete test logs: vmcore.xml")
290+
print("Vmcore Test Summary -- Passed:")
291+
print("\n".join(f"- {n}" for n in passed))
292+
if failed:
293+
print("Vmcore Test Summary -- FAILED:")
294+
print("\n".join(f"- {n}" for n in failed))
295+
sys.exit(1)
270296

271297

272298
def get_client() -> ObjectStorageClient:

‎tests/conftest.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2023, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
import sys
34
from fnmatch import fnmatch
45
from pathlib import Path
56
from typing import List
@@ -37,6 +38,16 @@ def prog_type() -> str:
3738
return "live"
3839

3940

41+
@pytest.fixture(scope="session", autouse=True)
42+
def log_global_env_facts(prog, record_testsuite_property):
43+
if VMCORE:
44+
record_testsuite_property("target", VMCORE_NAME)
45+
else:
46+
record_testsuite_property("target", "live")
47+
release = prog["UTS_RELEASE"].string_().decode("utf-8")
48+
record_testsuite_property("release", release)
49+
50+
4051
def pytest_addoption(parser):
4152
parser.addoption(
4253
"--vmcore",
@@ -104,6 +115,13 @@ def pytest_configure(config):
104115
for module in vmcore_dir.glob("*.ko.debug"):
105116
DEBUGINFO.append(module)
106117

118+
config.inicfg["junit_suite_name"] = "Python {}.{}.{} - {}".format(
119+
sys.version_info.major,
120+
sys.version_info.minor,
121+
sys.version_info.micro,
122+
f"vmcore {vmcore}" if vmcore else "live",
123+
)
124+
107125

108126
def pytest_runtest_setup(item: pytest.Item):
109127
skip_live = False

‎tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ deps =
1010
-rrequirements-dev.txt
1111
pytest-cov
1212
commands =
13-
python -m pytest --cov=drgn_tools --cov=tests -rP {posargs}
13+
python -m pytest --cov=drgn_tools --cov=tests --junitxml=test.xml -o junit_logging=all {posargs}
1414
passenv = DRGNTOOLS_*, GITLAB_CI, GITHUB_ACTIONS
1515

1616
[testenv:docs]

0 commit comments

Comments
 (0)
Please sign in to comment.