From 397917a1740832e513167612e4bd6a050a569de0 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Thu, 12 Nov 2026 19:23:25 +0100 Subject: [PATCH] fix(driver): leave get_interfaces_ip and cli to NAPALM's stubs get_interfaces_ip reported the speaker's address with a prefix length of 24 it never read: the speaker info has no netmask, and SoCo offers no reading for one, so a speaker in a /23 or /25 network was reported wrongly. cli answered [] -- not even NAPALM's dict shape -- for a speaker that has no CLI. Both overrides are gone; NAPALM's stubs raise NotImplementedError. Closes #15 --- CHANGELOG.md | 5 +++++ README.md | 7 ++++--- napalm_sonos/sonos_driver.py | 18 ------------------ tests/test_sonos.py | 20 ++++++++++++++------ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0468c72..c6ff2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,11 @@ All notable changes to this driver. The format follows 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). +- **Breaking:** `get_interfaces_ip()` and `cli()` are left to NAPALM's stubs and raise + `NotImplementedError`. `get_interfaces_ip()` reported the speaker's address with a + prefix length of 24 it never read -- the speaker reports none, and SoCo has no reading + for one -- so a speaker in any other network size was reported wrongly. `cli()` + answered `[]`, not even NAPALM's dict shape, for a speaker that has no CLI (#15). ### Fixed - `play()`, `pause()`, `stop()`, `next_track()`, `previous_track()`, `set_volume()` diff --git a/README.md b/README.md index a9e6821..f545603 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ with driver("192.0.2.20") as speaker: | Getter / action | | |---|---| | `get_facts` | from the speaker info read at `open()` | -| `get_interfaces`, `get_interfaces_ip` | one interface, `wlan0`, for the speaker's network connection (see below) | +| `get_interfaces` | one interface, `wlan0`, for the speaker's network connection (see below) | | `get_playback_state` | `{"state": "playing"\|"paused"\|"stopped"\|"transitioning", "source": …}` (media contract) | | `get_current_track` | yes | | `get_volume`, `set_volume`, `get_mute`, `set_mute` | yes | @@ -47,8 +47,9 @@ speaker's connection, whatever its medium. ## Not supported Configuration management (`load_replace_candidate` and `load_merge_candidate` raise -`NotImplementedError`), configuration export (`get_config`), the CLI, and every -routing, LLDP, ARP, MAC table, NTP, SNMP, BGP, optics, probe, user, network-instance, +`NotImplementedError`), configuration export (`get_config`), the CLI (`cli`, NAPALM's +stub), the interface addresses (`get_interfaces_ip`: the speaker reports no prefix +length, and SoCo has no reading for one), 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". diff --git a/napalm_sonos/sonos_driver.py b/napalm_sonos/sonos_driver.py index 88fe78f..dfaec2e 100644 --- a/napalm_sonos/sonos_driver.py +++ b/napalm_sonos/sonos_driver.py @@ -153,20 +153,6 @@ class SonosDriver(MediaDriver): } return interfaces - def get_interfaces_ip(self) -> dict[str, dict[str, Any]]: - """Return the speaker's address, on its one connection (see :meth:`get_interfaces`).""" - if not self._speaker_info: - return {} - info = self._speaker_info - ip = info.get("ip_address", self.hostname) - - ipv4_entry = { - ip: { - "prefix_length": 24, - } - } - return {_INTERFACE: {"ipv4": ipv4_entry, "ipv6": {}}} - def ping( self, destination: str, @@ -197,10 +183,6 @@ class SonosDriver(MediaDriver): "error": "Not supported on Sonos", } - def cli(self, commands: list[str]) -> list[dict[str, Any]]: - """Run CLI commands (not supported on Sonos).""" - return [] - def commit_config(self) -> None: """Commit the candidate config (no-op on Sonos).""" pass diff --git a/tests/test_sonos.py b/tests/test_sonos.py index 59a6a4b..6ff694f 100644 --- a/tests/test_sonos.py +++ b/tests/test_sonos.py @@ -117,14 +117,8 @@ class TestSonosDriver: interfaces = self.driver.get_interfaces() assert "eth0" not in self.driver.get_facts()["interface_list"] assert "eth0" not in interfaces - assert "eth0" not in self.driver.get_interfaces_ip() assert list(interfaces) == ["wlan0"] - def test_get_interfaces_ip(self): - ifaces_ip = self.driver.get_interfaces_ip() - assert "wlan0" in ifaces_ip - assert "192.168.1.100" in ifaces_ip["wlan0"]["ipv4"] - def test_get_playback_state_has_the_contracts_shape(self): """``{"state", "source"}`` as napalm-device-types' MediaDriver declares it (#11).""" self.mock_device.music_source = "RADIO" @@ -346,6 +340,8 @@ _NOT_SUPPORTED_GETTERS = [ "get_config", "get_environment", "get_firewall_policies", + # The speaker reports no prefix length; it was always given as 24 (#15). + "get_interfaces_ip", "get_lldp_neighbors", "get_lldp_neighbors_detail", "get_mac_address_table", @@ -367,6 +363,18 @@ def test_an_unsupported_getter_is_napalms_stub(getter): assert getattr(SonosDriver, getter) is getattr(NetworkDriver, getter) +def test_cli_is_napalms_stub(): + """A speaker has no CLI; `[]` was not even NAPALM's dict shape (#15).""" + assert SonosDriver.cli is NetworkDriver.cli + with pytest.raises(NotImplementedError): + SonosDriver("192.0.2.20").cli(["show version"]) + + +def test_get_interfaces_ip_says_not_implemented(): + with pytest.raises(NotImplementedError): + SonosDriver("192.0.2.20").get_interfaces_ip() + + 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):