25 lines
1.6 KiB
Python
25 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Measure dry-run inventory cost at +0/+100/+1000 synthetic private keys."""
|
|
import json,subprocess,tempfile,uuid
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
def dc(*args):return subprocess.check_output(['docker','compose',*args],cwd=ROOT,text=True,stderr=subprocess.DEVNULL).strip()
|
|
prefix='originals/cost-'+uuid.uuid4().hex
|
|
setup='mc alias set local http://s3:9000 "$(cat /run/secrets/s3_root_user)" "$(cat /run/secrets/s3_root_password)" >/dev/null; '
|
|
results=[]
|
|
def measure(extra):
|
|
raw=dc('run','--rm','--no-deps','api','reconcile')
|
|
r=json.loads(raw.splitlines()[-1]);r['extra_synthetic_objects']=extra;results.append(r)
|
|
with tempfile.TemporaryDirectory(prefix='lab4-inventory-') as folder:
|
|
try:
|
|
measure(0)
|
|
for count in [100,1000]:
|
|
for i in range(count):(Path(folder)/str(i)).write_text('synthetic-inventory-only\n')
|
|
dc('run','--rm','--no-deps','--volume',folder+':/probe:ro','--entrypoint','/bin/sh','s3-init','-c',setup+'mc mirror --quiet /probe local/messenger-attachments/'+prefix+' >/dev/null')
|
|
measure(count)
|
|
finally:
|
|
dc('run','--rm','--no-deps','--entrypoint','/bin/sh','s3-init','-c',setup+'mc rm --recursive --force local/messenger-attachments/'+prefix+' >/dev/null')
|
|
assert all(r['deleted_objects']==0 and r['deleted_metadata']==0 for r in results)
|
|
(ROOT/'evidence/inventory-cost.json').write_text(json.dumps({'method':'same existing dataset plus 0/100/1000 fresh synthetic keys; dry-run; CLI API limits; no metadata mutation; temporary prefix removed','runs':results},indent=2)+'\n')
|
|
print('PASS: dry-run costs measured at +0/+100/+1000 keys, probe prefix removed')
|