diff --git a/CHANGELOG.md b/CHANGELOG.md index 847c85a..39a04d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ recorded here; their history is the git log. ## [Unreleased] +### Added +- `UpdateDict` takes four optional fields for a source that says more of an update than a + package name (NetOrk/netork#2892): `title`, the vendor's `advisories` it ships (Windows + Update's KB articles), the `cves` it fixes on this host, and the vendor's own rating + (`vendor_severity`, Windows Update's `MsrcSeverity`). `UpdateHistoryPackageDict` takes an + optional `title`. Every reader that leaves them out still conforms. + ## [4.55.0] - 2026-12-01 ### Added diff --git a/README.md b/README.md index 8248567..09214cb 100644 --- a/README.md +++ b/README.md @@ -410,7 +410,10 @@ driver mixes it in and supplies `run_command`. **Update readers raise when they cannot read.** `get_available_updates` returns an empty list only when nothing is pending; netOrk keeps "pending since" per package, and an empty -list for "don't know" would reset it. +list for "don't know" would reset it. A source that names more than a package may say so +on each update, all optional: its `title`, the vendor's `advisories` it ships ("KB5070000"), +the `cves` it fixes on this host and the vendor's own rating (`vendor_severity`) -- what +Windows Update reports for every update it offers (NetOrk/netork#2892). `SystemdServicesMixin` (`get_services`, `manage_service`) is mixed in the same way, by the drivers whose host runs systemd. Listing the services, checking a unit name and diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 60f6744..bc3e492 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -81,7 +81,9 @@ class UpdateDict(TypedDict): """A software package that has a newer version available in the package repository. ``origin`` and ``security`` are optional: a reader that cannot tell leaves - them out, and netOrk treats a missing ``security`` as unknown. + them out, and netOrk treats a missing ``security`` as unknown. So are + ``title``, ``advisories``, ``cves`` and ``vendor_severity``, which only a source + that names them fills. """ name: str @@ -91,6 +93,18 @@ class UpdateDict(TypedDict): origin: NotRequired[str | None] #: True for a security update, False for a known other one, None when unknown. security: NotRequired[bool | None] + #: What the source calls the update, where its name is no package: Windows Update's + #: title, "2026-11 Cumulative Update for ... (KB5070000)" (NetOrk/netork#2892). + title: NotRequired[str | None] + #: The vendor's advisories the update ships, e.g. Windows Update's ``KBArticleIDs`` + #: as "KB5070000"; empty or left out when the source names none. + advisories: NotRequired[list[str]] + #: The CVEs the source says the update fixes on this host (Windows Update's + #: ``CveIDs``): the host's own word that each applies until the update is installed. + cves: NotRequired[list[str]] + #: The vendor's rating, in the vendor's word: Windows Update's ``MsrcSeverity`` + #: ("Critical", "Important", "Moderate", "Low"); None when it gives none. + vendor_severity: NotRequired[str | None] class InterruptedPackageDict(TypedDict): diff --git a/napalm_device_types/updates.py b/napalm_device_types/updates.py index ea33bf5..05cc8df 100644 --- a/napalm_device_types/updates.py +++ b/napalm_device_types/updates.py @@ -13,7 +13,7 @@ this class in can never shadow a working implementation from a sibling base. from __future__ import annotations from collections.abc import Callable -from typing import TYPE_CHECKING, Any, Literal +from typing import TYPE_CHECKING, Any, Literal, NotRequired from typing_extensions import TypedDict @@ -35,6 +35,9 @@ class UpdateHistoryPackageDict(TypedDict): action: UpdateHistoryAction # "disappear": dpkg dropped it, its files taken by another old_version: str | None # None where nothing was installed before new_version: str | None # None where nothing is installed after + #: What the source calls it, where the name is no package: Windows Update's title + #: (NetOrk/netork#2892). + title: NotRequired[str | None] class UpdateHistoryDict(TypedDict): @@ -80,6 +83,9 @@ class UpdateMixin: * origin (string, optional) - where it comes from, e.g. apt's suites * security (bool or None, optional) - a security update; leave it out or None when the source does not say + * title, advisories, cves, vendor_severity (optional) - what a source + that names more than a package says of it: Windows Update's title, + ``KBArticleIDs``, ``CveIDs`` and ``MsrcSeverity`` (NetOrk/netork#2892) **An empty list means nothing is pending.** A reader that cannot read -- no package index yet, an API that did not answer -- raises diff --git a/tests/test_pve93_contracts.py b/tests/test_pve93_contracts.py index 97a512b..9ffd1f4 100644 --- a/tests/test_pve93_contracts.py +++ b/tests/test_pve93_contracts.py @@ -51,6 +51,7 @@ def test_an_update_transaction_is_its_packages_and_who_asked_for_it(): "action", "old_version", "new_version", + "title", # optional: what Windows calls the update (NetOrk/netork#2892) } actions = typing.get_args(get_type_hints(UpdateHistoryPackageDict)["action"]) assert set(actions) == { diff --git a/tests/test_updates.py b/tests/test_updates.py index 6f068b3..7121263 100644 --- a/tests/test_updates.py +++ b/tests/test_updates.py @@ -47,3 +47,29 @@ def test_apply_updates_takes_a_log_callback_by_keyword_only(): def test_apply_updates_still_hides_at_runtime(): assert not hasattr(napalm_device_types.UpdateMixin, "apply_updates") + + +def test_a_pending_update_can_name_what_it_fixes(): + """A source that says which advisories and CVEs an update closes, and how its + vendor rates it (Windows Update's ``KBArticleIDs``, ``CveIDs``, ``MsrcSeverity``, + NetOrk/netork#2892), can pass that on. Optional: every reader that says nothing + of it still conforms.""" + from typing import get_type_hints + + from napalm_device_types.models import UpdateDict + + hints = get_type_hints(UpdateDict) + assert {"title", "advisories", "cves", "vendor_severity"} <= set(hints) + assert UpdateDict.__required_keys__ == {"name", "current_version", "new_version"} + + +def test_a_past_update_can_carry_its_title(): + """Windows names an update by its title, not by a package (NetOrk/netork#2892).""" + from typing import get_type_hints + + from napalm_device_types.updates import UpdateHistoryPackageDict + + assert "title" in get_type_hints(UpdateHistoryPackageDict, include_extras=True) + assert "NotRequired" in str( + get_type_hints(UpdateHistoryPackageDict, include_extras=True)["title"] + )