report: Add trial commit info to junit file
Change-Id: I997bbbeb3807af5cd927594a4155b824f0c6d03d
diff --git a/src/osmo_gsm_tester/core/report.py b/src/osmo_gsm_tester/core/report.py
index 121fbaf..5014bf5 100644
--- a/src/osmo_gsm_tester/core/report.py
+++ b/src/osmo_gsm_tester/core/report.py
@@ -46,6 +46,14 @@
replacement_char = '\uFFFD' # Unicode replacement character
return invalid_xml_char_ranges_regex.sub(replacement_char, escape(str))
+def hash_info_to_junit(testsuite, hash_info):
+ properties = et.SubElement(testsuite, 'properties')
+ for key, val in hash_info.items():
+ prop = et.SubElement(properties, 'property')
+ prop.set('name', 'ref:' + key)
+ prop.set('value', val)
+
+
def trial_to_junit_write(trial, junit_path):
elements = et.ElementTree(element=trial_to_junit(trial))
elements.write(junit_path)
@@ -57,8 +65,10 @@
num_errors = 0
time = 0
id = 0
+ hash_info = trial.get_all_inst_hash_info()
for suite in trial.suites:
testsuite = suite_to_junit(suite)
+ hash_info_to_junit(testsuite, hash_info)
testsuite.set('id', str(id))
id += 1
testsuites.append(testsuite)
diff --git a/src/osmo_gsm_tester/core/trial.py b/src/osmo_gsm_tester/core/trial.py
index eaf18c3..001421f 100644
--- a/src/osmo_gsm_tester/core/trial.py
+++ b/src/osmo_gsm_tester/core/trial.py
@@ -21,6 +21,7 @@
import time
import shutil
import tarfile
+import pathlib
from . import log
from . import util
@@ -212,6 +213,22 @@
self.log('Storing JUnit report in', junit_path)
report.trial_to_junit_write(self, junit_path)
+ def get_all_inst_hash_info(self):
+ d = {}
+ pathlist = pathlib.Path(str(self.inst_dir)).glob('**/*git_hashes.txt')
+ for path in pathlist:
+ # because path is object not string
+ abs_path_str = str(path) # because path is object not string
+ dir, file = os.path.split(abs_path_str)
+ reldir = os.path.relpath(dir, str(self.inst_dir)).rstrip(os.sep)
+ with open(abs_path_str, 'r') as f:
+ for line in [l.strip() for l in f.readlines()]:
+ if not line:
+ continue
+ hash, proj = tuple(line.split(' ', 1))
+ d[os.path.join(reldir,proj)] = hash
+ return d
+
def log_report(self):
log.large_separator(self.name(), self.status)
self.log(report.trial_to_text(self))