Ship trust-first CLI and runtime defaults
This commit is contained in:
parent
fb718af154
commit
5d63e4c16e
26 changed files with 894 additions and 134 deletions
|
|
@ -22,6 +22,7 @@ def test_vm_manager_lifecycle_and_auto_cleanup(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)
|
||||
vm_id = str(created["vm_id"])
|
||||
started = manager.start_vm(vm_id)
|
||||
|
|
@ -47,6 +48,7 @@ def test_vm_manager_exec_timeout(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
manager.start_vm(vm_id)
|
||||
|
|
@ -67,6 +69,7 @@ def test_vm_manager_stop_and_delete(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
manager.start_vm(vm_id)
|
||||
|
|
@ -89,6 +92,7 @@ def test_vm_manager_reaps_expired(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=1,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
instance = manager._instances[vm_id] # noqa: SLF001
|
||||
|
|
@ -112,6 +116,7 @@ def test_vm_manager_reaps_started_vm(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=1,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
manager.start_vm(vm_id)
|
||||
|
|
@ -145,9 +150,21 @@ def test_vm_manager_max_active_limit(tmp_path: Path) -> None:
|
|||
max_active_vms=1,
|
||||
network_manager=TapNetworkManager(enabled=False),
|
||||
)
|
||||
manager.create_vm(environment="debian:12-base", vcpu_count=1, mem_mib=512, ttl_seconds=600)
|
||||
manager.create_vm(
|
||||
environment="debian:12-base",
|
||||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)
|
||||
with pytest.raises(RuntimeError, match="max active VMs reached"):
|
||||
manager.create_vm(environment="debian:12-base", vcpu_count=1, mem_mib=512, ttl_seconds=600)
|
||||
manager.create_vm(
|
||||
environment="debian:12-base",
|
||||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)
|
||||
|
||||
|
||||
def test_vm_manager_state_validation(tmp_path: Path) -> None:
|
||||
|
|
@ -162,6 +179,7 @@ def test_vm_manager_state_validation(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
with pytest.raises(RuntimeError, match="must be in 'started' state"):
|
||||
|
|
@ -186,6 +204,7 @@ def test_vm_manager_status_expired_raises(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=1,
|
||||
allow_host_compat=True,
|
||||
)["vm_id"]
|
||||
)
|
||||
manager._instances[vm_id].expires_at = 0.0 # noqa: SLF001
|
||||
|
|
@ -213,6 +232,7 @@ def test_vm_manager_network_info(tmp_path: Path) -> None:
|
|||
vcpu_count=1,
|
||||
mem_mib=512,
|
||||
ttl_seconds=600,
|
||||
allow_host_compat=True,
|
||||
)
|
||||
vm_id = str(created["vm_id"])
|
||||
status = manager.status_vm(vm_id)
|
||||
|
|
@ -236,6 +256,7 @@ def test_vm_manager_run_vm(tmp_path: Path) -> None:
|
|||
timeout_seconds=30,
|
||||
ttl_seconds=600,
|
||||
network=False,
|
||||
allow_host_compat=True,
|
||||
)
|
||||
assert int(result["exit_code"]) == 0
|
||||
assert str(result["stdout"]) == "ok\n"
|
||||
|
|
@ -283,3 +304,33 @@ def test_vm_manager_firecracker_backend_path(
|
|||
network_manager=TapNetworkManager(enabled=False),
|
||||
)
|
||||
assert manager._backend_name == "firecracker" # noqa: SLF001
|
||||
|
||||
|
||||
def test_vm_manager_fails_closed_without_host_compat_opt_in(tmp_path: Path) -> None:
|
||||
manager = VmManager(
|
||||
backend_name="mock",
|
||||
base_dir=tmp_path / "vms",
|
||||
network_manager=TapNetworkManager(enabled=False),
|
||||
)
|
||||
vm_id = str(
|
||||
manager.create_vm(
|
||||
environment="debian:12-base",
|
||||
ttl_seconds=600,
|
||||
)["vm_id"]
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="guest boot is unavailable"):
|
||||
manager.start_vm(vm_id)
|
||||
|
||||
|
||||
def test_vm_manager_uses_canonical_default_cache_dir(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
monkeypatch.setenv("PYRO_ENVIRONMENT_CACHE_DIR", str(tmp_path / "cache"))
|
||||
manager = VmManager(
|
||||
backend_name="mock",
|
||||
base_dir=tmp_path / "vms",
|
||||
network_manager=TapNetworkManager(enabled=False),
|
||||
)
|
||||
|
||||
assert manager._environment_store.cache_dir == tmp_path / "cache" # noqa: SLF001
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue