Skip to content

Commit b726896

Browse files
committed
Implement output of testcase-specific report messages
Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent d579a43 commit b726896

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

Tests/iaas/openstack_test.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ def __init__(self):
232232
def __getattr__(self, key):
233233
val = self._values.get(key)
234234
if val is None:
235-
logger.debug(f'... {key}')
235+
# this is too verbose
236+
# logger.debug(f'... {key}')
236237
try:
237238
ret = self._functions[key](self)
238239
except BaseException as e:
@@ -256,6 +257,27 @@ def add_value(self, name, value):
256257
self._values[name] = value
257258

258259

260+
def _eval_result(result, messages):
261+
"""evaluates `result` from calling a check function
262+
263+
returns 0 if check function succeeded, otherwise 1;
264+
appends to list `messages` if the result contains messages
265+
"""
266+
# either a pair (success, messages)
267+
if isinstance(result, tuple):
268+
success, msgs = result
269+
messages.extend(messages)
270+
return not success
271+
# or just a list of messages
272+
if isinstance(result, list):
273+
if result:
274+
messages.extend(result)
275+
return 1
276+
return 0
277+
# or just a scalar (no messages)
278+
return not result
279+
280+
259281
def harness(name, *check_fns):
260282
"""Harness for evaluating testcase `name`.
261283
@@ -268,15 +290,21 @@ def harness(name, *check_fns):
268290
- 'PASS' otherwise
269291
"""
270292
logger.debug(f'** {name}')
293+
messages = []
271294
try:
272-
result = all(check_fn() for check_fn in check_fns)
295+
results = [check_fn() for check_fn in check_fns]
273296
except BaseException:
274297
logger.debug('exception during check', exc_info=True)
275298
result = 'ABORT'
276299
else:
277-
result = ['FAIL', 'PASS'][min(1, result)]
300+
fails = 0
301+
for r in results:
302+
fails += _eval_result(r, messages)
303+
result = ['FAIL', 'PASS'][fails == 0]
278304
# this is quite redundant
279305
# logger.debug(f'** computation end for {name}')
306+
for msg in messages:
307+
print(f"{name}: {msg}")
280308
print(f"{name}: {result}")
281309

282310

Tests/iaas/scs_0102_image_metadata/image_metadata.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ def is_outdated(img, now=time.time()):
101101

102102
def _log_error(cause, offenders, channel=logging.ERROR):
103103
if not offenders:
104-
return
104+
return []
105105
names = [img.name for img in offenders]
106-
logger.log(channel, f"{cause} for image(s): {', '.join(names)}")
106+
message = f"{cause} for image(s): {', '.join(names)}"
107+
logger.log(channel, message)
108+
return [message]
107109

108110

109111
def compute_scs_0102_prop_architecture(images, architectures=ARCHITECTURES):
@@ -165,8 +167,7 @@ def compute_scs_0102_prop_os_distro(images):
165167
def compute_scs_0102_prop_os_purpose(images, os_purposes=OS_PURPOSES):
166168
"""This test ensures that each image has a proper value for the property `os_distro`."""
167169
offenders = [img for img in images if img.properties.get('os_purpose') not in os_purposes]
168-
_log_error('property os_purpose not set or not correct', offenders)
169-
return not offenders
170+
return _log_error('property os_purpose not set or not correct', offenders)
170171

171172

172173
def compute_scs_0102_prop_hw_disk_bus(images, hw_disk_buses=HW_DISK_BUSES):

0 commit comments

Comments
 (0)