Files
archy/scripts/tests/qualify_os_ota_owner_boot.py

49 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Clone an actually applied bootstrap guest, then BIOS boot and query real D09.
Run in the same durable CPU2/8G/no-swap discipline as the installed VM harness.
Never writes the bootstrap owner's source disk; retains every failed child.
"""
import argparse
import json
from pathlib import Path
import subprocess
import sys
import time
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--applied-report',type=Path,required=True)
p.add_argument('--output',type=Path,required=True)
p.add_argument('--wait',type=int,default=0)
a=p.parse_args()
deadline=time.monotonic()+a.wait
while not (a.applied_report/'result.json').exists() and time.monotonic()<deadline:
time.sleep(2)
applied=json.loads((a.applied_report/'result.json').read_text())
assert applied['passed'], 'bootstrap/apply guest did not pass'
bootstrap=json.loads((a.applied_report/'os-ota-stage/bootstrap-result.json').read_text())
assert bootstrap['passed'] and bootstrap['os_status']['phase']=='REBOOT_REQUIRED'
event=next(e for e in reversed(bootstrap['os_status']['events']) if e['phase']=='REBOOT_REQUIRED')
release=event['details']['boot']['release']
a.output.mkdir(mode=0o755,exist_ok=False)
harness=Path(__file__).with_name('os_ota_installed_vm.py')
source=Path(__file__).resolve().parents[2]
results=[]
def step(name,*args):
command=[sys.executable,'-B',str(harness),'--output',str(a.output/name),*map(str,args)]
with (a.output/(name+'.driver.log')).open('x') as log:
result=subprocess.run(command,stdout=log,stderr=subprocess.STDOUT)
results.append(dict(name=name,exit=result.returncode,command=command))
(a.output/'progress.json').write_text(json.dumps(results,indent=2)+'\n')
result.check_returncode()
try:
step('disk','clone','--disk',applied['disk'])
disk=a.output/'disk/installed.raw'
step('export','export','--disk',disk,'--kernel-release',release)
step('postboot','boot','--disk',disk,'--kernel',a.output/'export'/('vmlinuz-'+release),
'--initrd',a.output/'export'/('initrd.img-'+release),'--firmware','--offline',
'--guest',source/'tests/regression/os-ota-installed-owner-postboot.py')
finally:
(a.output/'result.json').write_text(json.dumps(dict(passed=len(results)==3 and all(x['exit']==0 for x in results),
production_approved=False,source_applied_report=str(a.applied_report),results=results),indent=2)+'\n')