feat: add independent VM manager

This commit is contained in:
Codex
2026-10-13 04:04:30 +03:00
parent e6bec555c4
commit d7d01a4520
9 changed files with 1020 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
import tempfile
import unittest
from pathlib import Path
from hydra.profiles import Profile, load_profile, save_profile
class ProfilesTests(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory(prefix='hydra-test-')
self.addCleanup(self.tmp.cleanup)
self.root = Path(self.tmp.name)
self.iso = self.root / 'installer with spaces,comma.iso'
self.iso.touch()
def test_roundtrip_paths_and_defaults(self):
profile = Profile('guest', self.iso)
save_profile(self.root / 'guest.toml', profile)
loaded = load_profile(self.root / 'guest.toml')
self.assertEqual(loaded.iso, self.iso)
self.assertEqual((loaded.memory, loaded.cpus, loaded.disk_size), (4096, 2, '40G'))
self.assertEqual((loaded.graphics, loaded.network, loaded.bridge), ('auto', 'user', 'hydrabr0'))
def test_invalid_names_resources_and_modes(self):
for name in ('', '../guest', 'Guest', '-guest', 'a' * 33, 'a\n'):
with self.subTest(name=name), self.assertRaises(ValueError):
Profile(name, self.iso)
for field, values in {'memory': (0, -1, True, '4096'), 'cpus': (0, -1, True, 257),
'disk_size': ('0G', '-1G', '40G,evil', '40'),
'graphics': ('gl',), 'network': ('public',),
'bridge': ('../bad', 'a,evil')}.items():
for value in values:
with self.subTest(field=field, value=value), self.assertRaises(ValueError):
Profile('guest', self.iso, **{field: value})
def test_missing_iso_and_duplicate_profile_preserve_existing(self):
with self.assertRaises(ValueError):
Profile('guest', self.root / 'missing.iso')
dest = self.root / 'guest.toml'
save_profile(dest, Profile('guest', self.iso))
original = dest.read_bytes()
with self.assertRaises(FileExistsError):
save_profile(dest, Profile('guest', self.iso, memory=8192))
self.assertEqual(dest.read_bytes(), original)
def test_profile_name_must_match_filename(self):
path = self.root / 'guest.toml'
path.write_text(f'name = "other"\niso = "{self.iso}"\n')
with self.assertRaises(ValueError):
load_profile(path)
if __name__ == '__main__':
unittest.main()