Show live usage: CPU % and Mem % in the table, in-use on the info screen
CI / pytest and ruff (pull_request) Successful in 3m49s
CI / pytest and ruff (push) Has been cancelled

The guest table gets two last columns, CPU % (cpu * 100) and Mem %
(mem / maxmem), each with one decimal. They show "-" for a guest that
is not running or lacks the field.

The info screen's Resources table gets a header and an "In use"
column: CPU %, memory MiB with %, swap for containers, and rootfs used
GiB with % for containers. VM disks show "-", because the API reports
0 without guest-agent disk info. The info screen reads status and
usage in one status/current call (new cli.current).

After an action, the acted guest's status and usage both come from
status/current, so a guest that has just started no longer shows the
lagging listing's 0.0 %.

One blind-written test expected a VM's CPU cell to read "4 cores". VMs
have always shown sockets ("4 cores × 1 socket", as the resources
spec and its tests define), so that expectation was corrected.

Closes #12

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #24.
This commit is contained in:
DuckbootandClaude Opus 5.5 committed 2026-11-02 23:52:32 +01:00
1 parent 8c2b48a04c
commit eec65e0585
6 files changed
+356 -12

No files matched your search

+47
View File
@@ -374,6 +374,53 @@ def test_status_reads_live_status_current(fake):
]
# --- current (issue #12; spec: "Live usage" > cli.py) ------------------------------
def test_current_runs_status_current_for_lxc(fake):
fake.result = (json.dumps([{"key": "status", "value": "running"}]), "", 0)
cli.current(CT)
assert fake.argv == [
"cv4pve-cli", "api", "get", "/nodes/mainframe/lxc/100/status/current", "-o", "json",
] # fmt: skip
def test_current_runs_status_current_for_qemu(fake):
fake.result = (json.dumps([{"key": "status", "value": "running"}]), "", 0)
cli.current(VM)
assert fake.argv[3] == "/nodes/mainframe/qemu/108/status/current"
def test_current_flattens_key_value_list_to_dict(fake):
fake.result = (
json.dumps([
{"key": "status", "value": "running"}, {"key": "cpu", "value": 0.0538},
{"key": "mem", "value": 932048896}, {"key": "maxmem", "value": 8589934592},
{"key": "swap", "value": 0},
]),
"", 0,
) # fmt: skip
assert cli.current(CT) == {
"status": "running", "cpu": 0.0538, "mem": 932048896,
"maxmem": 8589934592, "swap": 0,
} # fmt: skip
def test_current_cli_failure_raises_clierror(monkeypatch):
FakeRun(monkeypatch, "Error: nope", "", 5)
with pytest.raises(cli.CliError):
cli.current(CT)
def test_status_still_returns_status_from_current_payload(fake):
fake.result = (
json.dumps([{"key": "cpu", "value": 0.5}, {"key": "status", "value": "running"}]),
"", 0,
) # fmt: skip
assert cli.status(VM) == "running"
assert fake.argv[3] == "/nodes/mainframe/qemu/108/status/current"
# --- contexts / use_context (spec: "Context switching" > cli.py) -------------
CONTEXT_LIST = (