clan-vm-manager: Fix regression
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import os
|
import os
|
||||||
@@ -7,7 +8,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any, get_type_hints
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -109,6 +110,21 @@ def spawn(
|
|||||||
if mp.get_start_method(allow_none=True) is None:
|
if mp.get_start_method(allow_none=True) is None:
|
||||||
mp.set_start_method(method="forkserver")
|
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
|
# Set names
|
||||||
proc_name = f"MPExec:{func.__name__}"
|
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.dirs import vm_state_dir
|
||||||
from clan_cli.history.add import HistoryEntry
|
from clan_cli.history.add import HistoryEntry
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
|
from clan_cli.vms.inspect import inspect_vm
|
||||||
from clan_cli.vms.qemu import QMPWrapper
|
from clan_cli.vms.qemu import QMPWrapper
|
||||||
|
|
||||||
from clan_vm_manager.components.executor import MPProcess, spawn
|
from clan_vm_manager.components.executor import MPProcess, spawn
|
||||||
@@ -224,14 +225,15 @@ class VMObject(GObject.Object):
|
|||||||
return
|
return
|
||||||
log.info(f"Successfully built VM {self.get_id()}")
|
log.info(f"Successfully built VM {self.get_id()}")
|
||||||
|
|
||||||
|
vm_config = inspect_vm(machine)
|
||||||
|
|
||||||
# Start the VM
|
# Start the VM
|
||||||
self.vm_process = spawn(
|
self.vm_process = spawn(
|
||||||
on_except=None,
|
on_except=None,
|
||||||
out_file=Path(str(self.log_dir.name)) / "vm.log",
|
out_file=Path(str(self.log_dir.name)) / "vm.log",
|
||||||
func=vms.run.run_vm,
|
func=vms.run.run_vm,
|
||||||
vm=self.data.flake.vm,
|
vm_config=vm_config,
|
||||||
cachedir=log_dir,
|
runtime_config=vms.run.RuntimeConfig(),
|
||||||
socketdir=log_dir,
|
|
||||||
)
|
)
|
||||||
log.debug(f"Started VM {self.get_id()}")
|
log.debug(f"Started VM {self.get_id()}")
|
||||||
GLib.idle_add(self._vm_status_changed_task)
|
GLib.idle_add(self._vm_status_changed_task)
|
||||||
|
|||||||
Reference in New Issue
Block a user