Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b68dc2455 | ||
|
|
66b6068ebf |
No files matched your search
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.20.0] - 2026-11-26
|
||||
|
||||
### Added
|
||||
- `get_update_history(since)` on apt hosts through napalm-device-types' `AptHistoryMixin`
|
||||
(4.47.0): every transaction in apt's history log and its rotations, newest first, with
|
||||
what it changed, when, who asked and the error it ended with (NetOrk/netork#2728). Read
|
||||
over `run_command` as the login user, as root only for a file that user may not read. A
|
||||
host with another package manager (dnf, yum, apk, pacman) raises `NotImplementedError`:
|
||||
their histories are not read yet. OpenMediaVault has it through `LinuxDriver`.
|
||||
|
||||
### Changed
|
||||
- Requires napalm-device-types 4.47.0, where `AptHistoryMixin` is released.
|
||||
|
||||
## [0.19.0] - 2026-11-26
|
||||
|
||||
### Added
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""What napalm-device-types implements for any POSIX host over ``run_command``.
|
||||
"""What napalm-device-types implements for a Linux host over ``run_command``.
|
||||
|
||||
The driver supplies ``run_command``; the readings, their parses and the writes are
|
||||
the mixins': scheduled jobs (cron, anacron, systemd timers) and time sync (chrony,
|
||||
systemd-timesyncd, ``timedatectl``). Their default paths are Debian's, which a
|
||||
the mixins': scheduled jobs (cron, anacron, systemd timers), time sync (chrony,
|
||||
systemd-timesyncd, ``timedatectl``), and on an apt host the update history from
|
||||
apt's own log (``_update_history``). Their default paths are Debian's, which a
|
||||
Linux host shares.
|
||||
"""
|
||||
|
||||
@@ -10,6 +11,8 @@ from __future__ import annotations
|
||||
|
||||
from napalm_device_types import PosixScheduledJobsMixin, PosixTimeSyncMixin
|
||||
|
||||
from napalm_linux._update_history import LinuxUpdateHistoryMixin
|
||||
|
||||
class LinuxPosixMixin(PosixScheduledJobsMixin, PosixTimeSyncMixin):
|
||||
"""Scheduled jobs and time sync of the host, over the driver's ``run_command``."""
|
||||
|
||||
class LinuxPosixMixin(PosixScheduledJobsMixin, PosixTimeSyncMixin, LinuxUpdateHistoryMixin):
|
||||
"""Scheduled jobs, time sync and the update history, over the driver's ``run_command``."""
|
||||
@@ -0,0 +1,28 @@
|
||||
"""The host's past package transactions (``UpdateMixin.get_update_history``, NetOrk/netork#2728).
|
||||
|
||||
On an apt host, napalm-device-types' ``AptHistoryMixin``: apt's history log over
|
||||
``run_command``, as the login user, and as root only for a file the login user
|
||||
may not read. dnf, yum, apk and pacman keep histories of their own that this
|
||||
driver does not read yet: ``NotImplementedError``, never an empty list.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from napalm_device_types import AptHistoryMixin, UpdateHistoryDict
|
||||
|
||||
|
||||
class LinuxUpdateHistoryMixin(AptHistoryMixin):
|
||||
"""``get_update_history`` on the hosts whose package manager the driver detected as apt."""
|
||||
|
||||
_pkg_manager: str | None
|
||||
|
||||
def get_update_history(self, since: int | None = None) -> list[UpdateHistoryDict]:
|
||||
"""apt's transactions on the host, newest first, from *since* (unix seconds) on.
|
||||
|
||||
:raises NotImplementedError: on a host whose package manager is not apt.
|
||||
"""
|
||||
if self._pkg_manager != "apt":
|
||||
raise NotImplementedError(
|
||||
f"No update history is read for package manager {self._pkg_manager!r}"
|
||||
)
|
||||
return super().get_update_history(since)
|
||||
+2
-2
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "napalm-linux"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
description = "NAPALM driver for generic Linux systems via SSH"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
@@ -34,7 +34,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"napalm>=4.0",
|
||||
"napalm-device-types>=4.45.0", # ServicesRestartMixin
|
||||
"napalm-device-types>=4.47.0", # AptHistoryMixin (the release after 4.46.0)
|
||||
"netmiko>=4.0.0",
|
||||
"paramiko>=5.0.0", # CVE-2026-44405
|
||||
]
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
"""The host's past package transactions (``UpdateMixin.get_update_history``, NetOrk/netork#2728).
|
||||
|
||||
On an apt host the reading and its parse are napalm-device-types' ``AptHistoryMixin``:
|
||||
apt's history log over ``run_command``, as the login user, root only for a file
|
||||
the login user may not read. Another package manager has no history this driver
|
||||
reads yet: ``NotImplementedError``, so a caller knows not to ask, not an empty list.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from napalm_device_types import APT_HISTORY_COMMAND, CommandResult
|
||||
|
||||
from napalm_linux import LinuxDriver
|
||||
|
||||
REPORT = """\
|
||||
### apt-history zone /usr/share/zoneinfo/Etc/UTC
|
||||
### apt-history offset +0000
|
||||
### apt-history file /var/log/apt/history.log
|
||||
|
||||
Start-Date: 2026-11-26 09:00:00
|
||||
Commandline: apt-get -y upgrade
|
||||
Requested-By: admin (1000)
|
||||
Upgrade: openssh-server:amd64 (1:10.0p1-7, 1:10.0p1-7+deb13u1)
|
||||
End-Date: 2026-11-26 09:01:00
|
||||
|
||||
### apt-history status 0
|
||||
### apt-history end
|
||||
"""
|
||||
|
||||
|
||||
def _driver(pkg_manager: str | None) -> tuple[LinuxDriver, list[tuple[str, bool]]]:
|
||||
driver = LinuxDriver("host", "user", "pw", optional_args={"sudo_password": "pw"})
|
||||
driver._pkg_manager = pkg_manager
|
||||
calls: list[tuple[str, bool]] = []
|
||||
|
||||
def run_command(command, *, privileged=False, timeout=60, stdin=None): # type: ignore[no-untyped-def]
|
||||
calls.append((command, privileged))
|
||||
return CommandResult(REPORT, "", 0)
|
||||
|
||||
driver.run_command = run_command # type: ignore[method-assign]
|
||||
return driver, calls
|
||||
|
||||
|
||||
def test_an_apt_host_reads_apts_log_as_the_login_user():
|
||||
driver, calls = _driver("apt")
|
||||
assert driver.get_update_history() == [
|
||||
{
|
||||
"id": "1795683600-0",
|
||||
"start": 1795683600,
|
||||
"end": 1795683660,
|
||||
"packages": [
|
||||
{
|
||||
"name": "openssh-server",
|
||||
"action": "upgrade",
|
||||
"old_version": "1:10.0p1-7",
|
||||
"new_version": "1:10.0p1-7+deb13u1",
|
||||
}
|
||||
],
|
||||
"requested_by": "admin",
|
||||
"command": "apt-get -y upgrade",
|
||||
"error": None,
|
||||
}
|
||||
]
|
||||
assert calls == [(APT_HISTORY_COMMAND, False)]
|
||||
|
||||
|
||||
def test_since_is_passed_on():
|
||||
driver, _ = _driver("apt")
|
||||
assert driver.get_update_history(since=1795683601) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("pkg_manager", ["dnf", "yum", "apk", "pacman", None])
|
||||
def test_another_package_manager_has_no_history_here(pkg_manager):
|
||||
driver, calls = _driver(pkg_manager)
|
||||
with pytest.raises(NotImplementedError):
|
||||
driver.get_update_history()
|
||||
assert calls == []
|
||||
Reference in new issue
Block a user