feat(hypervisor): resume_vm, and a paused guest is never running (NetOrk/netork#2658)
driver / lint (pull_request) Successful in 12s
driver / standard (pull_request) Successful in 15s
driver / types (pull_request) Successful in 50s
driver / test (3.12) (pull_request) Successful in 1m8s
driver / lowest (pull_request) Successful in 36s
driver / test (3.13) (pull_request) Successful in 1m0s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 59s
CI / driver (pull_request) Successful in 2m24s
driver / publish (pull_request) Skipped

The contract could suspend a VM but not bring it back: suspend_vm pointed
at start_vm, which Proxmox refuses for a paused guest because it is still
running. resume_vm is declared beside suspend_vm, optional like every power
action, and get_vms() says a guest that is not executing is paused or
suspended, never running.
This commit is contained in:
christianmanivong committed 2026-11-25 21:26:37 +01:00
1 parent e729b935a4
commit cd47587e80
3 files changed
+63 -2

No files matched your search

+10
View File
@@ -17,6 +17,16 @@ recorded here; their history is the git log.
`noble-security`), once each new suite's `InRelease` or `Release` is fetched with apt's
downloader; nothing is written where the vendor has none.
- `parse_apt_releases`, `rewrite_release`, `suite_release`, `APT_RELEASES_COMMAND`.
- `HypervisorDriver.resume_vm(name)`: bring a paused or suspended VM back where it stopped,
the counterpart of `suspend_vm` (NetOrk/netork#2658). Optional like every power action;
a driver that can resume some guests but not others refuses the others with
`RuntimeError`.
### Changed
- `HypervisorDriver.get_vms()`: a guest that is not executing is never `"running"`. It is
`"paused"` while its process still holds its memory and `"suspended"` once its state was
saved away (NetOrk/netork#2658). `suspend_vm` names `resume_vm`, not `start_vm`, as the
way back.
## [4.41.0] - 2026-11-17
+30 -2
View File
@@ -71,7 +71,11 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
* name (string) - VM display name
* vmid (string) - hypervisor-internal ID (Proxmox: ``"100"``,
VMware: the instance UUID)
* status (string) - ``"running"``, ``"stopped"``, ``"paused"``, ``"suspended"``
* status (string) - ``"running"``, ``"stopped"``, ``"paused"``, ``"suspended"``.
A guest that is not executing is never ``"running"``: ``"paused"``
while its process still holds its memory (Proxmox's ``qmpstatus``
``paused``), ``"suspended"`` once its state was saved away (VMware's
``suspended``). :meth:`resume_vm` brings either back.
* vcpus (int) - number of virtual CPUs assigned
* memory (int) - configured RAM in megabytes
* cpu_usage (float) - current CPU utilisation 0.0–1.0
@@ -248,7 +252,9 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
def suspend_vm(self, name: str) -> None:
"""
Suspends (pauses) a running virtual machine, preserving its in-memory
state. The VM can be resumed with :meth:`start_vm`.
state. :meth:`get_vms` then reports it ``"paused"`` (its process
still holds the memory) or ``"suspended"`` (its state was saved
away), and :meth:`resume_vm` brings it back.
:param name: VM name or its ``vmid``.
:raises ValueError: If no VM with the given name/ID exists.
@@ -260,6 +266,28 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
"""
...
def resume_vm(self, name: str) -> None:
"""
Resumes a paused or suspended virtual machine where it stopped, the
counterpart of :meth:`suspend_vm`. The method blocks until the
hypervisor took the request.
Optional, like every power action: a driver whose platform cannot
resume a guest does not implement it, and a caller then offers no
resume. A driver that can resume some guests but not others (a
Proxmox container) refuses the others with ``RuntimeError``.
:param name: VM name or its ``vmid``.
:raises ValueError: If no VM with the given name/ID exists.
:raises RuntimeError: If the VM is neither paused nor suspended, or
the platform cannot resume this kind of guest.
Example::
driver.resume_vm("web01")
"""
...
# ------------------------------------------------------------------
# Snapshots
# ------------------------------------------------------------------
+23
View File
@@ -12,6 +12,7 @@ These tests pin the property that prevents a fourth.
from __future__ import annotations
import ast
import inspect
import pytest
@@ -82,6 +83,7 @@ class TestDeclaredMethodsDoNotExistAtRuntime:
(StorageDriver, "get_disks"),
(StorageDriver, "get_volumes"),
(HypervisorDriver, "get_vms"),
(HypervisorDriver, "resume_vm"),
(FirewallDriver, "send_wake_on_lan"),
(SwitchDriver, "set_vlan"),
(AccessPointDriver, "get_wireless_config"),
@@ -101,6 +103,27 @@ class TestDeclaredMethodsDoNotExistAtRuntime:
assert not hasattr(base, method)
class TestHypervisorPowerContract:
"""The power actions a hypervisor driver may implement, as declared."""
@staticmethod
def _declared(module) -> dict[str, list[str]]:
tree = ast.parse(inspect.getsource(module))
methods: dict[str, list[str]] = {}
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
methods[node.name] = [a.arg for a in node.args.args]
return methods
def test_resume_vm_is_declared_beside_suspend_vm(self):
"""A VM netOrk paused must be one it can bring back (NetOrk/netork#2658)."""
from napalm_device_types import hypervisor
declared = self._declared(hypervisor)
assert declared.get("suspend_vm") == ["self", "name"]
assert declared.get("resume_vm") == ["self", "name"]
class TestNoShadowingAcrossRoles:
"""The regression test for the bug class."""