Skip to content

Commit dcbe423

Browse files
k0machifruch
authored andcommitted
run.py: Introduce metadata files for runs
This commit adds a new file emitted by the matrix runs, intended to provide metadata about the run for reporting tools that are executed later, such as Argus. Currently, the metadata file always contains the driver name (derived from result xml name), type (in this case it's always python), and either failure_reason key (which contains exception stack trace that happened during .run() or path to the resulting junit xml file relative to the metadata file. This commit is part of ongoing task to improve matrix pipeline reporting to Argus. Task: scylladb/argus#289
1 parent 9fc7bec commit dcbe423

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

main.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ def main(arguments: argparse.Namespace):
1919
for driver_version in arguments.versions:
2020
for protocol in arguments.protocols:
2121
logging.info('=== PYTHON DRIVER VERSION %s, PROTOCOL v%s ===', driver_version, protocol)
22-
try:
23-
result = Run(python_driver_git=arguments.python_driver_git,
22+
runner = Run(python_driver_git=arguments.python_driver_git,
2423
python_driver_type=arguments.driver_type,
2524
scylla_install_dir=arguments.scylla_install_dir,
2625
tag=driver_version,
2726
protocol=protocol,
2827
tests=arguments.tests,
2928
scylla_version=arguments.scylla_version,
30-
collect_only=arguments.collect_only).run()
31-
29+
collect_only=arguments.collect_only)
30+
try:
31+
result = runner.run()
3232
logging.info("=== (%s:%s) PYTHON DRIVER MATRIX RESULTS FOR PROTOCOL v%s ===",
3333
arguments.driver_type, driver_version, protocol)
3434
logging.info(", ".join(f"{key}: {value}" for key, value in result.summary.items()))
@@ -43,7 +43,9 @@ def main(arguments: argparse.Namespace):
4343
logging.exception(f"{driver_version} failed")
4444
status = 1
4545
exc_type, exc_value, exc_traceback = sys.exc_info()
46-
results[(driver_version, protocol)] = dict(exception=traceback.format_exception(exc_type, exc_value, exc_traceback))
46+
failure_reason = traceback.format_exception(exc_type, exc_value, exc_traceback)
47+
results[(driver_version, protocol)] = dict(exception=failure_reason)
48+
runner.create_metadata_for_failure(reason="\n".join(failure_reason))
4749

4850
if arguments.recipients:
4951
email_report = create_report(results=results)

run.py

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import os
34
import re
@@ -52,13 +53,25 @@ def version_folder(self) -> Path:
5253
else:
5354
raise ValueError("Not found directory for python-driver version '%s'", self.driver_version)
5455

56+
@cached_property
57+
def xunit_dir(self) -> Path:
58+
return Path(os.path.dirname(__file__)) / "xunit" / self.driver_version
59+
60+
@property
61+
def result_file_name(self) -> str:
62+
return f'pytest.{self._python_driver_type}.v{self._protocol}.{self.driver_version}.xml'
63+
64+
@property
65+
def metadata_file_name(self) -> str:
66+
return f'metadata_{self._python_driver_type}_v{self._protocol}_{self.driver_version}.json'
67+
5568
@cached_property
5669
def xunit_file(self) -> Path:
57-
xunit_dir = Path(os.path.dirname(__file__)) / "xunit" / self.driver_version
58-
if not xunit_dir.exists():
59-
xunit_dir.mkdir(parents=True)
70+
71+
if not self.xunit_dir.exists():
72+
self.xunit_dir.mkdir(parents=True)
6073

61-
file_path = xunit_dir / f'pytest.{self._python_driver_type}.v{self._protocol}.{self.driver_version}.xml'
74+
file_path = self.xunit_dir / self.result_file_name
6275
if file_path.exists():
6376
file_path.unlink()
6477
return file_path
@@ -166,8 +179,24 @@ def _checkout_branch(self):
166179
logging.error("Failed to branch for version '%s', with: '%s'", self.driver_version, str(exc))
167180
return False
168181

182+
def create_metadata_for_failure(self, reason: str) -> None:
183+
metadata_file = self.xunit_dir / self.metadata_file_name
184+
metadata = {
185+
"driver_name": self.result_file_name.replace(".xml", ""),
186+
"driver_type": "python",
187+
"failure_reason": reason,
188+
}
189+
metadata_file.write_text(json.dumps(metadata))
190+
191+
169192
def run(self) -> ProcessJUnit:
170193
junit = ProcessJUnit(self.xunit_file, self.ignore_tests)
194+
metadata_file = self.xunit_dir / self.metadata_file_name
195+
metadata = {
196+
"driver_name": self.result_file_name.replace(".xml", ""),
197+
"driver_type": "python",
198+
"junit_result": f"./{self.xunit_file.name}",
199+
}
171200
logging.info("Changing the current working directory to the '%s' path", self._python_driver_git)
172201
os.chdir(self._python_driver_git)
173202
if self._checkout_branch() and self._apply_patch_files() and self._install_python_requirements():
@@ -180,6 +209,7 @@ def run(self) -> ProcessJUnit:
180209
env=self.environment, cwd=self._python_driver_git)
181210
# clean ccm clusters, for next runs
182211
self._run_command_in_shell("rm -rf tests/integration/ccm | true")
212+
metadata_file.write_text(json.dumps(metadata))
183213
junit.save_after_analysis(driver_version=self.driver_version, protocol=self._protocol,
184214
python_driver_type=self._python_driver_type)
185215
return junit

0 commit comments

Comments
 (0)