clan-vm-manager: Fix regression
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import dataclasses
|
||||
import inspect
|
||||
import logging
|
||||
import multiprocessing as mp
|
||||
import os
|
||||
@@ -7,7 +8,7 @@ import sys
|
||||
import traceback
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, get_type_hints
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -109,6 +110,21 @@ def spawn(
|
||||
if mp.get_start_method(allow_none=True) is None:
|
||||
mp.set_start_method(method="forkserver")
|
||||
|
||||
# Validate kwargs against the signature of func
|
||||
func_signature = inspect.signature(func)
|
||||
bound_args = func_signature.bind_partial(**kwargs)
|
||||
bound_args.apply_defaults() # Ensure defaults are applied to missing args
|
||||
|
||||
# Type-check kwargs against func's annotations
|
||||
type_hints = get_type_hints(func)
|
||||
for arg_name, arg_value in kwargs.items():
|
||||
if arg_name in type_hints:
|
||||
expected_type = type_hints[arg_name]
|
||||
if not isinstance(arg_value, expected_type):
|
||||
msg = f"Argument '{arg_name}' must be of type {expected_type}, but got type {type(arg_value)}"
|
||||
|
||||
raise TypeError(msg)
|
||||
|
||||
# Set names
|
||||
proc_name = f"MPExec:{func.__name__}"
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from clan_cli.clan_uri import ClanURI
|
||||
from clan_cli.dirs import vm_state_dir
|
||||
from clan_cli.history.add import HistoryEntry
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.vms.inspect import inspect_vm
|
||||
from clan_cli.vms.qemu import QMPWrapper
|
||||
|
||||
from clan_vm_manager.components.executor import MPProcess, spawn
|
||||
@@ -224,14 +225,15 @@ class VMObject(GObject.Object):
|
||||
return
|
||||
log.info(f"Successfully built VM {self.get_id()}")
|
||||
|
||||
vm_config = inspect_vm(machine)
|
||||
|
||||
# Start the VM
|
||||
self.vm_process = spawn(
|
||||
on_except=None,
|
||||
out_file=Path(str(self.log_dir.name)) / "vm.log",
|
||||
func=vms.run.run_vm,
|
||||
vm=self.data.flake.vm,
|
||||
cachedir=log_dir,
|
||||
socketdir=log_dir,
|
||||
vm_config=vm_config,
|
||||
runtime_config=vms.run.RuntimeConfig(),
|
||||
)
|
||||
log.debug(f"Started VM {self.get_id()}")
|
||||
GLib.idle_add(self._vm_status_changed_task)
|
||||
|
||||
Reference in New Issue
Block a user