Compare commits

...
3 Commits
Author SHA1 Message Date
Christian Manivong b37672a269 Merge origin/main (0.14.0) into feature/services-need-restart
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Failing after 25s
driver / test (3.12) (pull_request) Failing after 17s
driver / test (3.13) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 18s
driver / security (pull_request) Failing after 37s
driver / build (pull_request) Successful in 32s
CI / driver (pull_request) Failing after 1m32s
driver / publish (pull_request) Skipped
Needs napalm-device-types 4.46.0: ServicesRestartMixin with an LXC
container's processes left out, and 0.14.0's CredentialExpiryMixin.
2026-11-26 19:26:58 +01:00
Christian Manivong 63ffc64050 chore(release): 0.16.0
driver / standard (pull_request) Successful in 19s
driver / lint (pull_request) Successful in 18s
driver / types (pull_request) Failing after 58s
driver / test (3.12) (pull_request) Failing after 57s
driver / test (3.13) (pull_request) Failing after 52s
driver / lowest (pull_request) Failing after 27s
driver / build (pull_request) Successful in 34s
driver / security (pull_request) Successful in 1m12s
CI / driver (pull_request) Failing after 2m45s
driver / publish (pull_request) Skipped
2026-11-26 19:01:33 +01:00
Christian Manivong b792f6d210 feat(services-restart): which services on the node still run replaced code, as root (NetOrk/netork#2750)
Both drivers mix in napalm-device-types' ServicesRestartMixin. The command
goes over the exec path, root's login as a rule, behind an id -u guard: a
login other than root would see only its own processes and read as
clean, so it prints nothing and the read raises. A running VM's QEMU is
listed as a process; an LXC container's processes are left out by the
parse, since a container updates itself. No stdin.
2026-11-26 18:55:13 +01:00
7 changed files with 113 additions and 8 deletions

No files matched your search

+17
View File
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.16.0] - 2026-11-26
### Added
- `get_services_need_restart()` on both drivers (napalm-device-types' `ServicesRestartMixin`,
NetOrk/netork#2750): the services that still run code an update replaced on disk, so they
keep the old library until they restart. One fixed, read-only command over the exec path,
which is root's login: `needs-restarting -s`, else `needrestart` in list-only mode, else the
processes whose `/proc/<pid>/maps` maps deleted code, each named by its cgroup's service. A
running VM's QEMU (`qemu.slice`) is listed as a process; an LXC container's processes are
left out, since a container updates itself. It runs only when the login is root
(`id -u` is 0): another login gets no report and the read raises, rather than read as
clean what it cannot see. No stdin.
### Changed
- Needs napalm-device-types 4.46.0 or later (`ServicesRestartMixin`, with an LXC
container's processes left out).
## [0.14.0] - 2026-11-26
### Added
+2 -1
View File
@@ -131,6 +131,7 @@ device = driver(
| `put_scheduled_job(spec)` / `delete_scheduled_job(key, digest=)` | an application's own job, as a systemd timer |
| `get_time_sync` | chrony's sources, the ones DHCP gave apart (`dhcp_ntp_servers`), whether it is synchronised, the zone from `timedatectl`, in one round trip over SSH (napalm-device-types' `PosixTimeSyncMixin`); the zone from `GET /nodes/{node}/time` only where the host names none |
| `configure_time_sync(ntp_servers=, timezone=)` | servers to `/etc/chrony/sources.d/netork.sources`, every other configured source commented out (DHCP's `sourcedir` stays), then a reload or a restart of chrony; the zone through `PUT /nodes/{node}/time` (the token needs `Sys.Modify` on `/nodes/{node}`), so `/etc/timezone` and the web UI follow. Only this node: in a cluster each node keeps its own clock |
| `get_services_need_restart` | the services that still run code an update replaced on disk, as root over SSH (napalm-device-types' `ServicesRestartMixin`): `needrestart` in list-only mode where it is installed, else the processes whose `/proc/<pid>/maps` maps deleted code. A running VM's QEMU is a process (`processes`), an LXC container's processes are left out (the container updates itself). Only as root: another SSH login gets no reading, rather than a clean one |
**Not implemented** (raise `NotImplementedError`):
`get_bgp_config`, `get_bgp_neighbors`, `get_bgp_neighbors_detail`,
@@ -188,7 +189,7 @@ the disks and ZFS pools the server manages itself.
| `get_facts`, `get_interfaces`, `get_interfaces_ip`, `get_environment` | the API; host name, DMI and MAC addresses over SSH |
| `get_disks`, `get_disk_pools` | `/nodes/localhost/disks/{list,zfs}` |
| `get_licenses` | `pbs-subscription` |
| packages, updates, services, kernel, listening sockets, sshd hardening, `reboot_host`, `shutdown_host` | as on Proxmox VE |
| packages, updates, services, kernel, listening sockets, services still running replaced code, sshd hardening, `reboot_host`, `shutdown_host` | as on Proxmox VE |
| scheduled jobs | as on Proxmox VE; `proxmox-backup*` units are `platform`. Verify, prune, sync and GC jobs are `get_backup_jobs`, not scheduled jobs |
| `get_time_sync`, `configure_time_sync`, `get_ntp_servers` | as on Proxmox VE, the zone through `/nodes/localhost/time` (writing it needs `Sys.Modify` on `/system/time`) |
+2
View File
@@ -27,6 +27,7 @@ from napalm_device_types import (
OpenSshServerMixin,
PortSpec,
ServicePackagesMixin,
ServicesRestartMixin,
StorageDriver,
SystemdServicesMixin,
SystemIdentityMixin,
@@ -65,6 +66,7 @@ class ProxmoxBackupDriver(
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
ServicesRestartMixin,
SystemIdentityMixin,
SystemdServicesMixin,
ProxmoxScheduledJobsMixin,
+2
View File
@@ -38,6 +38,7 @@ from napalm_device_types import (
OpenSshServerMixin,
PortSpec,
ServicePackagesMixin,
ServicesRestartMixin,
SnmpAgentMixin,
SystemdServicesMixin,
SystemIdentityMixin,
@@ -100,6 +101,7 @@ class ProxmoxDriver(
ServicePackagesMixin,
ListeningSocketsMixin,
LogSourcesMixin,
ServicesRestartMixin,
SystemIdentityMixin,
SystemdServicesMixin,
ProxmoxScheduledJobsMixin,
+12 -5
View File
@@ -1,11 +1,11 @@
"""What a Proxmox VE node and a Proxmox Backup Server share as Debian hosts.
The transports for napalm-device-types' host readers (kernel facts, service
packages, system identity, listening sockets, systemd services, host status,
apt's proxy), packages and APT updates, the subscription, root file writes,
and restarting or shutting the host down. All of it is the same on both
products: the same ``/nodes/{node}/apt``, ``/subscription`` and ``/status``
endpoints, and root's shell over the driver's own SSH session.
packages, system identity, listening sockets, the services that still run replaced
code, systemd services, host status, apt's proxy), packages and APT updates, the
subscription, root file writes, and restarting or shutting the host down. All of it
is the same on both products: the same ``/nodes/{node}/apt``, ``/subscription`` and
``/status`` endpoints, and root's shell over the driver's own SSH session.
"""
from __future__ import annotations
@@ -91,6 +91,13 @@ class ProxmoxHostMixin:
which runs as root either way."""
return str(self._exec_ssh_command(command))
def _run_services_restart_command(self, command: str) -> str:
"""The transport for ``ServicesRestartMixin.get_services_need_restart``: the exec
path, which is root's login as a rule. Run only as root: a reading of the login's
own processes would read as clean, so another login prints nothing and the parse
raises (NetOrk/netork#2750). No stdin."""
return str(self._exec_ssh_command(f'[ "$(id -u)" = 0 ] && {command}'))
def get_packages(self) -> list[PackageDict]:
"""Return installed Debian packages with available-update info.
+2 -2
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-proxmox"
version = "0.14.0"
version = "0.16.0"
description = "NAPALM drivers for Proxmox VE (classic Linux networking, SDN, OVS) and Proxmox Backup Server"
readme = "README.md"
license = "Apache-2.0"
@@ -21,7 +21,7 @@ classifiers = [
requires-python = ">=3.12"
dependencies = [
"napalm>=5.0.0",
"napalm_device_types>=4.44.0", # CredentialExpiryMixin, UpdateHistoryDict, VMDict.uid
"napalm_device_types>=4.46.0", # ServicesRestartMixin with LXC left out; CredentialExpiryMixin
"paramiko>=5.0.0", # CVE-2026-44405; imported directly for the node's SSH session (_base.py)
"proxmoxer>=2.0.0",
"netaddr>=0.9.0",
+76
View File
@@ -0,0 +1,76 @@
"""`get_services_need_restart`: the services on the node that still run replaced code.
An openssl or glibc update replaces the files on disk; every daemon that had them
loaded keeps the old code until it restarts (NetOrk/netork#2750). On a hypervisor that
is where a restart instead of a reboot matters most. The command and its parse are
napalm-device-types' (``ServicesRestartMixin``); the driver only carries the command
over its exec path, which runs as root. A login that is not root gets no reading: it
would see only its own processes and read as clean.
"""
from __future__ import annotations
import subprocess
from unittest.mock import patch
import pytest
from napalm_device_types import ServicesRestartMixin
from napalm_proxmox import ProxmoxBackupDriver
from napalm_proxmox.driver import ProxmoxDriver
#: A PVE node after an openssl update, read by the /proc scan (no needrestart):
#: pveproxy and a running VM's QEMU still map the old library, and so does a
#: container's own nginx, which the container updates itself.
WIRE = (
"RST_BEGIN\n[maps]\n"
"2101 pveproxy worker\n"
"3100 kvm\n"
"4100 nginx\n"
"[cgroups]\n"
"2101 0::/system.slice/pveproxy.service\n"
"3100 0::/qemu.slice/101.scope\n"
"4100 0::/lxc/200/ns/system.slice/nginx.service\n"
"RST_END\n"
)
@pytest.mark.parametrize("driver_class", [ProxmoxDriver, ProxmoxBackupDriver])
def test_both_drivers_declare_the_contract(driver_class):
assert issubclass(driver_class, ServicesRestartMixin)
def test_it_reads_as_root_over_the_exec_path(driver):
with patch.object(driver, "_exec_ssh_command", return_value=WIRE) as exec_:
reading = driver.get_services_need_restart()
[command] = [c.args[0] for c in exec_.call_args_list]
assert command.startswith('[ "$(id -u)" = 0 ] && sh -c \'')
assert reading == {
"source": "maps",
"units": ["pveproxy"],
"processes": [{"pid": 3100, "name": "kvm"}],
}
def test_the_backup_server_reads_it_the_same_way():
drv = ProxmoxBackupDriver("192.0.2.80", "root", "", optional_args={"token_name": "a!b"})
wire = "RST_BEGIN\n[needrestart]\nNEEDRESTART-SVC: proxmox-backup-proxy.service\nRST_END\n"
with patch.object(drv, "_exec_ssh_command", return_value=wire):
reading = drv.get_services_need_restart()
assert reading["units"] == ["proxmox-backup-proxy"]
def test_a_login_other_than_root_gets_no_reading(driver):
"""The guard runs nothing but as root, so no report comes back and the parse raises."""
def as_this_user(command: str) -> str:
return subprocess.run(["sh", "-c", command], capture_output=True, text=True).stdout
if subprocess.run(["id", "-u"], capture_output=True, text=True).stdout.strip() == "0":
pytest.skip("runs as root here")
with patch.object(driver, "_exec_ssh_command", side_effect=as_this_user):
with pytest.raises(ValueError):
driver.get_services_need_restart()