diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f0502..0d3ae89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.27.0] - 2026-12-03 + +### Added +- `get_shares()` (napalm-device-types' `PosixSharesMixin`, 4.58.0): the NFS exports and + Samba shares the host serves, from the kernel's export table and `testparm -s`, each + naming the service that serves it (NetOrk/netork#3104). Read on an exec channel as the + login user: both are readable to everyone. A NAS driver built on `LinuxDriver` that reads + its own configuration (OpenMediaVault) keeps its own `get_shares`. +- `get_network_mounts()` (napalm-device-types' `NetworkMountsMixin`, 4.58.0): the NFS + exports and SMB shares the host has mounted, from `/proc/self/mounts`, on an exec channel + as the login user (NetOrk/netork#3104). + +### Changed +- Through napalm-device-types 4.58.0, `get_services` reports `nfs-server` as running while + its unit is active, and `get_listening_sockets` names it as the unit of the kernel's NFS + sockets. + ## [0.26.0] - 2026-12-01 ### Added diff --git a/napalm_linux/linux.py b/napalm_linux/linux.py index 7176f35..98f4795 100644 --- a/napalm_linux/linux.py +++ b/napalm_linux/linux.py @@ -40,8 +40,10 @@ from napalm_device_types import ( HostStatusMixin, KernelFactsMixin, LldpNeighborDict, + NetworkMountsMixin, OpenSshServerMixin, OSDriver, + PosixSharesMixin, ServiceClustersMixin, ServicePackagesMixin, SnmpAgentMixin, @@ -275,6 +277,8 @@ class LinuxDriver( AptProxyMixin, KernelFactsMixin, ServicePackagesMixin, + PosixSharesMixin, + NetworkMountsMixin, LinuxProcessReadingsMixin, HostFirewallMixin, VirtualIpsMixin, @@ -1042,6 +1046,20 @@ 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 # ------------------------------------------------------------------ diff --git a/pyproject.toml b/pyproject.toml index 708b956..3f76ea7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "napalm-linux" -version = "0.26.0" +version = "0.27.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.55.0", # LoginSessionsMixin + "napalm-device-types>=4.58.0", # PosixSharesMixin, nfs-server running "netmiko>=4.0.0", "paramiko>=5.0.0", # CVE-2026-44405 ] diff --git a/tests/test_linux.py b/tests/test_linux.py index 6e3fd03..23d220e 100644 --- a/tests/test_linux.py +++ b/tests/test_linux.py @@ -1523,6 +1523,61 @@ def test_get_service_packages_runs_the_shared_command_under_sh_on_an_exec_channe driver._device.send_command.assert_not_called() +_SHARES = ( + "SHARES_BEGIN\n[units]\nId=nfs-server.service\nLoadState=loaded\n\n" + "Id=smbd.service\nLoadState=not-found\n\nId=smb.service\nLoadState=not-found\n" + "[etab]\n/srv/backups\t10.0.0.0/24(rw,sync,no_subtree_check)\n[samba]\nSHARES_END\n" +) + + +def test_get_shares_runs_the_shared_command_under_sh_on_an_exec_channel(driver): + """The NFS exports and Samba shares an ordinary server serves (NetOrk/netork#3104). + Everything it reads is readable to everyone, so never through sudo.""" + from shlex import quote + + from napalm_device_types import CommandResult, PosixSharesMixin + from napalm_device_types.posix_shares import POSIX_SHARES_COMMAND + + assert isinstance(driver, PosixSharesMixin) + calls = [] + + def run_command(command, *, privileged=False, timeout=60, stdin=None): + calls.append((command, privileged)) + return CommandResult(_SHARES, "", 0) + + driver.run_command = run_command + + shares = driver.get_shares() + + assert list(shares) == ["nfs:/srv/backups"] + assert shares["nfs:/srv/backups"]["service"] == "nfs-server" + assert calls == [(f"sh -c {quote(POSIX_SHARES_COMMAND)}", False)] + driver._device.send_command.assert_not_called() + + +def test_get_network_mounts_reads_the_hosts_mounts_without_sudo(driver): + """Which NFS exports and SMB shares the host uses (NetOrk/netork#3104).""" + from shlex import quote + + from napalm_device_types import CommandResult, NetworkMountsMixin + from napalm_device_types.network_mounts import NETWORK_MOUNTS_COMMAND + + assert isinstance(driver, NetworkMountsMixin) + calls = [] + + def run_command(command, *, privileged=False, timeout=60, stdin=None): + calls.append((command, privileged)) + out = "MOUNTS_BEGIN\nnas:/export/scan /mnt/scan nfs4 rw,addr=192.0.2.8 0 0\nMOUNTS_END\n" + return CommandResult(out, "", 0) + + driver.run_command = run_command + + [mount] = driver.get_network_mounts() + + assert (mount["server"], mount["export"]) == ("nas", "/export/scan") + assert calls == [(f"sh -c {quote(NETWORK_MOUNTS_COMMAND)}", False)] + + # --------------------------------------------------------------------------- # Services: listed in one round trip, controlled through systemctl (#7) # ---------------------------------------------------------------------------