36 lines
2.7 KiB
Python
36 lines
2.7 KiB
Python
import pathlib,subprocess,secrets,json,time
|
|
import os
|
|
root=pathlib.Path(__file__).resolve().parents[2]
|
|
bundle=pathlib.Path(os.environ['HEALTHAPP_RELEASE']).resolve()
|
|
name='healthapp-b-native-'+secrets.token_hex(4)
|
|
image='healthapp-b-systemd-test:debian12'
|
|
evidence=root/'ImplementationPlan/evidence';evidence.mkdir(exist_ok=True)
|
|
def run(args,check=True):
|
|
r=subprocess.run(args,capture_output=True,text=True)
|
|
if check and r.returncode:raise RuntimeError('Command failed: '+str(args[:3])+'\n'+(r.stdout+r.stderr)[-4000:])
|
|
return r
|
|
run(['docker','build','-t',image,str(root/'tools/native-install-test')])
|
|
run(['docker','run','--rm','-d','--privileged','--cgroupns=private','--tmpfs','/run','--tmpfs','/run/lock','--name',name,image])
|
|
try:
|
|
for _ in range(60):
|
|
r=run(['docker','exec',name,'systemctl','is-system-running'],False)
|
|
if r.stdout.strip() in ('running','degraded'):break
|
|
time.sleep(.5)
|
|
else:raise RuntimeError('systemd did not start')
|
|
run(['docker','cp',str(bundle),name+':/release'])
|
|
result=run(['docker','exec',name,'bash','/release/install.sh','--host','localhost'],False)
|
|
(evidence/'native-debian12.log').write_text(result.stdout+result.stderr)
|
|
print((result.stdout+result.stderr)[-5000:])
|
|
if result.returncode:
|
|
logs=run(['docker','exec',name,'journalctl','-u','healthapp-b','--no-pager','-n','40'],False)
|
|
print(logs.stdout[-4000:]);raise RuntimeError('native installation failed')
|
|
config_mode=run(['docker','exec',name,'stat','-c','%a %U %G','/etc/healthapp-b/appsettings.json']).stdout.strip()
|
|
if config_mode!='640 root healthapp-b':raise RuntimeError('runtime configuration permissions are incorrect')
|
|
before=run(['docker','exec',name,'sha256sum','/etc/healthapp-b/appsettings.json']).stdout
|
|
duplicate=run(['docker','exec',name,'bash','/release/install.sh','--host','localhost'],False)
|
|
if duplicate.returncode==0 or before!=run(['docker','exec',name,'sha256sum','/etc/healthapp-b/appsettings.json']).stdout:raise RuntimeError('existing installation was overwritten')
|
|
data={'environment':run(['docker','exec',name,'cat','/etc/os-release']).stdout,'runtime':run(['docker','exec',name,'dotnet','--list-runtimes']).stdout,'applicationPID':run(['docker','exec',name,'systemctl','show','healthapp-b','--property','MainPID','--value']).stdout.strip(),'databaseStatus':run(['docker','exec',name,'pg_isready']).stdout.strip(),'result':'passed','overwriteRejected':True,'runtimeConfigMode':config_mode,'isolation':'Disposable privileged systemd Linux container; native installer/unit/services executed; not physical-host or measurement evidence'}
|
|
(evidence/'native-debian12-summary.json').write_text(json.dumps(data,indent=2)+'\n')
|
|
print('Native Debian 12 installation passed.')
|
|
finally:run(['docker','stop',name],False)
|