Skip to content

Commit 967f2da

Browse files
Ricardo Cañuelor-c-n
authored andcommitted
result_summary: add cmdline option --output-dir
Introduce a new command-line option: --output-dir, and rename the old --output to --output-file. Signed-off-by: Ricardo Cañuelo <[email protected]>
1 parent c3960ed commit 967f2da

File tree

5 files changed

+117
-53
lines changed

5 files changed

+117
-53
lines changed

config/result-summary.yaml

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# file used for the summary generation. This template must be a file in
1212
# config/result_summary_templates. Other optional fields are supported:
1313
#
14-
# - "output": name of the file where the output will be stored (in
14+
# - "output_file": name of the file where the output will be stored (in
1515
# data/output)
1616
# - "title": title for the report
1717
#
@@ -34,7 +34,7 @@
3434
# action: summary
3535
# title: "Example test report"
3636
# template: "mytemplate.jinja2"
37-
# output: "default-test.txt"
37+
# output_file: "default-test.txt"
3838
# preset:
3939
# test:
4040
# # Query by group, name, arch and list of repos
@@ -62,7 +62,7 @@ monitor-active-stable-rc-build-regressions:
6262
action: monitor
6363
title: "<strong>stable-rc</strong> kernel build regression"
6464
template: "generic-regression-report.html.jinja2"
65-
output: "stable-rc-build-regression-report.html"
65+
output_file: "stable-rc-build-regression-report.html"
6666
preset:
6767
regression:
6868
- name__re: kbuild
@@ -77,7 +77,7 @@ monitor-stable-rc-build-failures:
7777
action: monitor
7878
title: "<strong>stable-rc</strong> kernel build failure"
7979
template: "generic-test-failure-report.html.jinja2"
80-
output: "stable-rc-build-failure.html"
80+
output_file: "stable-rc-build-failure.html"
8181
preset:
8282
kbuild:
8383
- result: fail
@@ -90,7 +90,7 @@ monitor-active-stable-rc-boot-regressions:
9090
action: monitor
9191
title: "<strong>stable-rc</strong> kernel boot regression"
9292
template: "generic-regression-report.html.jinja2"
93-
output: "stable-rc-boot-regression-report.html"
93+
output_file: "stable-rc-boot-regression-report.html"
9494
preset:
9595
regression:
9696
- group__re: baseline
@@ -104,20 +104,53 @@ monitor-all-regressions:
104104
action: monitor
105105
title: "KernelCI regression report"
106106
template: "generic-regression-report.html.jinja2"
107-
output: "regression-report.html"
107+
output_file: "regression-report.html"
108108
preset:
109109
regression:
110110

111+
monitor-all-test-failures__runtime_errors:
112+
metadata:
113+
action: monitor
114+
title: "KernelCI test failure report"
115+
template: "generic-test-failure-report.html.jinja2"
116+
output_file: "test-failure-report.html"
117+
preset:
118+
test:
119+
- result: fail
120+
data.error_code__ne: null
121+
111122
monitor-all-test-failures:
112123
metadata:
113124
action: monitor
114125
title: "KernelCI test failure report"
115126
template: "generic-test-failure-report.html.jinja2"
116-
output: "test-failure-report.html"
127+
output_file: "test-failure-report.html"
117128
preset:
118129
test:
119130
- result: fail
131+
data.error_code: null
120132

133+
monitor-all-build-failures__runtime_errors:
134+
metadata:
135+
action: monitor
136+
title: "KernelCI kbuild failure report"
137+
template: "generic-test-failure-report.html.jinja2"
138+
output_file: "kbuild-failure-report.html"
139+
preset:
140+
kbuild:
141+
- result: fail
142+
data.error_code__ne: null
143+
144+
monitor-all-build-failures:
145+
metadata:
146+
action: monitor
147+
title: "KernelCI kbuild failure report"
148+
template: "generic-test-failure-report.html.jinja2"
149+
output_file: "kbuild-failure-report.html"
150+
preset:
151+
kbuild:
152+
- result: fail
153+
data.error_code: null
121154

122155
### Summary presets
123156

@@ -127,7 +160,7 @@ stable-rc-build-regressions:
127160
action: summary
128161
title: "<strong>stable-rc</strong> kernel build regressions"
129162
template: "generic-regressions.html.jinja2"
130-
output: "stable-rc-build-regressions.html"
163+
output_file: "stable-rc-build-regressions.html"
131164
preset:
132165
regression:
133166
- name__re: kbuild
@@ -140,7 +173,7 @@ active-stable-rc-build-regressions:
140173
action: summary
141174
title: "<strong>stable-rc</strong> kernel build regressions"
142175
template: "generic-regressions.html.jinja2"
143-
output: "active-stable-rc-build-regressions.html"
176+
output_file: "active-stable-rc-build-regressions.html"
144177
preset:
145178
regression:
146179
- name__re: kbuild
@@ -155,7 +188,7 @@ stable-rc-build-failures:
155188
action: summary
156189
title: "<strong>stable-rc</strong> kernel build failures"
157190
template: "generic-test-failures.html.jinja2"
158-
output: "stable-rc-build-failures.html"
191+
output_file: "stable-rc-build-failures.html"
159192
preset:
160193
kbuild:
161194
- result: fail
@@ -168,7 +201,7 @@ stable-rc-boot-regressions:
168201
action: summary
169202
title: "<strong>stable-rc</strong> kernel boot regressions"
170203
template: "generic-regressions.html.jinja2"
171-
output: "stable-rc-boot-regressions.html"
204+
output_file: "stable-rc-boot-regressions.html"
172205
preset:
173206
regression:
174207
- group__re: baseline
@@ -181,7 +214,7 @@ stable-rc-boot-active-regressions:
181214
action: summary
182215
title: "<strong>stable-rc</strong> kernel boot regressions"
183216
template: "generic-regressions.html.jinja2"
184-
output: "stable-rc-boot-regressions.html"
217+
output_file: "stable-rc-boot-regressions.html"
185218
preset:
186219
regression:
187220
- group__re: baseline
@@ -196,7 +229,7 @@ stable-rc-boot-failures:
196229
action: summary
197230
title: "<strong>stable-rc</strong> kernel boot failures"
198231
template: "generic-test-failures.html.jinja2"
199-
output: "stable-rc-boot-failures.html"
232+
output_file: "stable-rc-boot-failures.html"
200233
preset:
201234
test:
202235
- group__re: baseline
@@ -210,7 +243,7 @@ tast-failures:
210243
action: summary
211244
title: "General Tast test failures"
212245
template: "generic-test-failures.html.jinja2"
213-
output: "tast-failures.html"
246+
output_file: "tast-failures.html"
214247
preset:
215248
test:
216249
- group__re: tast
@@ -224,7 +257,7 @@ tast-failures__runtime_errors:
224257
action: summary
225258
title: "General Tast test failures"
226259
template: "generic-test-failures.html.jinja2"
227-
output: "tast-failures.html"
260+
output_file: "tast-failures.html"
228261
preset:
229262
test:
230263
- group__re: tast
@@ -239,7 +272,7 @@ mainline-next-regressions:
239272
action: summary
240273
title: "Regressions found in mainline and next"
241274
template: "generic-regressions.html.jinja2"
242-
output: "mainline-next-regressions.html"
275+
output_file: "mainline-next-regressions.html"
243276
preset:
244277
regression:
245278
- data.error_code: null
@@ -252,7 +285,7 @@ mainline-next-test-failures:
252285
action: summary
253286
title: "Regressions found in mainline and next"
254287
template: "generic-regressions.html.jinja2"
255-
output: "mainline-next-regressions.html"
288+
output_file: "mainline-next-regressions.html"
256289
preset:
257290
test:
258291
- result: fail
@@ -268,7 +301,7 @@ mainline-next-active-regressions:
268301
action: summary
269302
title: "Regressions found in mainline and next"
270303
template: "generic-regressions.html.jinja2"
271-
output: "mainline-next-active-regressions.html"
304+
output_file: "mainline-next-active-regressions.html"
272305
preset:
273306
regression:
274307
- data.error_code: null
@@ -285,7 +318,7 @@ mainline-next-regressions__runtime_errors:
285318
action: summary
286319
title: "'Regressions' found in mainline and next due to runtime errors"
287320
template: "generic-regressions.html.jinja2"
288-
output: "mainline-next-regressions__runtime_errors.html"
321+
output_file: "mainline-next-regressions__runtime_errors.html"
289322
preset:
290323
regression:
291324
- data.error_code__ne: null
@@ -300,7 +333,7 @@ tast-regressions-x86_64:
300333
action: summary
301334
title: "Regressions found on Tast tests for x86_64"
302335
template: "generic-regressions.html.jinja2"
303-
output: "tast-regressions-x86_64.html"
336+
output_file: "tast-regressions-x86_64.html"
304337
preset:
305338
regression:
306339
- group__re: tast
@@ -315,7 +348,7 @@ tast-regressions-x86_64__runtime_errors:
315348
action: summary
316349
title: "'Regressions' found on Tast tests for x86_64 due to runtime errors"
317350
template: "generic-regressions.html.jinja2"
318-
output: "tast-regressions-x86_64__runtime_errors.html"
351+
output_file: "tast-regressions-x86_64__runtime_errors.html"
319352
preset:
320353
regression:
321354
- group__re: tast
@@ -329,7 +362,7 @@ active-kunit-regressions:
329362
action: summary
330363
title: "Active regressions found on kunit tests"
331364
template: "generic-regressions.html.jinja2"
332-
output: "kunit-regressions.html"
365+
output_file: "kunit-regressions.html"
333366
preset:
334367
regression:
335368
- group__re: kunit
@@ -342,7 +375,7 @@ all-kunit-failures:
342375
action: summary
343376
title: "All kunit test failures"
344377
template: "generic-test-failures.html.jinja2"
345-
output: "kunit-failures.html"
378+
output_file: "kunit-failures.html"
346379
preset:
347380
test:
348381
- group__re: kunit

src/result_summary.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@
1919
# (default: yesterday) and --date-to (default: now) options, formatted
2020
# as YYYY-MM-DD or YYYY-MM-DDTHH:mm:SS (UTC)
2121
#
22-
# Each preset may define the name of the output file generated (in
23-
# data/output). This can be overriden with the --output option. If no
24-
# output file is defined, the output will be printed to stdout.
22+
# Each preset may define the name and the directory of the output file
23+
# generated (in data/output). This can be overriden with the
24+
# --output-dir and --output-file options. If no output file is defined,
25+
# the output will be printed to stdout.
2526
#
2627
# For current status info, see the development changelog in
27-
# config/result_summary_templates/CHANGELOG
28+
# doc/result-summary-CHANGELOG
2829

2930
# TODO:
3031
# - Refactor liberally
31-
# - Implement loop mode
3232
# - Send email reports
3333
# - Do we want to focus on regressions only or on any kind of result?
3434
# If we want test results as well:
3535
# - Provide logs for test leaf nodes
3636
# - Tweak output and templates according to user needs
37-
# - Parameterize/generalize templates to avoid duplication
3837
# - Other suggested improvements
3938

4039
import sys
@@ -81,9 +80,12 @@ def _setup(self, args):
8180
extra_query_params = {}
8281
if args.query_params:
8382
extra_query_params = split_query_params(args.query_params)
84-
output = None
85-
if args.output:
86-
output = args.output
83+
output_dir = None
84+
if args.output_dir:
85+
output_dir = args.output_dir
86+
output_file = None
87+
if args.output_file:
88+
output_file = args.output_file
8789
# End of command line argument loading and sanity checks
8890

8991
# Load presets and template
@@ -103,7 +105,8 @@ def _setup(self, args):
103105
'preset_params': preset_params,
104106
'extra_query_params': extra_query_params,
105107
'template': template,
106-
'output': output,
108+
'output_file': output_file,
109+
'output_dir': output_dir,
107110
}
108111
# Action-specific setup
109112
if metadata.get('action') == 'summary':
@@ -171,7 +174,11 @@ class cmd_run(Command):
171174
"(YYYY-mm-DDTHH:MM:SS). Default: until now"),
172175
},
173176
{
174-
'name': '--output',
177+
'name': '--output-dir',
178+
'help': "Override the 'output_dir' preset parameter"
179+
},
180+
{
181+
'name': '--output-file',
175182
'help': "Override the 'output' preset parameter"
176183
},
177184
{

src/result_summary/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
SERVICE_NAME = 'result_summary'
22
TEMPLATES_DIR = './config/result_summary_templates/'
3-
OUTPUT_DIR = '/home/kernelci/data/output/'
3+
BASE_OUTPUT_DIR = '/home/kernelci/data/output/'
44
logger = None

src/result_summary/monitor.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,29 @@ def run(service, context):
9090
'node': node,
9191
}
9292
output_text = context['template'].render(template_params)
93-
output = context['output']
94-
if not output:
95-
# Since we expect many reports to be generated,
96-
# prepend them with a timestamp
97-
now_str = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
98-
if 'output' in context['metadata']:
99-
output = now_str + '__' + context['metadata']['output']
100-
if output:
101-
with open(os.path.join(result_summary.OUTPUT_DIR, output), 'w') as output_file:
102-
output_file.write(output_text)
103-
service.log.info(f"Report generated in {output}")
93+
# Setup output dir from base path and user-specified
94+
# parameter (in preset metadata or cmdline)
95+
output_dir = result_summary.BASE_OUTPUT_DIR
96+
if context.get('output_dir'):
97+
output_dir = os.path.join(output_dir, context['output_dir'])
98+
elif 'output_dir' in context['metadata']:
99+
output_dir = os.path.join(output_dir, context['metadata']['output_dir'])
100+
os.makedirs(output_dir, exist_ok=True)
101+
# Generate and dump output
102+
# output_file specified in cmdline:
103+
output_file = context['output_file']
104+
if not output_file:
105+
# Check if output_file is specified as a preset
106+
# parameter. Since we expect many reports to be
107+
# generated, prepend them with a timestamp
108+
if 'output_file' in context['metadata']:
109+
now_str = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
110+
output_file = now_str + '__' + context['metadata']['output_file']
111+
if output_file:
112+
output_file = os.path.join(output_dir, output_file)
113+
with open(output_file, 'w') as outfile:
114+
outfile.write(output_text)
115+
service.log.info(f"Report generated in {output_file}")
104116
else:
105117
result_summary.logger.info(output_text)
106118
else:

src/result_summary/summary.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,25 @@ def run(service, context):
130130
'last_updated_to': context['date_params'].get(_date_params['last_updated_to']),
131131
}
132132
output_text = context['template'].render(template_params)
133-
output = context['output']
134-
if not output:
135-
if 'output' in context['metadata']:
136-
output = context['metadata']['output']
137-
if output:
138-
with open(os.path.join(result_summary.OUTPUT_DIR, output), 'w') as output_file:
139-
output_file.write(output_text)
133+
# Setup output dir from base path and user-specified
134+
# parameter (in preset metadata or cmdline)
135+
output_dir = result_summary.BASE_OUTPUT_DIR
136+
if context.get('output_dir'):
137+
output_dir = os.path.join(output_dir, context['output_dir'])
138+
elif 'output_dir' in context['metadata']:
139+
output_dir = os.path.join(output_dir, context['metadata']['output_dir'])
140+
os.makedirs(output_dir, exist_ok=True)
141+
# Generate and dump output
142+
# output_file specified in cmdline:
143+
output_file = context['output_file']
144+
if not output_file:
145+
# Check if output_file is specified as a preset parameter
146+
if 'output_file' in context['metadata']:
147+
output_file = context['metadata']['output_file']
148+
if output_file:
149+
output_file = os.path.join(output_dir, output_file)
150+
with open((output_file), 'w') as outfile:
151+
outfile.write(output_text)
140152
else:
141153
result_summary.logger.info(output_text)
142154
return True

0 commit comments

Comments
 (0)