feat(vm): resume a paused VM, and list it as paused (NetOrk/netork#2658)
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 52s
driver / test (3.12) (pull_request) Successful in 1m1s
driver / test (3.13) (pull_request) Successful in 56s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m13s
CI / driver (pull_request) Successful in 2m43s
driver / publish (pull_request) Skipped

suspend_vm paused a QEMU guest that nothing could bring back: start is
refused because PVE still says the guest is running. resume_vm posts
status/resume for a paused VM and refuses a container or a guest that is
not paused. get_vms() asks for the full status and reports a guest whose
qmpstatus is paused or suspended as paused, not running.
This commit is contained in:
Christian Manivong committed 2026-11-25 21:28:46 +01:00
1 parent 449230c624
commit 93c974b8f0
4 files changed
+109 -4

No files matched your search

+60
View File
@@ -41,6 +41,43 @@ class TestGetVmsReportsStringIds:
assert [vm["vmid"] for vm in driver.get_vms()] == ["99", "1000"]
class TestGetVmsTellsPausedFromRunning:
"""PVE reports a paused guest ``status: running``; only ``qmpstatus`` tells, and only
when the listing is asked for the full status (NetOrk/netork#2658)."""
@pytest.fixture
def listed(self, driver, api):
driver.get_vm_interfaces = MagicMock(return_value=({}, False, False))
driver._get_vm_disk_and_boot = MagicMock(return_value=([], False))
api.lxc.get.return_value = []
def statuses(*qemu):
api.qemu.get.return_value = [
{"vmid": 100 + i, "name": f"vm{i}", **row} for i, row in enumerate(qemu)
]
return {vm["vmid"]: vm["status"] for vm in driver.get_vms()}
return statuses
def test_the_listing_asks_for_the_full_status(self, listed, api):
listed({"status": "running", "qmpstatus": "running"})
api.qemu.get.assert_called_once_with(full=1)
def test_a_paused_guest_is_paused(self, listed):
assert listed({"status": "running", "qmpstatus": "paused"}) == {"100": "paused"}
def test_a_guest_asleep_in_s3_is_paused(self, listed):
"""Its QEMU process still holds its memory; ``status/resume`` wakes it."""
assert listed({"status": "running", "qmpstatus": "suspended"}) == {"100": "paused"}
def test_running_and_stopped_stay_as_they_are(self, listed):
assert listed(
{"status": "running", "qmpstatus": "running"},
{"status": "stopped", "qmpstatus": "stopped"},
{"status": "running"},
) == {"100": "running", "101": "stopped", "102": "running"}
class TestResolveVm:
def test_by_vmid_string(self, driver, api):
assert driver._resolve_vm("100") == (100, "vm")
@@ -84,6 +121,29 @@ class TestPowerActions:
with pytest.raises(RuntimeError, match="container"):
driver.suspend_vm("200")
@pytest.mark.parametrize("qmpstatus", ["paused", "suspended"])
def test_resume_posts_status_resume_and_waits(self, driver, api, qmpstatus):
guest = api.qemu.return_value
guest.status.current.get.return_value = {"status": "running", "qmpstatus": qmpstatus}
guest.status.resume.post.return_value = "UPID:resume"
driver.resume_vm("web01")
guest.status.resume.post.assert_called_once()
driver._wait_for_task.assert_called_once_with("UPID:resume", timeout=120)
@pytest.mark.parametrize(
"current", [{"status": "running", "qmpstatus": "running"}, {"status": "stopped"}]
)
def test_resume_of_a_guest_that_is_not_paused_is_refused(self, driver, api, current):
api.qemu.return_value.status.current.get.return_value = current
with pytest.raises(RuntimeError, match="not paused"):
driver.resume_vm("100")
api.qemu.return_value.status.resume.post.assert_not_called()
def test_resume_of_a_container_is_refused(self, driver, api):
with pytest.raises(RuntimeError, match="container 200"):
driver.resume_vm("200")
api.lxc.return_value.status.resume.post.assert_not_called()
def test_api_error_becomes_runtime_error(self, driver, api):
api.qemu.return_value.status.start.post.side_effect = Exception("locked")
with pytest.raises(RuntimeError, match="locked"):