Add guarded deletion of obsolete llama.cpp builds
This commit is contained in:
1 parent
b9cf08ea7e
commit
8d537ab9ef
5 files changed
+86
-3
No files matched your search
@@ -53,6 +53,46 @@ class RuntimeTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):r.activate('../unknown')
|
||||
r.activate('one');r.activate('two');r.rollback()
|
||||
self.assertEqual(Runtime(d).status()['active'],'one')
|
||||
def deletion_fixture(self,d):
|
||||
r=Runtime(d);a='a'*32;b='b'*32;c='c'*32
|
||||
r.state.update(builds=[{'id':x} for x in (a,b,c)],active=a,previous=b)
|
||||
for x in (a,b,c):(Path(d)/x).mkdir();(Path(d)/x/'binary').write_text('build')
|
||||
return r,a,b,c
|
||||
def test_delete_old_build_and_persist(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
r,a,b,c=self.deletion_fixture(d);r.delete(c)
|
||||
self.assertFalse((Path(d)/c).exists());self.assertEqual([x['id'] for x in Runtime(d).status()['builds']],[a,b])
|
||||
def test_delete_protects_standard_and_requires_rollback_confirmation(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
r,a,b,c=self.deletion_fixture(d)
|
||||
with self.assertRaisesRegex(ValueError,'Standard'):r.delete(a)
|
||||
with self.assertRaisesRegex(ValueError,'Rückfall'):r.delete(b)
|
||||
r.delete(b,True);self.assertIsNone(r.status()['previous']);self.assertTrue((Path(d)/a).exists())
|
||||
def test_delete_rejects_paths_busy_and_running_process(self):
|
||||
from unittest.mock import Mock
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
r,a,b,c=self.deletion_fixture(d)
|
||||
for x in ('../outside',None,'unknown'):
|
||||
with self.assertRaises(ValueError):r.delete(x)
|
||||
r.busy=True
|
||||
with self.assertRaisesRegex(ValueError,'Build oder'):r.delete(c)
|
||||
r.busy=False;r.fitting=True
|
||||
with self.assertRaisesRegex(ValueError,'Speicherprognose'):r.delete(c)
|
||||
r.fitting=False;r.deletion_guard=lambda:'Modellwechsel läuft'
|
||||
with self.assertRaisesRegex(ValueError,'Modellwechsel'):r.delete(c)
|
||||
r.deletion_guard=lambda:None;proc=Mock();proc.__truediv__=Mock(return_value=proc);proc.resolve.return_value=(Path(d)/c/'binary').resolve()
|
||||
with patch('runtime.Path.glob',return_value=[proc]):
|
||||
with self.assertRaisesRegex(ValueError,'laufenden Prozess'):r.delete(c)
|
||||
self.assertTrue((Path(d)/c).exists())
|
||||
def test_delete_owned_verification_symlink_but_not_external_target(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
root=Path(d)/'runtime';root.mkdir();r,a,b,c=self.deletion_fixture(root)
|
||||
import shutil
|
||||
shutil.rmtree(root/c);target=Path(d)/'runtime-verification'/c;target.mkdir(parents=True);(root/c).symlink_to(target)
|
||||
r.delete(c);self.assertFalse(target.exists());self.assertFalse((root/c).is_symlink())
|
||||
shutil.rmtree(root/b);outside=Path(d)/'outside'/b;outside.mkdir(parents=True);(root/b).symlink_to(outside)
|
||||
with self.assertRaisesRegex(ValueError,'Build-Pfad'):r.delete(b,True)
|
||||
self.assertTrue(outside.exists())
|
||||
def test_restart_marks_interrupted(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
r=Runtime(d);r.state['job']={'state':'running'};r.save()
|
||||
|
||||
Reference in new issue
Block a user