ops: protect mounted test artifacts and document capacity adoption gate
Owned disk maintenance only / maintenance (push) Successful in 11s

This commit is contained in:
Canina Hermes committed 2026-11-19 07:33:24 +00:00
1 parent 6dec2c1469
commit 63ced7b44a
3 files changed
+41 -2

No files matched your search

+7 -2
View File
@@ -4,7 +4,7 @@ import pathlib,os,time,shutil,fcntl,subprocess,json,sys
BASE=pathlib.Path('/opt/services/canina/.managed-disk')
RESERVE=20*1024**3
def retire(root,now=None):
def retire(root,now=None,protected=()):
root=pathlib.Path(root);now=time.time() if now is None else now
if root.is_symlink() or root.resolve()!=root:raise RuntimeError('unsafe root')
removed=[]
@@ -13,6 +13,8 @@ def retire(root,now=None):
if p.is_symlink() or not p.is_dir() or p.resolve()!=p:continue
if not marker.is_file() or marker.is_symlink() or marker.read_text()!='canina-managed-test-v1\n':continue
if now-p.stat().st_mtime<7*86400:continue
if any(v==str(p) or v.startswith(str(p)+'/') or str(p).startswith(v.rstrip('/')+'/') for v in protected):continue
if os.path.ismount(p):continue
# Unknown/source-bearing contents are never eligible; symlinks are never followed.
if any(x.name in {'.git','.env','node_modules','vendor'} or x.is_symlink() or os.path.ismount(x) for x in p.rglob('*')):continue
users=[]
@@ -45,7 +47,10 @@ def main():
raise SystemExit(subprocess.call(sys.argv[2:]))
if busy():raise SystemExit('Active heavy work: retention deferred')
before=shutil.disk_usage(BASE).free
removed=retire(BASE/'tests')
ids=subprocess.check_output(['docker','ps','-aq'],text=True).split()
containers=json.loads(subprocess.check_output(['docker','inspect',*ids],text=True)) if ids else []
protected=[m['Source'] for c in containers for m in c['Mounts']]
removed=retire(BASE/'tests',protected=protected)
p=subprocess.run(['docker','builder','prune','--force','--filter','until=24h'],capture_output=True,text=True,timeout=300,check=True)
print(json.dumps({'removed_tests':removed,'docker_cache_result':p.stdout.strip(),'available_before':before,'available_after':shutil.disk_usage(BASE).free}))
if __name__=='__main__':main()
+5
View File
@@ -17,4 +17,9 @@ class Tests(unittest.TestCase):
try:self.assertEqual(m.retire(r),[])
finally:f.close()
self.assertEqual(m.retire(r),['busy'])
def test_mounted_artifact_is_preserved(self):
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
with tempfile.TemporaryDirectory() as d:
r=pathlib.Path(d);p=r/'mounted';p.mkdir();(p/'.disposable-test').write_text('canina-managed-test-v1\n');os.utime(p,(1,1))
self.assertEqual(m.retire(r,protected=[str(p/'result')]),[])
if __name__=='__main__':unittest.main()