64 lines
3.2 KiB
Python
64 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Run inside normal acceptance VMs; stdout is a single acceptance record."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def call(*args, success=True):
|
|
p = subprocess.run(['archipelago', *args], text=True, capture_output=True, timeout=600)
|
|
assert (p.returncode == 0) == success, (args, p.returncode, p.stdout, p.stderr)
|
|
return p
|
|
|
|
|
|
def query(*args, success=True):
|
|
p = call(*args, '--json', success=success)
|
|
assert not p.stderr, ('JSON mode must not print progress', p.stderr)
|
|
result = json.loads(p.stdout)
|
|
assert isinstance(result, dict)
|
|
if not success:
|
|
assert isinstance(result.get('error'), dict), result
|
|
return result
|
|
|
|
|
|
phase = sys.argv[1]
|
|
marker = 'archipelago.acceptance=retained'
|
|
if phase == 'prepare':
|
|
status = query('status')
|
|
assert status['booted']['deployment_id']
|
|
human = call('status')
|
|
assert not human.stdout.lstrip().startswith('{')
|
|
assert all(word not in human.stdout + human.stderr for word in ['retry token:', 'admission:', 'Checked plan '])
|
|
debug = call('status', '--debug', '--json')
|
|
assert json.loads(debug.stdout)['booted'] == status['booted']
|
|
assert any(json.loads(line)['event'] == 'result' for line in debug.stderr.splitlines())
|
|
before = query('kargs')
|
|
rejected = query('kargs', '--append=ostree=/invalid', success=False)
|
|
assert rejected['error']['message']
|
|
assert query('kargs') == before, 'Invalid edit changed deployment'
|
|
first = query('kargs', '--append-if-missing=archipelago.acceptance=initial')
|
|
assert first['outcome'] == 'staged'
|
|
second = query('kargs', '--replace=archipelago.acceptance=initial=retained', '--delete-if-present=quiet')
|
|
assert second['outcome'] == 'staged'
|
|
selected = query('kargs')['selected']
|
|
assert marker in selected['arguments'] and 'quiet' not in selected['arguments']
|
|
unchanged = query('kargs', '--append-if-missing=' + marker)
|
|
assert unchanged['outcome'] == 'no-change'
|
|
assert query('kargs')['selected']['deployment_id'] == selected['deployment_id']
|
|
human = call('kargs', '--append-if-missing=' + marker)
|
|
assert all(word not in human.stdout + human.stderr for word in ['retry token:', 'admission:', 'Checked plan ', '{'])
|
|
Path('/var/tmp/archipelago-cli-contract.json').write_text(json.dumps({'marker':marker, 'original':before}))
|
|
elif phase == 'verify':
|
|
evidence = json.loads(Path('/var/tmp/archipelago-cli-contract.json').read_text())
|
|
assert evidence['marker'] in Path('/proc/cmdline').read_text().split()
|
|
assert 'quiet' not in Path('/proc/cmdline').read_text().split(), 'Extension staging reset user kargs'
|
|
state = query('kargs')
|
|
booted = next(d for d in state['deployments'] if d['booted'])
|
|
assert marker in booted['arguments'] and 'quiet' not in booted['arguments']
|
|
history = query('transaction', 'list')
|
|
assert not history['next_cursor'], 'Acceptance must read complete history'
|
|
assert any(r['Kind'] == 'kernel-arguments' and r['State'] == 'succeeded' for r in history['transactions'])
|
|
else:
|
|
raise ValueError('Unknown acceptance phase')
|
|
print(json.dumps({'passed':True,'phase':phase,'cli_formats':['human','json','debug-json'],'kernel_arguments':marker}))
|