refactor: the share and mount transports in their own mixin (NetOrk/netork#3104)
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 15s
driver / lowest (pull_request) Successful in 27s
driver / types (pull_request) Successful in 54s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 53s
driver / build (pull_request) Successful in 24s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 1m41s
driver / publish (pull_request) Skipped

The standard's ratchet holds linux.py at its recorded size: the two exec-channel
transports move to _shares.LinuxSharesMixin, which the host readings bring in.
This commit is contained in:
Christian Manivong committed 2026-12-03 18:45:51 +01:00
1 parent 6f073aa96c
commit 480107c96a
3 files changed
+42 -19

No files matched your search

+4 -1
View File
@@ -1,5 +1,6 @@
"""Readings of the host's processes: listening sockets, log sources, running backups,
and the services that still run replaced code.
and the services that still run replaced code; and the file shares the host serves
and has mounted (``_shares``, NetOrk/netork#3104).
The first two commands are napalm-device-types' and read-only. Root only widens
what they see -- ``ss`` names every process behind a socket, ``/proc/<pid>/fd`` shows every
@@ -26,6 +27,7 @@ from napalm_device_types import ListeningSocketsMixin, LogSourcesMixin, Services
from napalm_linux._hardening import LinuxHardeningMixin
from napalm_linux._logins import LinuxLoginAccountsMixin
from napalm_linux._running_backups import LinuxRunningBackupsMixin
from napalm_linux._shares import LinuxSharesMixin
#: Seconds either reading may take; a busy host lists thousands of descriptors.
_READ_TIMEOUT = 60
@@ -38,6 +40,7 @@ class LinuxProcessReadingsMixin(
LinuxRunningBackupsMixin,
LinuxHardeningMixin,
LinuxLoginAccountsMixin,
LinuxSharesMixin,
):
"""The transports for ``get_listening_sockets``, ``get_log_sources`` and
``get_services_need_restart``, and ``get_running_backups``, ``get_hardening``
+38
View File
@@ -0,0 +1,38 @@
"""The file shares the host serves and the ones it has mounted (NetOrk/netork#3104).
Both readings are napalm-device-types': the NFS exports and Samba shares the host
serves (``PosixSharesMixin``) and the NFS exports and SMB shares it has mounted
(``NetworkMountsMixin``). Both commands are read-only and read files every user may
read, so they run on an exec channel under ``sh`` as the login user, never through sudo.
"""
from __future__ import annotations
from shlex import quote
from typing import TYPE_CHECKING
from napalm_device_types import NetworkMountsMixin, PosixSharesMixin
if TYPE_CHECKING: # pragma: no cover - for type checkers only
from napalm_device_types import CommandResult
class LinuxSharesMixin(PosixSharesMixin, NetworkMountsMixin):
"""The transports for ``get_shares`` and ``get_network_mounts``."""
if TYPE_CHECKING: # pragma: no cover - declared for type checkers only
def run_command(
self,
command: str,
*,
privileged: bool = False,
timeout: float = 60,
stdin: bytes | None = None,
) -> CommandResult: ...
def _run_shares_command(self, command: str) -> str:
return self.run_command(f"sh -c {quote(command)}", timeout=60).stdout
def _run_network_mounts_command(self, command: str) -> str:
return self.run_command(f"sh -c {quote(command)}", timeout=30).stdout
-18
View File
@@ -40,10 +40,8 @@ from napalm_device_types import (
HostStatusMixin,
KernelFactsMixin,
LldpNeighborDict,
NetworkMountsMixin,
OpenSshServerMixin,
OSDriver,
PosixSharesMixin,
ServiceClustersMixin,
ServicePackagesMixin,
SnmpAgentMixin,
@@ -277,8 +275,6 @@ class LinuxDriver(
AptProxyMixin,
KernelFactsMixin,
ServicePackagesMixin,
PosixSharesMixin,
NetworkMountsMixin,
LinuxProcessReadingsMixin,
HostFirewallMixin,
VirtualIpsMixin,
@@ -1046,20 +1042,6 @@ class LinuxDriver(
"""
return self.run_command(f"sh -c {_shlex_quote(command)}", timeout=120).stdout
def _run_shares_command(self, command: str) -> str:
"""The transport for ``PosixSharesMixin.get_shares``: the NFS exports and Samba
shares the host serves (NetOrk/netork#3104).
An exec channel under ``sh``, like the service packages. The export table and
Samba's configuration are readable to everyone, so never through sudo.
"""
return self.run_command(f"sh -c {_shlex_quote(command)}", timeout=60).stdout
def _run_network_mounts_command(self, command: str) -> str:
"""The transport for ``NetworkMountsMixin.get_network_mounts``: the NFS exports
and SMB shares the host has mounted (NetOrk/netork#3104). Readable by everyone."""
return self.run_command(f"sh -c {_shlex_quote(command)}", timeout=30).stdout
# ------------------------------------------------------------------
# HostFirewallMixin – the transport for get_host_firewall
# ------------------------------------------------------------------