diff --git a/napalm_device_types/kernel.py b/napalm_device_types/kernel.py index 1487bf3..00ba412 100644 --- a/napalm_device_types/kernel.py +++ b/napalm_device_types/kernel.py @@ -33,8 +33,8 @@ import gzip import zlib from typing import TYPE_CHECKING +from napalm_device_types.kernel_models import KernelFactsDict from napalm_device_types.livepatch import live_patches, parse_canonical_status -from napalm_device_types.models import KernelFactsDict _BEGIN = "KFACTS_BEGIN" _END = "KFACTS_END" @@ -212,7 +212,9 @@ class KernelFactsMixin: if patches["canonical"] is not None: return facts try: - patches["canonical"] = parse_canonical_status(run(LIVEPATCH_STATUS_COMMAND)) - except Exception: # noqa: BLE001 - root refused or the client failed: not read - pass + status = run(LIVEPATCH_STATUS_COMMAND) + except Exception: # noqa: BLE001 - root refused or the client failed + # Not read: ``canonical`` stays None, as without a driver that gains root. + return facts + patches["canonical"] = parse_canonical_status(status) return facts diff --git a/napalm_device_types/kernel_models.py b/napalm_device_types/kernel_models.py new file mode 100644 index 0000000..a2c6488 --- /dev/null +++ b/napalm_device_types/kernel_models.py @@ -0,0 +1,34 @@ +"""The shape of the kernel facts (``KernelFactsMixin.get_kernel_facts``). + +A module of its own rather than in :mod:`napalm_device_types.models`, which re-exports +it: the reading grew its live patches (NetOrk/netork#2701), and ``models`` is at its +recorded size. +""" + +from __future__ import annotations + +from typing import NotRequired + +from typing_extensions import TypedDict + +from napalm_device_types.livepatch import LivePatchesDict + + +class KernelFactsDict(TypedDict): + """What the running kernel has built and loaded (``KernelFactsMixin.get_kernel_facts``). + + ``None`` means *could not be read*; an empty list means *read, and there is + nothing*. The difference is what lets a consumer say "this module cannot be + loaded on this kernel" rather than "we did not look". + + Module names are normalised by :func:`napalm_device_types.kernel.module_name`: + no path, no ``.ko`` suffix, ``-`` folded to ``_``. + """ + + release: str # uname -r + loaded: list[str] | None # /proc/modules + builtin: list[str] | None # modules.builtin -- compiled into the kernel image + available: list[str] | None # modules.dep -- shipped as loadable modules + config: dict[str, str] | None # build configuration, set options only; quotes stripped + #: The live patches the kernel carries (NetOrk/netork#2701, ``livepatch``). + live_patches: NotRequired[LivePatchesDict] diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 400ee50..60f6744 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -21,7 +21,7 @@ from napalm_device_types.access_point_models import SSIDBridgeDict as SSIDBridge from napalm_device_types.access_point_models import SSIDDict as SSIDDict from napalm_device_types.access_point_models import WirelessClientDict as WirelessClientDict from napalm_device_types.access_point_models import WirelessConfigDict as WirelessConfigDict -from napalm_device_types.livepatch import LivePatchesDict +from napalm_device_types.kernel_models import KernelFactsDict as KernelFactsDict from napalm_device_types.snmp_health_profile import SnmpHealthProfile as SnmpHealthProfile from napalm_device_types.snmp_health_profile import SnmpInterfacesSpec as SnmpInterfacesSpec from napalm_device_types.snmp_health_profile import SnmpMemorySpec as SnmpMemorySpec @@ -274,26 +274,6 @@ class NATTranslationDict(TypedDict): age: float -class KernelFactsDict(TypedDict): - """What the running kernel has built and loaded (``KernelFactsMixin.get_kernel_facts``). - - ``None`` means *could not be read*; an empty list means *read, and there is - nothing*. The difference is what lets a consumer say "this module cannot be - loaded on this kernel" rather than "we did not look". - - Module names are normalised by :func:`napalm_device_types.kernel.module_name`: - no path, no ``.ko`` suffix, ``-`` folded to ``_``. - """ - - release: str # uname -r - loaded: list[str] | None # /proc/modules - builtin: list[str] | None # modules.builtin -- compiled into the kernel image - available: list[str] | None # modules.dep -- shipped as loadable modules - config: dict[str, str] | None # build configuration, set options only; quotes stripped - #: The live patches the kernel carries (NetOrk/netork#2701, ``livepatch``). - live_patches: NotRequired[LivePatchesDict] - - class ListeningSocketDict(TypedDict): """A TCP socket that listens, or a UDP socket that is bound, on the host. diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json index 2591259..1aaf91a 100644 --- a/tests/quality_baseline.json +++ b/tests/quality_baseline.json @@ -31,7 +31,7 @@ }, "mypy_relaxed": [], "python_file_lines": { - "napalm_device_types/models.py": 1353 + "napalm_device_types/models.py": 1336 }, "untyped_public": [] }