feat: the host's file shares and network mounts, 0.27.0 (NetOrk/netork#3104)

- get_shares() through napalm-device-types' PosixSharesMixin: the NFS exports and
  Samba shares the host serves, each naming its service.
- get_network_mounts() through NetworkMountsMixin: the NFS exports and SMB shares
  the host has mounted.
- Requires napalm-device-types 4.58.0, which also reports nfs-server running while
  its unit is active and names it as the unit of the kernel's NFS sockets.
This commit is contained in:
Christian Manivong committed 2026-12-03 18:43:45 +01:00
1 parent 612bda6ce2
commit 6f073aa96c
4 files changed
+92 -2

No files matched your search

+55
View File
@@ -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)
# ---------------------------------------------------------------------------