From 56e0560eb2d2d1599205759b4e906ad92c465689 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Thu, 12 Nov 2026 18:54:07 +0100 Subject: [PATCH] fix(driver): leave unsupported getters to NAPALM's stubs get_config() overrode NAPALM's stub with `return {}` and took no arguments, so get_config(retrieve="running") raised TypeError, which a caller reports as a failed configuration backup on every poll. The other getters a speaker has nothing for (environment, optics, routing, ARP, MAC table, LLDP, NTP, SNMP, BGP, probes, users, network instances, firewall policies) had the same shape: an empty answer reads as "implemented, nothing there", and get_route_to() required an argument NAPALM defaults. All of them are gone; NAPALM's stubs raise NotImplementedError. Closes #13 --- CHANGELOG.md | 7 ++++ README.md | 7 +++- napalm_sonos/sonos_driver.py | 80 ------------------------------------ tests/test_sonos.py | 45 +++++++++++++++++++- 4 files changed, 55 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd37c8a..0468c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,13 @@ All notable changes to this driver. The format follows on 3.12, so 3.10 and 3.11 are no longer tested (NAPALM/driver-standard#6). - The floor on napalm is 5.1: older releases import `pkg_resources`, which a Python 3.12 venv no longer has. +- **Breaking:** the NAPALM getters a speaker has nothing for are no longer overridden: + `get_config()`, `get_environment()`, `get_optics()`, the routing, ARP, MAC table, LLDP, + NTP, SNMP, BGP, probe, user, network-instance and firewall-policy getters raise + NAPALM's `NotImplementedError` instead of answering `{}` or `[]`. An empty answer read + as "implemented, nothing there", and `get_config()` and `get_route_to()` did not even + take NAPALM's arguments: `get_config(retrieve="running")` raised `TypeError`, which a + caller reported as a failed configuration backup on every poll (#13). ### Fixed - `play()`, `pause()`, `stop()`, `next_track()`, `previous_track()`, `set_volume()` diff --git a/README.md b/README.md index cd16218..a9e6821 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,11 @@ speaker's connection, whatever its medium. ## Not supported Configuration management (`load_replace_candidate` and `load_merge_candidate` raise -`NotImplementedError`), the CLI, and every routing, LLDP, ARP, NTP, SNMP, BGP, user -and environment getter: they return empty results. +`NotImplementedError`), configuration export (`get_config`), the CLI, and every +routing, LLDP, ARP, MAC table, NTP, SNMP, BGP, optics, probe, user, network-instance, +firewall-policy and environment getter. The driver leaves those getters to NAPALM, +whose stubs raise `NotImplementedError`: a speaker has no such data, and an empty +answer would read as "read, nothing there". ## Installation diff --git a/napalm_sonos/sonos_driver.py b/napalm_sonos/sonos_driver.py index 7734830..88fe78f 100644 --- a/napalm_sonos/sonos_driver.py +++ b/napalm_sonos/sonos_driver.py @@ -167,42 +167,6 @@ class SonosDriver(MediaDriver): } return {_INTERFACE: {"ipv4": ipv4_entry, "ipv6": {}}} - def get_arp_table(self, vrf: str = "") -> list[dict[str, Any]]: - """Return the ARP table (not supported on Sonos).""" - return [] - - def get_lldp_neighbors(self) -> dict[str, Any]: - """Return LLDP neighbors (not supported on Sonos).""" - return {} - - def get_lldp_neighbors_detail(self, interface: str = "") -> dict[str, Any]: - """Return detailed LLDP neighbors (not supported on Sonos).""" - return {} - - def get_config(self) -> dict[str, Any]: - """Return the device config (not supported on Sonos).""" - return {} - - def get_environment(self) -> dict[str, Any]: - """Return environment/power info (not supported on Sonos).""" - return {} - - def get_optics(self) -> dict[str, Any]: - """Return optics info (not supported on Sonos).""" - return {} - - def get_ntp_peers(self) -> dict[str, str | None]: - """Return NTP peers (not supported on Sonos).""" - return {} - - def get_ntp_servers(self) -> dict[str, str | None]: - """Return NTP servers (not supported on Sonos).""" - return {} - - def get_ntp_stats(self) -> list[dict[str, Any]]: - """Return NTP stats (not supported on Sonos).""" - return [] - def ping( self, destination: str, @@ -233,50 +197,6 @@ class SonosDriver(MediaDriver): "error": "Not supported on Sonos", } - def get_route_to(self, destination: str) -> list[dict[str, Any]]: - """Return routing table (not supported on Sonos).""" - return [] - - def get_snmp_information(self) -> dict[str, Any]: - """Return SNMP info (not supported on Sonos).""" - return {} - - def get_users(self) -> dict[str, Any]: - """Return user accounts (not supported on Sonos).""" - return {} - - def get_network_instances(self, name: str = "") -> dict[str, Any]: - """Return network instances / VRFs (not supported on Sonos).""" - return {} - - def get_bgp_config(self, group: str = "") -> dict[str, Any]: - """Return BGP config (not supported on Sonos).""" - return {} - - def get_bgp_neighbors(self) -> dict[str, Any]: - """Return BGP neighbors (not supported on Sonos).""" - return {} - - def get_bgp_neighbors_detail(self, neighbor_address: str = "") -> dict[str, Any]: - """Return detailed BGP neighbor info (not supported on Sonos).""" - return {} - - def get_probes_config(self) -> dict[str, Any]: - """Return probe config (not supported on Sonos).""" - return {} - - def get_probes_results(self) -> dict[str, Any]: - """Return probe results (not supported on Sonos).""" - return {} - - def get_mac_address_table(self) -> list[dict[str, Any]]: - """Return MAC address table (not supported on Sonos).""" - return [] - - def get_firewall_policies(self) -> dict[str, Any]: - """Return firewall policies (not supported on Sonos).""" - return {} - def cli(self, commands: list[str]) -> list[dict[str, Any]]: """Run CLI commands (not supported on Sonos).""" return [] diff --git a/tests/test_sonos.py b/tests/test_sonos.py index 1e6c3b5..59a6a4b 100644 --- a/tests/test_sonos.py +++ b/tests/test_sonos.py @@ -4,6 +4,7 @@ import pytest import requests import soco import soco.groups +from napalm.base import NetworkDriver from napalm.base.exceptions import ( CommandErrorException, ConnectionClosedException, @@ -334,8 +335,48 @@ def test_the_driver_module_has_its_docstring(): assert module.__doc__ and "Sonos" in module.__doc__ -def test_get_arp_table_takes_napalms_vrf_argument(): - assert SonosDriver("192.168.1.100").get_arp_table(vrf="") == [] +#: NAPALM getters a speaker has nothing for. Each stays NAPALM's own stub, which raises +#: NotImplementedError: an override answering {} or [] reads as "implemented, nothing +#: there" to a caller that asks whether the driver has its own getter (#13). +_NOT_SUPPORTED_GETTERS = [ + "get_arp_table", + "get_bgp_config", + "get_bgp_neighbors", + "get_bgp_neighbors_detail", + "get_config", + "get_environment", + "get_firewall_policies", + "get_lldp_neighbors", + "get_lldp_neighbors_detail", + "get_mac_address_table", + "get_network_instances", + "get_ntp_peers", + "get_ntp_servers", + "get_ntp_stats", + "get_optics", + "get_probes_config", + "get_probes_results", + "get_route_to", + "get_snmp_information", + "get_users", +] + + +@pytest.mark.parametrize("getter", _NOT_SUPPORTED_GETTERS) +def test_an_unsupported_getter_is_napalms_stub(getter): + assert getattr(SonosDriver, getter) is getattr(NetworkDriver, getter) + + +def test_get_config_with_napalms_arguments_says_not_implemented(): + """`get_config(retrieve="running")` raised TypeError, read as a failed backup (#13).""" + with pytest.raises(NotImplementedError): + SonosDriver("192.0.2.20").get_config(retrieve="running") + + +def test_get_route_to_with_napalms_defaults_says_not_implemented(): + """The override required `destination`; NAPALM's getter defaults it (#13).""" + with pytest.raises(NotImplementedError): + SonosDriver("192.0.2.20").get_route_to() @pytest.mark.parametrize(