"""One-shot administrator integration check; never stop an existing workload.""" import json, pathlib, sqlite3, struct, subprocess, time, urllib.request ROOT=pathlib.Path('/root/llmuser-gpu-priority-20261110') PROJECT=pathlib.Path('/data/llmusers/llmuser/workspace/projects/llm-services') POLICY=pathlib.Path('/var/lib/llmuser-gpu-policy/status.json') D='/usr/bin/docker' UUID='GPU-6f547b70-7a25-70cb-e134-888402be61e2' KEY=(PROJECT/'config/api_key').read_text().strip() report={'started_at':time.time(),'checks':{},'events':[],'passed':False} probes={} job_id=None def record(phase, **extra): item={'phase':phase,'time':time.time(),**extra} report['events'].append(item) (ROOT/'integration-progress.json').write_text(json.dumps(report,indent=2)) print(json.dumps(item),flush=True) def api(path, payload=None): headers={'Authorization':'Bearer '+KEY} data=None if payload is not None: data=json.dumps(payload).encode() headers['Content-Type']='application/json' return json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:18190'+path,data=data,headers=headers),timeout=10)) def status(): s=json.loads(POLICY.read_text()) if s['error'] is not None or time.time()-s['generated_at']>5: raise RuntimeError('GPU monitor unavailable') return s def gpu2(): return next(g for g in status()['gpus'] if g['uuid']==UUID) def wait_for(predicate, seconds, description): deadline=time.monotonic()+seconds while time.monotonic()=1 and not any(g['own_pids'] for g in status()['gpus']) else None interrupted=wait_for(yielded,30,'llmuser process exit and requeue') report['checks']['foreign_appearance_preempts_and_requeues']=True report['checks']['all_llmuser_gpu_processes_released']=True report['preempted_snapshot']=interrupted assert inspect('llmuser-priority-validation-preempt')['State']['Running'] report['checks']['foreign_probe_not_terminated']=True time.sleep(3) assert api('/jobs/'+job_id)['state']=='queued' record('verified_preemption_and_foreign_preserved',job_id=job_id) stop_probe('llmuser-priority-validation-preempt') def completed(): j=api('/jobs/'+job_id) if j['state'] in ('failed','cancelled','timed_out'):raise RuntimeError(json.dumps(j)) return j if j['state']=='succeeded' else None final=wait_for(completed,420,'same job restarts and produces image') assert final['id']==job_id and final['attempt_count']>=2 and final['preemptions']>=1 assert final['gpu_uuid']==UUID path=pathlib.Path('/data/llmusers/llmuser/workspace')/pathlib.Path(final['result']['outputs'][0]['path']).relative_to('/workspace') raw=path.read_bytes();assert raw[:8]==b'\x89PNG\r\n\x1a\n' and struct.unpack('>II',raw[16:24])==(512,512) assert ('attempt-%04d'%final['attempt_count']) in str(path) report['checks']['same_job_resumes_from_start_on_available_gpu']=True report['checks']['retry_has_isolated_valid_image_output']=True report['final_job']=final report['passed']=True record('completed',job_id=job_id,attempt_count=final['attempt_count'],preemptions=final['preemptions']) except Exception as exc: report['error']=type(exc).__name__+': '+str(exc) record('failed',error=report['error']) if job_id: try:api('/jobs/'+job_id+'/cancel',{}) except Exception:pass finally: for name in list(probes): try:stop_probe(name) except Exception as exc:report.setdefault('cleanup_errors',[]).append(str(exc)) report['finished_at']=time.time() (ROOT/'priority-integration.json').write_text(json.dumps(report,indent=2))