From 3865fd7d10d76cd265800fd8d5915a5792be4619 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 19 Oct 2026 21:20:00 +0200 Subject: Dashboard: VM meters and sparklines, slackpkg tile sbb-remote 0.3.0 adds CPU busy % (two /proc/stat samples), RAM total and available, disk / total and free, and the last slackpkg update (LASTUPDATE) and package change (/var/log/packages), replacing disk_free. The Dashboard shows a VM card with meters for CPU, RAM and disk / (accent, warning from 80%, critical from 90%, value always printed) and CPU/RAM sparklines from this session's polls, and a slackpkg tile in place of VM load. Co-Authored-By: Claude Opus 5.5 --- tests/test_remote.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/test_remote.py') diff --git a/tests/test_remote.py b/tests/test_remote.py index c2b9857..2f273fb 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -391,11 +391,38 @@ class StatsTest(Base): def test_missing_sources_are_null(self): s = sbb.cmd_stats(self.cfg) self.assertIsNotNone(s["load"]) + self.assertEqual(set(s["disk"]), {"total", "free"}) + self.assertIn("slackpkg", s) self.assertIsNone(s["packages"]) self.assertIsNone(s["slackrepo"]) self.assertEqual(s["sync"], {"personal": None, "pentesting": None}) json.dumps(s) + def test_vm_figures(self): + meminfo = os.path.join(self.tmp, "meminfo") + with open(meminfo, "w") as f: + f.write("MemTotal: 16000 kB\nMemFree: 9000 kB\nMemAvailable: 12000 kB\n") + self.assertEqual(sbb._meminfo(meminfo), {"total": 16000 * 1024, "available": 12000 * 1024}) + with mock.patch.object(sbb, "_cpu_times", side_effect=[(100, 1000), (150, 1100)]), \ + mock.patch.object(sbb.time, "sleep"): + self.assertEqual(sbb._cpu(), 50.0) + stat = os.path.join(self.tmp, "stat") + with open(stat, "w") as f: + f.write("cpu 10 0 10 70 10 0 0 0 0 0\ncpu0 1 2 3 4\n") + self.assertEqual(sbb._cpu_times(stat), (20, 100)) # idle + iowait count as not busy + + def test_slackpkg_times(self): + last = os.path.join(self.tmp, "LASTUPDATE") + with open(last, "w") as f: + f.write("1791760212\n") + pkgs = os.path.join(self.tmp, "packages") + os.mkdir(pkgs) + for name, t in (("a-1-x86_64-1", 1000), ("b-2-x86_64-1", 3000)): + open(os.path.join(pkgs, name), "w").close() + os.utime(os.path.join(pkgs, name), (t, t)) + self.assertEqual(sbb._slackpkg(last, pkgs), {"update": 1791760212, "upgrade": 3000}) + self.assertEqual(sbb._slackpkg("/nonexistent", "/nonexistent"), {"update": None, "upgrade": None}) + def test_counts(self): r = self.cfg["repo_dir"] for p in ("cat/foo", "cat/bar", "personal/foo", "personal/baz", "pentesting/nmap"): -- cgit v1.2.3