aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-13 20:49:56 +0100
committerDanilo M. <danix@danix.xyz>2026-11-13 20:49:56 +0100
commit896163d7961d86b4e023a50ce4f6e19a30006a3f (patch)
tree9a2266a1120f8913616991d9350fa6667c248f0e /tests
parent69e6ce2bf7272797cf08ee4fbe0ff9fe0fc3b1f4 (diff)
downloaddeck-it-896163d7961d86b4e023a50ce4f6e19a30006a3f.tar.gz
deck-it-896163d7961d86b4e023a50ce4f6e19a30006a3f.zip
feat(vm): tablet tiles with screen, trends and a power button
Each VM is a tile: its screen from virsh screenshot (JPEG through ffmpeg, every 5s while the tab shows), booting until sshd answers at the ssh -G host and port, CPU and RAM trends, and a big power button, tap for the gentle action and hold to force off. A tap on the tile opens a sheet with every action as an icon and the snapshots as a timeline with their age. hold.js is now the one press and hold, K1C's stop included, and vibrates the tablet when it fires; the Windows long-press buzzes too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_vm.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/test_vm.py b/tests/test_vm.py
index b84ec97..10791dc 100644
--- a/tests/test_vm.py
+++ b/tests/test_vm.py
@@ -31,6 +31,8 @@ DOMSTATS = """Domain: 'alpha'
state.reason=1
cpu.time={ns}
balloon.current=4194304
+ balloon.available=4000000
+ balloon.usable=3000000
vcpu.current=2
Domain: 'beta'
@@ -50,6 +52,7 @@ class Fake:
self.ns = 1_000_000_000
self.fail = None
self.kitty_ok = True
+ self.listening = set()
def __call__(self, cmd, timeout=10):
self.cmds.append(cmd)
@@ -59,7 +62,17 @@ class Fake:
elif cmd[:2] == ["virsh", "dominfo"]:
out = "Managed save: yes\n" if cmd[2] == "beta" else "Managed save: no\n"
elif cmd[:2] == ["virsh", "snapshot-list"]:
- out = "clean\nworking\n\n" if cmd[2] == "alpha" else ""
+ out = (" Name Creation Time State\n----\n"
+ " clean 2026-03-06 10:27:47 +0100 shutoff\n"
+ " working 2026-04-04 16:00:51 +0200 running\n\n") if cmd[2] == "alpha" else ""
+ elif cmd[:2] == ["virsh", "snapshot-current"]:
+ out, code = ("working\n", 0) if cmd[-1] == "alpha" else ("", 1)
+ elif cmd[:2] == ["ssh", "-G"]:
+ out = "user root\nhostname 192.0.2.9\nport 2290\n" if cmd[2] == "alpha" else f"hostname {cmd[2]}\nport 22\n"
+ elif cmd[:2] == ["virsh", "screenshot"]:
+ Path(cmd[cmd.index("--file") + 1]).write_bytes(b"P6 1 1 255 ...")
+ elif cmd[0] == "ffmpeg":
+ Path(cmd[-1]).write_bytes(b"JPEG")
elif cmd[:2] == ["virsh", "domifaddr"]:
out = (" Name MAC address Protocol Address\n---\n"
" lo 00:00:00:00:00:00 ipv4 127.0.0.1/8\n"
@@ -72,7 +85,8 @@ class Fake:
def make(fake, now, **extra):
- cfg = {"run": fake, "clock": lambda: now[0], "spawn": lambda f: f(), "hyprland": "classic"}
+ cfg = {"run": fake, "clock": lambda: now[0], "spawn": lambda f: f(), "hyprland": "classic",
+ "probe": lambda host, port: (host, port) in fake.listening}
cfg.update(extra)
return vm.make(cfg)
@@ -90,13 +104,31 @@ class VmTest(unittest.TestCase):
self.assertEqual((a["name"], a["state"], a["vcpus"]), ("alpha", "running", 2))
self.assertIsNone(a["cpu"]) # one sample: no rate yet
self.assertEqual(a["mem"], 4194304 * 1024)
+ self.assertEqual(a["used"], 1000000 * 1024)
+ self.assertIsNone(b["used"])
self.assertEqual(a["ip"], "192.0.2.5")
- self.assertEqual(a["snapshots"], ["clean", "working"])
+ self.assertEqual([s["name"] for s in a["snapshots"]], ["clean", "working"])
+ self.assertEqual(a["snapshots"][0]["created"], 1772789267)
+ self.assertEqual([s["current"] for s in a["snapshots"]], [False, True])
self.assertEqual((b["state"], b["saved"], b["ip"]), ("shut off", True, ""))
self.fake.ns += 1_000_000_000 # 1 s of CPU over 2 s, 2 vCPUs
self.now[0] += 2
self.assertAlmostEqual(self.mod.state()["vms"][0]["cpu"], 25.0)
+ def test_ssh_ready_from_ssh_alias(self):
+ st = self.mod.state()
+ self.assertEqual((st["vms"][0]["ready"], st["vms"][1]["ready"]), (False, None))
+ self.fake.listening.add(("192.0.2.9", 2290)) # alias host and port, not the agent IP
+ self.now[0] += 2 # booting: re-probed within seconds
+ self.mod.state()
+ self.assertTrue(self.mod.state()["vms"][0]["ready"])
+
+ def test_screenshot_only_for_running_vm(self):
+ self.mod.state()
+ self.assertEqual(self.mod.image("alpha"), (b"JPEG", "image/jpeg"))
+ self.assertIsNone(self.mod.image("beta")) # shut off
+ self.assertIsNone(self.mod.image("../etc"))
+
def test_offline(self):
self.fake.fail = "domstats"
st = self.mod.state()