Refactor public API around environments

This commit is contained in:
Thales Maciel 2026-03-08 16:02:02 -03:00
parent 57dae52cc2
commit 5d5243df23
41 changed files with 1301 additions and 459 deletions

View file

@ -1,4 +1,4 @@
"""Direct Firecracker boot validation for a bundled runtime profile."""
"""Direct Firecracker boot validation for a curated environment."""
from __future__ import annotations
@ -12,13 +12,13 @@ from pathlib import Path
from types import SimpleNamespace
from pyro_mcp.runtime import resolve_runtime_paths
from pyro_mcp.vm_environments import EnvironmentStore, get_environment
from pyro_mcp.vm_firecracker import build_launch_plan
from pyro_mcp.vm_profiles import get_profile
@dataclass(frozen=True)
class BootCheckResult:
profile: str
environment: str
workdir: Path
firecracker_started: bool
vm_alive_after_wait: bool
@ -49,30 +49,31 @@ def _classify_result(*, firecracker_log: str, serial_log: str, vm_alive: bool) -
def run_boot_check(
*,
profile: str = "debian-base",
environment: str = "debian:12-base",
vcpu_count: int = 1,
mem_mib: int = 1024,
wait_seconds: int = 8,
keep_workdir: bool = False,
) -> BootCheckResult: # pragma: no cover - integration helper
get_profile(profile)
get_environment(environment)
if wait_seconds <= 0:
raise ValueError("wait_seconds must be positive")
runtime_paths = resolve_runtime_paths()
profile_dir = runtime_paths.artifacts_dir / profile
environment_store = EnvironmentStore(runtime_paths=runtime_paths)
installed_environment = environment_store.ensure_installed(environment)
workdir = Path(tempfile.mkdtemp(prefix="pyro-boot-check-"))
try:
rootfs_copy = workdir / "rootfs.ext4"
shutil.copy2(profile_dir / "rootfs.ext4", rootfs_copy)
shutil.copy2(installed_environment.rootfs_image, rootfs_copy)
instance = SimpleNamespace(
vm_id="abcd00000001",
vcpu_count=vcpu_count,
mem_mib=mem_mib,
workdir=workdir,
metadata={
"kernel_image": str(profile_dir / "vmlinux"),
"kernel_image": str(installed_environment.kernel_image),
"rootfs_image": str(rootfs_copy),
},
network=None,
@ -114,7 +115,7 @@ def run_boot_check(
vm_alive=vm_alive,
)
return BootCheckResult(
profile=profile,
environment=environment,
workdir=workdir,
firecracker_started="Successfully started microvm" in firecracker_log,
vm_alive_after_wait=vm_alive,
@ -131,7 +132,7 @@ def run_boot_check(
def main() -> None: # pragma: no cover - CLI wiring
parser = argparse.ArgumentParser(description="Run a direct Firecracker boot check.")
parser.add_argument("--profile", default="debian-base")
parser.add_argument("--environment", default="debian:12-base")
parser.add_argument("--vcpu-count", type=int, default=1)
parser.add_argument("--mem-mib", type=int, default=1024)
parser.add_argument("--wait-seconds", type=int, default=8)
@ -140,13 +141,13 @@ def main() -> None: # pragma: no cover - CLI wiring
args = parser.parse_args()
result = run_boot_check(
profile=args.profile,
environment=args.environment,
vcpu_count=args.vcpu_count,
mem_mib=args.mem_mib,
wait_seconds=args.wait_seconds,
keep_workdir=args.keep_workdir,
)
print(f"[boot] profile={result.profile}")
print(f"[boot] environment={result.environment}")
print(f"[boot] firecracker_started={result.firecracker_started}")
print(f"[boot] vm_alive_after_wait={result.vm_alive_after_wait}")
print(f"[boot] process_returncode={result.process_returncode}")