os-autoinst-distri-rocky/fifcheck

44 lines
1.7 KiB
Plaintext
Raw Normal View History

Add a whole intermediate template format ('FIF') and tools I and @lruzicka (and I think @jskladan and @jsedlak and @michelmno and everyone else who's ever touched it...) are being gradually driven nuts by manually editing the test templates. The bigger the files get the more awkward it is to keep them straight and be sure we're doing it right. Upstream doesn't do things the same way we do (they mostly edit in the web UI and dump to file for the record), but we do still think making changes in the repo and posting to the web UI is the right way around to do it, we just wish the format was saner. Upstream has actually recently introduced a YAML-based approach to storing job templates which tries to condense things a bit, and you can dump to that format with dump-templates --json, but @lruzicka and I agree that that format is barely better for hand editing in a text editor than the older one our templates currently use. So, this commit introduces...Fedora Intermediate Format (FIF) - an alternative format for representing job templates - and some tools for working with it. It also contains our existing templates in this new format, and removes the old template files. The format is documented in the docstrings of the tools, but briefly, it keeps Machines, Products and TestSuites but improves their format a bit (by turning dicts-of-lists into dicts-of- dicts), and adds Profiles, which are combinations of Machines and Products. TestSuites can indicate which Profiles they should be run on. The intermediate format converter (`fifconverter`) converts existing template data (in JSON format; use tojson.pm to convert our perl templates to JSON) to the intermediate format and writes it out. As this was really intended only for one-time use (the idea is that after one-time conversion, we will edit the templates in the intermediate format from now on), its operation is hardcoded and relies on specific filenames. The intermediate format loader (`fifloader`) generates JobTemplates from the TestSuites and Profiles, reverses the quality-of-life improvements of the intermediate format, and produces template data compatible with the upstream loader, then can write it to disk and/or call the upstream loader directly. The check script (`fifcheck`) runs existing template data through both the converter and the loader, then checks that the result is equivalent to the input. Again this was mostly written for one- time use so is fairly rough and hard-coded, but I'm including it in the commit so others can check the work and so on. Signed-off-by: Adam Williamson <awilliam@redhat.com>
2020-01-23 14:20:10 +00:00
#!/bin/python3
"""This is a sanity check for the Fedora Intermediate Format (fif) converter and loader. It reads
in templates.old.json and templates-updates.old.json - which are expected to be our original-format
templates in JSON format - runs them through the converter to the intermediate format, then runs
them through the loader *from* the intermediate format, and (via DeepDiff, thanks jskladan!) checks
that the results are equivalent to the input, pace a couple of expected differences.
"""
from deepdiff import DeepDiff
import json
import subprocess
with open('templates.old.json', 'r') as tempfh:
origtemp = json.load(tempfh)
with open('templates-updates.old.json', 'r') as updfh:
origupd = json.load(updfh)
# run the converter
subprocess.run(['./fifconverter.py'])
# run the loader on the converted files
subprocess.run(['./fifloader.py', '--write', 'templates.fif.json', 'templates-updates.fif.json'])
with open('generated.json', 'r') as generatedfh:
generated = json.load(generatedfh)
# merge origs
origtemp['Products'].extend(origupd['Products'])
origtemp['TestSuites'].extend(origupd['TestSuites'])
origtemp['JobTemplates'].extend(origupd['JobTemplates'])
for item in generated['Products']:
# we generate the product names in the converter, our original
# templates don't have them
item['name'] = ""
for item in generated['JobTemplates']:
if item['group_name'] == 'fedora':
# we don't explicitly specify this in our original templates,
# but the converter adds it (rather than relying on openQA
# to guess when loading)
del item['group_name']
ddiff = DeepDiff(origtemp, generated, ignore_order=True, report_repetition=True)
# if this is just {}, we're good
print(ddiff)