Source code

Download source archive ↓

verify-extended-jobs.py

1#!/usr/bin/env python3
2"""Run every extended sample through the standalone engine after public publication."""
3import json,subprocess,time
4from pathlib import Path
5from urllib.request import urlopen
6from urllib.error import HTTPError,URLError
7HERE=Path(__file__).resolve().parent
8ROOT=HERE.parents[2]
9def main():
10 specs=json.loads((HERE/'extra-specs.json').read_text());results=[]
11 for name,s in specs.items():
12  deadline=time.monotonic()+3600
13  while True:
14   try:
15    with urlopen('http://127.0.0.1:8820/v1/operators/'+s['name']+'/1.0',timeout=10) as response:json.load(response)
16    break
17   except HTTPError as e:
18    if e.code!=404:raise
19   except URLError:pass
20   if time.monotonic()>deadline:raise TimeoutError('Publication did not complete: '+name)
21   time.sleep(5)
22  cmd=['sudo','-n','-u','cnic','-g','docker',str(ROOT/'xstream-engine/target/universal/stage/bin/xstream-runner'),str(HERE/'engine-extended.yaml'),str(HERE/'jobs-extended'/f'{name}.yaml')]
23  result=subprocess.run(cmd,cwd=ROOT,capture_output=True,timeout=180)
24  assert result.returncode==0,(name,result.stderr.decode(errors='replace')[-6000:])
25  assert result.stdout.decode()==s['fixture']['expected'],(name,result.stdout,s['fixture']['expected'])
26  results.append({'operator':s['name']+'@1.0','job':f'jobs-extended/{name}.yaml','status':'passed','output':result.stdout.decode()})
27  (HERE/'verification-extended-jobs.json').write_text(json.dumps({'status':'passed' if len(results)==len(specs) else 'running','completed':len(results),'total':len(specs),'jobs':results},indent=2)+'\n')
28  print('PASS standalone Job',name,flush=True)
29if __name__=='__main__':main()