UI: Display error logs on VM crash. Fixed inspect_vm problem.
All checks were successful
checks-impure / test (pull_request) Successful in 1m32s
checks / test (pull_request) Successful in 2m41s

This commit is contained in:
Luis Hebendanz 2024-01-29 15:11:57 +07:00
parent 155a1ee98c
commit f6c811e531
4 changed files with 22 additions and 28 deletions

View File

@ -35,6 +35,7 @@ class Machine:
self.deployment_info = json.loads(
self.build_nix("config.system.clan.deployment.file").read_text()
)
print(f"self_deployment_info: {self.deployment_info}")
@property
def deployment_address(self) -> str:
@ -46,6 +47,7 @@ class Machine:
def secrets_module(self) -> str:
if not hasattr(self, "deployment_info"):
self.get_deployment_info()
print(f"self_deployment_info2: {self.deployment_info}")
return self.deployment_info["secretsModule"]
@property
@ -77,7 +79,8 @@ class Machine:
return Path(self.flake_path)
print(nix_eval([f"{self.flake}"]))
self.flake_path = run(nix_eval([f"{self.flake}"])).stdout.strip()
print(f"self.flake:{self.flake}. Type: {type(self.flake)}")
self.flake_path = run(nix_eval([f"{self.flake} "])).stdout.strip()
return Path(self.flake_path)
@property
@ -95,6 +98,7 @@ class Machine:
system = config["system"]
attr = f'clanInternals.machines."{system}".{self.name}.{attr}'
print(f"attr: {attr}")
if attr in self.eval_cache and not refresh:
return self.eval_cache[attr]
@ -107,8 +111,10 @@ class Machine:
else:
flake = self.flake
log.info(f"evaluating {flake}#{attr}")
output = run(nix_eval([f"{flake}#{attr}"])).stdout.strip()
print(f"evaluating {flake}#{attr}")
cmd = nix_eval([f"{flake}#{attr}"])
print(f"cmd: {cmd}")
output = run(cmd).stdout.strip()
self.eval_cache[attr] = output
return output

View File

@ -18,7 +18,7 @@ from collections.abc import Callable
# Kill the new process and all its children by sending a SIGTERM signal to the process group
def _kill_group(proc: mp.Process) -> None:
pid = proc.pid
if proc.is_alive():
if proc.is_alive() and pid:
os.killpg(pid, signal.SIGTERM)
else:
print(f"Process {proc.name} with pid {pid} is already dead", file=sys.stderr)

View File

@ -1,7 +1,5 @@
import sys
import tempfile
import weakref
from collections.abc import Callable
from pathlib import Path
from typing import Any, ClassVar
@ -18,12 +16,12 @@ from clan_vm_manager.models.interfaces import VMStatus
from .executor import MPProcess, spawn
gi.require_version("Gtk", "4.0")
import threading
from gi.repository import Gio, GLib, GObject
import logging
import multiprocessing as mp
import threading
from clan_cli.machines.machines import Machine
from gi.repository import Gio, GLib, GObject
log = logging.getLogger(__name__)
@ -57,11 +55,9 @@ class VM(GObject.Object):
return
machine = Machine(
name=self.data.flake.flake_attr,
flake=self.data.flake.flake_url,
)
vm = vms.run.inspect_vm(
machine
flake=Path(self.data.flake.flake_url),
)
vm = vms.run.inspect_vm(machine)
self.process = spawn(
on_except=None,
log_dir=Path(str(self.log_dir.name)),
@ -91,7 +87,7 @@ class VM(GObject.Object):
self._last_liveness = self.is_running()
# If the VM was running and now it is not, remove the watcher
if prev_liveness == True and not self.is_running():
if prev_liveness and not self.is_running():
return GLib.SOURCE_REMOVE
return GLib.SOURCE_CONTINUE

View File

@ -1,5 +1,6 @@
from collections.abc import Callable
from functools import partial
import gi
from clan_cli.history.add import HistoryEntry
@ -7,7 +8,7 @@ from clan_vm_manager.models.use_join import Join, JoinValue
from clan_vm_manager.models.use_views import Views
gi.require_version("Adw", "1")
from gi.repository import Adw, Gdk, Gio, GObject, Gtk
from gi.repository import Adw, Gio, GObject, Gtk
from clan_vm_manager.models.use_vms import VM, VMS
@ -77,7 +78,7 @@ class ClanList(Gtk.Box):
boxed_list.remove_css_class("no-shadow")
flake = vm.data.flake
row = Adw.ActionRow()
# Title
row.set_title(flake.clan_name)
@ -144,22 +145,18 @@ class ClanList(Gtk.Box):
return row
def show_error_dialog(self, error: str) -> None:
p = Views.use().main_window
# app = Gio.Application.get_default()
# p = Gtk.Application.get_active_window(app)
dialog = Adw.MessageDialog(
heading="Error"
)
dialog = Adw.MessageDialog(heading="Error")
dialog.add_response("ok", "ok")
dialog.set_body(error)
dialog.set_transient_for(p) # set the parent window of the dialog
dialog.set_transient_for(p) # set the parent window of the dialog
dialog.choose()
def on_trust_clicked(self, item: JoinValue, widget: Gtk.Widget) -> None:
def on_join(_history: list[HistoryEntry]) -> None:
VMS.use().refresh()
@ -189,14 +186,9 @@ class ClanList(Gtk.Box):
row.set_state(True)
vm.stop()
def vm_status_changed(self, switch: Gtk.Switch, vm: VM, _vm: VM) -> None:
switch.set_active(vm.is_running())
switch.set_state(vm.is_running())
if vm.process and vm.process.proc.exitcode != 0:
print(f"====== {vm.is_running()}")
if not vm.is_running() and vm.process.proc.exitcode != 0:
self.show_error_dialog(vm.read_log())