fix(driver): leave get_interfaces_ip and cli to NAPALM's stubs
driver / standard (pull_request) Successful in 22s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 4m13s
driver / test (3.13) (pull_request) Successful in 4m5s
driver / lowest (pull_request) Successful in 3m38s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 1m19s
CI / driver (pull_request) Successful in 6m10s
driver / publish (pull_request) Skipped

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
This commit is contained in:
Christian Manivong committed 2026-11-12 19:23:25 +01:00
1 parent bb55884216
commit 397917a174
4 files changed
+23 -27

No files matched your search

+5
View File
@@ -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()`
+4 -3
View File
@@ -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".
-18
View File
@@ -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
+14 -6
View File
@@ -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):