Commit d50a24ac authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files add an option to generate config templates

Try to semi-automate the writing of yaml configuration files by generating
a template yaml configuration from tests data, which can be further edited

Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <>
parent cd007bb7
......@@ -97,6 +97,23 @@ Try it with:
$ ./ --config sample.yaml ...
### Generating a configuration template
To ease the writing of yaml configurations, there is a `--template` option to
generate a configuration "template" from the results of a run:
``` {.sh}
$ ./ --template template.yaml ...
This generated configuration can then be further edited manually.
* Tests with result "PASS" are omitted.
* The following tests fields are omitted from the generated rule "criteria":
"iteration", "start date" and "start time".
* The generated rule "criteria" "log" field is filtered to remove the leading
path before C filename.
## Notes
### Known Issues:
* "comment" is currently not implemented, as formatting is not currently consistent, should reflect the comments from the test.
......@@ -7,6 +7,7 @@ import argparse
import csv
import logging
import json
import re
from packaging import version
......@@ -359,6 +360,44 @@ def gen_yaml(cross_check, filename):
yaml.dump(cross_check, yamlfile, Dumper=Dumper)
# Generate yaml config template
# This is to help writing yaml config.
# We omit tests with result PASS.
# We omit some tests keys: iteration and dates.
# We remove the leading directory from C filename in log.
def gen_template(cross_check, filename):
assert('yaml' in sys.modules)
logging.debug(f'Generate {filename}')
omitted_keys = set(['iteration', 'start date', 'start time'])
t = []
i = 1
for x in cross_check:
if x['result'] == 'PASS':
r = {
'rule': f'Generated rule ({i})',
'criteria': {},
'update': {'result': 'TEMPLATE'},
for key, value in x.items():
if key in omitted_keys:
if key == 'log':
value = re.sub(r'^/.*/', '', value)
r['criteria'][key] = value
i += 1
with open(filename, 'w') as yamlfile:
yaml.dump(t, yamlfile, Dumper=Dumper)
# Combine or two databases db1 and db2 coming from ekl and seq files
# respectively into a single cross_check database
# Tests in db1, which were not meant to be run according to db2 have their
......@@ -462,6 +501,8 @@ def main():
'--config', help='Input .yaml configuration filename')
parser.add_argument('--yaml', help='Output .yaml filename')
'--template', help='Output .yaml config template filename')
args = parser.parse_args()
......@@ -558,8 +599,12 @@ def main():
if 'yaml' in args and args.yaml is not None:
gen_yaml(cross_check, args.yaml)
#command line argument 3&4, key are to support a key & value search.
#these will be displayed in CLI
# Generate yaml config template if requested
if 'template' in args and args.template is not None:
gen_template(cross_check, args.template)
# command line argument 3&4, key are to support a key & value search.
# these will be displayed in CLI
if args.find_key is not None and args.find_value is not None:
found = key_value_find(db1, args.find_key, args.find_value)
#print the dict
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment