52 lines
2.5 KiB
Python
52 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Bind explicitly reviewed evidence to ISO/OSTree identities for publication."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def digest(path):
|
|
with Path(path).open('rb') as stream:
|
|
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
|
|
|
|
|
def prepare(config):
|
|
records = []
|
|
for item in config['candidates']:
|
|
root = Path(item['directory'])
|
|
iso = root / 'build/output' / item['iso_name']
|
|
repo = root / 'build/repo'
|
|
sha = digest(iso)
|
|
if item['variant'] == 'core':
|
|
summary = json.loads(Path(item['core_summary']).read_text())
|
|
if summary.get('passed') is not True or summary.get('iso_sha256') != sha:
|
|
raise ValueError('Core VM acceptance missing or mismatched')
|
|
if item.get('native_summary'):
|
|
summary = json.loads(Path(item['native_summary']).read_text())
|
|
if summary.get('passed') is not True or summary.get('iso_sha256') != sha:
|
|
raise ValueError('Native GNOME acceptance missing or mismatched')
|
|
checks = []
|
|
for check in item['checks']:
|
|
path = Path(check['path'])
|
|
if check.get('contains') and check['contains'] not in path.read_text():
|
|
raise ValueError('Missing check marker: ' + str(path))
|
|
checks.append(dict(path=str(path), sha256=digest(path)))
|
|
def resolve(ref):
|
|
return subprocess.check_output(['ostree', '--repo=' + str(repo), 'rev-parse', ref], text=True).strip()
|
|
record = dict(variant=item['variant'], version=item['version'], iso=str(iso), repo=str(repo),
|
|
sha256=sha, image_commit=resolve('core'), layer_commit=resolve('layers/core'),
|
|
acceptance=str(root / 'hardware-test-acceptance.json'))
|
|
if item['variant'] == 'gnome':
|
|
record['purpose_layer_commit'] = resolve('layers/purpose/desktop/gnome')
|
|
if item.get('expected_image_commit') and record['image_commit'] != item['expected_image_commit']:
|
|
raise ValueError('Reviewed image differs from repository')
|
|
Path(record['acceptance']).write_text(json.dumps(record | dict(scope='hardware-test',
|
|
accepted=True, checks=checks, limitations=item.get('limitations', [])), indent=2) + '\n')
|
|
records.append(record)
|
|
Path(config['output']).write_text(json.dumps(records, indent=2) + '\n')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
prepare(json.loads(Path(sys.argv[1]).read_text()))
|