Skip to content

Commit 79cc15a

Browse files
committed
Add testcase anchors to log view
Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 402a47b commit 79cc15a

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

compliance-monitor/monitor.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,31 @@ def _patch_report(report):
427427
log.append('arguments: ' + shlex.join(run['argv']))
428428
for invdata in run['invocations'].values():
429429
log.append('$ ' + invdata['cmd'])
430-
log.extend(invdata['stderr'])
430+
for line in invdata['stderr']:
431+
if line.startswith('DEBUG: ** '):
432+
testcase_id = line.split()[2]
433+
line = f'INFO: *** {testcase_id}'
434+
log.append(line)
431435
for tc_id, value in invdata['results'].items():
432436
tests[tc_id] = {'result': value}
433437

434438

439+
def _augment_report(report):
440+
tests = report.get('tests', {})
441+
log = []
442+
for line in report.get('log', ()):
443+
if line.startswith('INFO: *** '):
444+
testcase_id = line.split()[2]
445+
result = tests.get(testcase_id)
446+
if result is not None:
447+
result['_inlog'] = True
448+
val = result.get('result', None)
449+
verdict = {1: 'PASS', 0: 'DNF', -1: 'FAIL'}.get(val, 'N/A')
450+
line = f'INFO: *** {testcase_id} ({verdict})'
451+
log.append(line)
452+
report['log'] = log
453+
454+
435455
@app.post("/reports")
436456
async def post_report(
437457
request: Request,
@@ -590,7 +610,20 @@ def report_url(report, *args, **kwargs): return _build_report_url(base_url, repo
590610
def _redact_report(report):
591611
"""remove all lines from script output in `report` that are not directly linked to any testcase"""
592612
log = report['log']
593-
redacted = [line for line in log if line.split(':', 1)[0] in ('WARNING', 'ERROR', 'CRITICAL')]
613+
# don't do list comprehension here because it would restrict the logic
614+
# (e.g. hard to replace a batch of lines by a different batch of lines)
615+
redacted = []
616+
for line in log:
617+
parts = line.split(': ', 1)
618+
if len(parts) != 2:
619+
continue
620+
# don't redact 'official' error messages
621+
# this can still leak information and should be changed
622+
if parts[0] in ('WARNING', 'ERROR', 'CRITICAL'):
623+
redacted.append(line)
624+
# don't redact the line that states what testcase is now being tested
625+
elif parts[0] in ('INFO', ) and parts[1].startswith('***'):
626+
redacted.append(line)
594627
report['log'] = redacted
595628
return len(log) != len(redacted)
596629

@@ -618,6 +651,7 @@ async def get_report_view(
618651
raise HTTPException(status_code=404)
619652
report = reports[0]
620653
_patch_report(report)
654+
_augment_report(report)
621655
redacted = _redact_report(report)
622656
return render_view(
623657
VIEW_REPORT, view_type, report=report, base_url=settings.base_url,
@@ -640,6 +674,7 @@ async def get_report_view_full(
640674
raise HTTPException(status_code=404)
641675
report = reports[0]
642676
_patch_report(report)
677+
_augment_report(report)
643678
check_role(account, report['subject'], ROLES['read_any'])
644679
return render_view(
645680
VIEW_REPORT, view_type, report=report, base_url=settings.base_url,

compliance-monitor/templates/overview.html.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
li {margin:0.33em 0;}
1414
#log + ul {padding-left:0;}
1515
#log + ul > li {margin:0;display:block;text-indent:1em hanging;}
16-
#log + ul > li strong {background-color:yellow;}
16+
#log + ul > li strong em {background-color:yellow;font-style:normal;}
1717
</style>
1818
{% if title %}<h1>{{title}}</h1>
1919
{% endif %}{{fragment}}</body>

compliance-monitor/templates/report.md.j2

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ else %}{% set uuid = report.uuid %}{% set scopeuuid = report.scope %}{% endif -%
1111
{% if report.tests -%}
1212
## Tests
1313
{% for resultid, resultdata in report.tests.items() | sort %}
14-
- {{ resultid }}: {{ resultdata.result | verdict_check }}
15-
{: #{{ resultid }} }
14+
- {{ resultid }}: {{ resultdata.result | verdict_check }}{% if not resultdata._inlog %}
15+
{: #{{ resultid }} } {% endif %}
1616
{%- endfor -%}
1717
{% endif %}
1818
{% if report.log %}
1919
## Log{%if redacted %} (redacted){%endif%} {: #log }
2020

2121
{% for line in report.log %}
22-
- {% if line.split(':', 1)[0].lower() in ('warning', 'error', 'critical') %}**`{{line}}`**{%
22+
- {% if line.split(':', 1)[0].lower() in ('warning', 'error', 'critical') %}**_`{{line}}`_**{%
23+
elif line.startswith('INFO: *** ') %}{% if 'PASS' in line %} `{{line}}` {% else %} **`{{line}}`** {% endif %}
24+
{: #{{line.split()[2]}} }{%
2325
else %}`{{line}}`{% endif %}
2426
{%- endfor %}
2527

26-
{% if redacted %}
27-
» [show unredacted (requires login) 🔒]({{report_url(uuid, full=True)}}#{{ invid }})
2828
{% endif %}
2929

30+
{% if redacted %}
31+
» [show unredacted (requires login) 🔒]({{report_url(uuid, full=True)}}#{{ invid }})
3032
{% endif %}

0 commit comments

Comments
 (0)