Skip to content

Commit 187a5ef

Browse files
committed
Intermediate: check script outputs partial report
fields uuid, subject, scope need to be added in externally Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 3504a66 commit 187a5ef

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

Tests/iaas/openstack_test.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
SPDX-License-Identifier: CC-BY-SA 4.0
88
"""
99

10+
from datetime import datetime
1011
import getopt
1112
import logging
1213
import os
1314
import sys
1415

1516
import openstack
17+
import yaml
1618

1719
from scs_0100_flavor_naming.flavor_names import compute_flavor_spec
1820
from scs_0100_flavor_naming.flavor_names_check import \
@@ -206,28 +208,24 @@ def add_value(self, name, value):
206208
self._values[name] = value
207209

208210

209-
def harness(name, *check_fns):
211+
def harness(name, results, *check_fns):
210212
"""Harness for evaluating testcase `name`.
211213
212-
Logs beginning of computation.
214+
Logs beginning and end of computation.
213215
Calls each fn in `check_fns`.
214-
Prints (to stdout) 'name: RESULT', where RESULT is one of
215-
216-
- 'ABORT' if an exception occurs during the function calls
217-
- 'FAIL' if one of the functions has a falsy result
218-
- 'PASS' otherwise
216+
Records result to `results`.
219217
"""
220218
logger.info(f'*** {name}')
221219
try:
222220
result = all(check_fn() for check_fn in check_fns)
223221
except BaseException:
224222
logger.debug('exception during check', exc_info=True)
225-
result = 'ABORT'
223+
value = 0
226224
else:
227-
result = ['FAIL', 'PASS'][min(1, result)]
228-
# this is quite redundant
229-
# logger.debug(f'** computation end for {name}')
230-
print(f"{name}: {result}")
225+
value = 1 if result else -1
226+
result = ['FAIL', 'ABORT', 'PASS'][value + 1]
227+
logger.info(f'+++ {name}: {result}')
228+
results[name] = value
231229

232230

233231
def run_preflight_checks(container):
@@ -244,6 +242,15 @@ def run_preflight_checks(container):
244242
raise RuntimeError("OpenStack user is missing member role.")
245243

246244

245+
class _LogHandler(logging.Handler):
246+
def __init__(self, level=logging.NOTSET, log=None):
247+
super().__init__(level=level)
248+
self.log = [] if log is None else log
249+
250+
def handle(self, record):
251+
self.log.append(f'{record.levelname}: {record.msg}')
252+
253+
247254
def main(argv):
248255
# configure logging, disable verbose library logging
249256
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
@@ -287,8 +294,22 @@ def main(argv):
287294
for testcase in testcases:
288295
print(f"{testcase}: ABORT")
289296
raise
297+
298+
results = {}
299+
log = []
300+
logging.root.addHandler(_LogHandler(level=logging.DEBUG, log=log))
290301
for testcase in testcases:
291-
harness(testcase, lambda: getattr(c, testcase.replace('-', '_')))
302+
harness(testcase, results, lambda: getattr(c, testcase.replace('-', '_')))
303+
report = {
304+
'creator': 'openstack_test.py v0.1.0',
305+
'checked_at': datetime.now(),
306+
'tests': {
307+
key: {'result': value}
308+
for key, value in results.items()
309+
},
310+
'log': log,
311+
}
312+
yaml.safe_dump(report, sys.stdout, default_flow_style=False, sort_keys=False, explicit_start=True)
292313
return 0
293314

294315

0 commit comments

Comments
 (0)