diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e6212d..61a6191 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,12 +7,28 @@ All notable changes to this driver. The format follows
## [Unreleased]
### Changed
+- **Breaking:** Netgear Plus `get_vlans` keys are `int` VLAN ids, as in NAPALM's
+ `get_vlans`; they were strings (`"1"`). `get_vlans_detail` keeps its string keys
+ (#21).
- Python 3.12 is the floor (`requires-python = ">=3.12"`): netOrk runs every driver
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.
### Fixed
+- Reads the Netgear Plus web interface cannot do raise NAPALM's own
+ `NotImplementedError` instead of answering with empty values without asking the switch
+ (#21): `get_mac_address_table`, `get_lldp_neighbors`, `get_lldp_neighbors_detail`,
+ `get_config`, `get_users`, `get_snmp_information`, `get_ntp_servers`, `get_ntp_peers`
+ and `get_ntp_stats`. An application can tell "not supported" from "read, none" again.
+ `get_arp_table` still returns `[]`: the switches are L2 only.
+- Netgear Plus `get_vlans_detail` and `get_vlans` raise when `vlan.cgi` cannot be read
+ (`ConnectionException` when the request fails, `RuntimeError` for an error answer or
+ an empty page). They reported a switch without VLANs (#21).
+- Smart `get_snmp_config` raises when `show snmp` fails. It returned `None`, the same
+ as a switch without SNMP (#21).
+- The README's requirements match `pyproject.toml`: NAPALM 5.1 (it said 4.0), and
+ paramiko and netaddr are listed (#22).
- The README describes `netgear_plus` too (#19). Its getter table now has a column per
driver: on Plus switches most getters return empty values without asking the switch,
and `cli`, `ping`, `get_route_to` and the configuration methods raise
@@ -34,6 +50,10 @@ All notable changes to this driver. The format follows
older floors (napalm 4.0, napalm-device-types 4.16) than the driver needs.
### Removed
+- **Breaking:** the Netgear Plus driver no longer has `get_spanning_tree`,
+ `get_port_channels`, `get_dot1x_ports` and `get_mac_acl`. They returned an empty dict
+ without asking the switch; napalm-device-types declares them for switches that can
+ read them, and an application tells that by the method being there (#21).
- **Breaking:** the Netgear Plus driver no longer has `set_vlan`, `delete_vlan` and
`set_interface`. They only raised `NotImplementedError`; an application that tells
what a switch can do by whether the method exists offered VLAN and port editing on
diff --git a/README.md b/README.md
index 8b6cbb2..7aaea0d 100644
--- a/README.md
+++ b/README.md
@@ -28,11 +28,15 @@ The two drivers share the package, not their abilities: `netgear_plus` reads far
| Dependency | Minimum version |
|---|---|
| Python | 3.12 |
-| NAPALM | 4.0 |
+| NAPALM | 5.1 |
| napalm-device-types | 4.21.1 |
-| Netmiko | 4.0 |
+| Netmiko | 4.0.0 |
+| paramiko | 5.0.0 |
+| netaddr | 0.7.19 |
| py-netgear-plus (`netgear_plus`) | 0.6.4 |
+The same floors as `pyproject.toml`; `pip` installs all of them with the package.
+
## Installation
```bash
@@ -71,21 +75,21 @@ with driver("192.168.0.239", "admin", "password") as device:
| `get_facts` | ✅ | ✅ | model, hostname, os_version, serial; `uptime` is always `0.0` |
| `get_interfaces` | ✅ | ✅ | link, speed, port name; `is_enabled` always `True`, `mtu` always 1518, no MAC |
| `get_interfaces_ip` | ✅ | ⚪ | |
-| `get_config` | ✅ | ⚪ | empty strings for running, startup and candidate |
-| `get_arp_table` | ✅ | ⚪ | |
-| `get_mac_address_table` | ✅ | ⚪ | |
-| `get_lldp_neighbors` | ✅ | ⚪ | |
-| `get_lldp_neighbors_detail` | ✅ | ⚪ | |
-| `get_vlans` | ✅ | ✅ | 802.1Q VLANs from the web page `vlan.cgi`; keys are strings (`"1"`) |
-| `get_vlans_detail` | ❌ | ✅ | tagged and untagged ports per VLAN |
+| `get_config` | ✅ | ❌ | the web interface has no configuration text |
+| `get_arp_table` | ✅ | ⚪ | the switches are L2 only: no ARP table |
+| `get_mac_address_table` | ✅ | ❌ | |
+| `get_lldp_neighbors` | ✅ | ❌ | |
+| `get_lldp_neighbors_detail` | ✅ | ❌ | |
+| `get_vlans` | ✅ | ✅ | 802.1Q VLANs from the web page `vlan.cgi`; raises when it cannot be read |
+| `get_vlans_detail` | ❌ | ✅ | tagged and untagged ports per VLAN; keys are strings (`"1"`) |
| `get_environment` | ✅ | ✅ | Smart: CPU + memory only. Plus: PoE power status per PoE port only |
| `get_interfaces_counters` | ✅ | ✅ | rx/tx octets from the switch's cumulative totals, CRC errors as rx_errors; the rest `0` |
-| `get_users` | ✅ | ⚪ | |
-| `get_snmp_information` | ✅ | ⚪ | |
+| `get_users` | ✅ | ❌ | |
+| `get_snmp_information` | ✅ | ❌ | |
| `get_snmp_config` | ✅ | ⚪ | always `None`: SNMP is not read |
-| `get_ntp_servers` | ✅ | ⚪ | |
-| `get_ntp_peers` | ✅ | ⚪ | Smart: same as servers |
-| `get_ntp_stats` | ⚪ | ⚪ | not exposed via the Smart CLI |
+| `get_ntp_servers` | ✅ | ❌ | |
+| `get_ntp_peers` | ✅ | ❌ | Smart: same as servers |
+| `get_ntp_stats` | ⚪ | ❌ | not exposed via the Smart CLI |
| `get_route_to` | ✅ | ❌ | Smart: static/connected only |
| `get_poe_status` | ✅ | ✅ | delivering or searching per PoE port, the model's power budgets; `enabled` always `True`, no power draw |
| `set_poe_enabled` | ❌ | ✅ | |
@@ -105,8 +109,8 @@ with driver("192.168.0.239", "admin", "password") as device:
| `get_optics` | ⚪ | ❌ | DDM not exposed via the Smart CLI |
| `get_ipv6_neighbors_table` | ⚪ | ❌ | not exposed via the Smart CLI |
-`netgear_plus` also has `get_spanning_tree`, `get_port_channels`, `get_dot1x_ports` and
-`get_mac_acl`; they always return an empty dict.
+Neither driver has `get_spanning_tree`, `get_port_channels`, `get_dot1x_ports` or
+`get_mac_acl`.
## Connecting
diff --git a/napalm_netgear/netgear_plus.py b/napalm_netgear/netgear_plus.py
index a547536..6f8b406 100644
--- a/napalm_netgear/netgear_plus.py
+++ b/napalm_netgear/netgear_plus.py
@@ -396,14 +396,6 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
"memory": {},
}
- def get_mac_address_table(self) -> list[dict]:
- """Return the MAC address table.
-
- Not available via the HTTP web interface of Plus switches.
- Returns an empty list.
- """
- return []
-
def get_arp_table(self, vrf: str = "") -> list[dict]:
"""Return the ARP table.
@@ -412,22 +404,6 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
"""
return []
- def get_lldp_neighbors(self) -> dict[str, Any]:
- """Return LLDP neighbors.
-
- Not supported on Netgear Plus switches.
- Returns an empty dict.
- """
- return {}
-
- def get_lldp_neighbors_detail(self, interface: str = "") -> dict[str, Any]:
- """Return detailed LLDP neighbor info.
-
- Not supported on Netgear Plus switches.
- Returns an empty dict.
- """
- return {}
-
def get_vlans_detail(self) -> dict[str, Any]:
"""Return VLAN configuration by scraping the switch's /vlan.cgi page.
@@ -440,16 +416,7 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
"""
import re
- url = f"http://{self.hostname}/vlan.cgi"
- try:
- resp = self._connector.fetch_page("get", url, {})
- except Exception:
- return {}
-
- if not resp or resp.status_code != 200 or not resp.text:
- return {}
-
- text = resp.text
+ text = self._fetch_vlan_page()
# Parse VLAN IDs and names from vid-4 / vnm-4 span pairs.
# Example: ...24Guest
@@ -496,7 +463,19 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
return vlans
- def get_vlans(self) -> dict[str, Any]:
+ def _fetch_vlan_page(self) -> str:
+ """The text of ``vlan.cgi``; a failed fetch or an answer that is no page raises (#21)."""
+ url = f"http://{self.hostname}/vlan.cgi"
+ try:
+ resp = self._connector.fetch_page("get", url, {})
+ except Exception as exc: # py-netgear-plus passes on whatever its request raised
+ raise ConnectionException(f"Cannot read {url}: {exc}") from exc
+ if not resp or resp.status_code != 200 or not resp.text:
+ status = getattr(resp, "status_code", None)
+ raise RuntimeError(f"{url} answered with no VLAN page (HTTP {status})")
+ return str(resp.text)
+
+ def get_vlans(self) -> dict[int, Any]:
"""Return VLAN information (standard NAPALM format).
Delegates to get_vlans_detail() and merges tagged and untagged ports
@@ -504,27 +483,13 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
"""
detail = self.get_vlans_detail()
return {
- vid: {
+ int(vid): {
"name": info["name"],
"interfaces": info["tagged"] + info["untagged"],
}
for vid, info in detail.items()
}
- def get_config(
- self,
- retrieve: str = "all",
- full: bool = False,
- sanitized: bool = False,
- format: str = "text",
- ) -> dict[str, str]:
- """Return device configuration.
-
- Netgear Plus switches do not expose running/startup config via HTTP.
- Returns empty strings for all config slots.
- """
- return {"running": "", "startup": "", "candidate": ""}
-
def load_merge_candidate(self, filename: str | None = None, config: str | None = None) -> None:
raise NotImplementedError("Config management is not supported for Netgear Plus switches.")
@@ -571,73 +536,10 @@ class NetgearPlusDriver(FirmwareOfferMixin, SwitchDriver):
"cli() is not supported for Netgear Plus switches (HTTP-only device)."
)
- def get_users(self) -> dict[str, Any]:
- """Return user accounts.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_snmp_information(self) -> dict[str, Any]:
- """Return SNMP configuration.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_ntp_servers(self) -> dict[str, Any]:
- """Return configured NTP servers.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_ntp_peers(self) -> dict[str, Any]:
- """Return NTP peers.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_ntp_stats(self) -> list[dict]:
- """Return NTP stats.
-
- Not available via HTTP API. Returns an empty list.
- """
- return []
-
# ------------------------------------------------------------------
- # SwitchDriver abstract methods (not applicable for this device)
+ # PoE
# ------------------------------------------------------------------
- def get_spanning_tree(self) -> dict[str, Any]:
- """Return spanning tree status.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_port_channels(self) -> dict[str, Any]:
- """Return port-channel information.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_dot1x_ports(self) -> dict[str, Any]:
- """Return 802.1X port configuration.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
- def get_mac_acl(self) -> dict[str, Any]:
- """Return MAC ACL information.
-
- Not available via HTTP API. Returns an empty dict.
- """
- return {}
-
def get_poe_status(self) -> dict[str, Any]:
"""Return PoE status.
diff --git a/napalm_netgear/netgear_smart.py b/napalm_netgear/netgear_smart.py
index c5db884..61e7ab1 100644
--- a/napalm_netgear/netgear_smart.py
+++ b/napalm_netgear/netgear_smart.py
@@ -1847,11 +1847,7 @@ class NetgearSmartDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
except ImportError:
return None
- try:
- out = self._send_command("show snmp")
- except Exception:
- return None
-
+ out = self._send_command("show snmp") # a failed read raises (#21)
if not out:
return None
diff --git a/tests/quality_baseline.json b/tests/quality_baseline.json
index 452714d..64491bd 100644
--- a/tests/quality_baseline.json
+++ b/tests/quality_baseline.json
@@ -1,7 +1,6 @@
{
"coverage_floor": 48.0,
"function_complexity": {
- "napalm_netgear/netgear_plus.py::NetgearPlusDriver.get_vlans_detail": 14,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver._add_lag_info_v7": 13,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver._get_lldp_table": 12,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver._get_lldp_table_v7": 11,
@@ -11,11 +10,11 @@
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_interfaces_counters": 12,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_poe_status": 11,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_route_to": 12,
- "napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_snmp_config": 16,
+ "napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_snmp_config": 15,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_snmp_information": 11
},
"function_lines": {
- "napalm_netgear/netgear_plus.py::NetgearPlusDriver.get_vlans_detail": 67,
+ "napalm_netgear/netgear_plus.py::NetgearPlusDriver.get_vlans_detail": 58,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver._parse_interfaces": 78,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_arp_table": 52,
"napalm_netgear/netgear_smart.py::NetgearSmartDriver.get_facts": 64,
@@ -31,7 +30,7 @@
"napalm_netgear.netgear_smart"
],
"python_file_lines": {
- "napalm_netgear/netgear_smart.py": 2067
+ "napalm_netgear/netgear_smart.py": 2063
},
"untyped_public": [
"napalm_netgear/netgear_plus.py::NetgearPlusDriver.get_snmp_config",
diff --git a/tests/unit/test_reads_not_empty.py b/tests/unit/test_reads_not_empty.py
new file mode 100644
index 0000000..bdf450f
--- /dev/null
+++ b/tests/unit/test_reads_not_empty.py
@@ -0,0 +1,117 @@
+"""A read that cannot happen or that failed is not reported as "nothing there" (#21).
+
+- Netgear Plus answered reads its web interface cannot do (MAC table, LLDP, the
+ configuration, users, SNMP, NTP, spanning tree, port channels, 802.1X, MAC ACLs)
+ with empty values, without asking the switch. NAPALM's getters now raise NAPALM's
+ own ``NotImplementedError``; the switch-role getters, which napalm-device-types only
+ declares, are not there at all -- as for the VLAN writes in #9.
+- Plus ``get_vlans_detail`` read a failed fetch of ``vlan.cgi`` as no VLANs, and
+ ``get_vlans`` keyed VLANs by strings where NAPALM uses ``int``.
+- Smart ``get_snmp_config`` read a failed ``show snmp`` as "no SNMP".
+"""
+
+from __future__ import annotations
+
+from unittest.mock import MagicMock
+
+import pytest
+from napalm.base import NetworkDriver
+from napalm.base.exceptions import ConnectionException
+
+from napalm_netgear.netgear_plus import NetgearPlusDriver
+from napalm_netgear.netgear_smart import NetgearSmartDriver
+
+#: The parts of ``vlan.cgi`` the driver reads, in the layout its parser documents:
+#: VLAN 1 untagged on both ports, VLAN 24 tagged on port 2.
+VLAN_PAGE = (
+ '1Default'
+ '24Guest'
+ '1*,'
+ '1*, 24,'
+)
+
+NAPALM_GETTERS = [
+ "get_mac_address_table",
+ "get_lldp_neighbors",
+ "get_lldp_neighbors_detail",
+ "get_config",
+ "get_users",
+ "get_snmp_information",
+ "get_ntp_servers",
+ "get_ntp_peers",
+ "get_ntp_stats",
+]
+SWITCH_ROLE_GETTERS = ["get_spanning_tree", "get_port_channels", "get_dot1x_ports", "get_mac_acl"]
+
+
+def _plus(page: MagicMock | Exception | None = None) -> NetgearPlusDriver:
+ driver = NetgearPlusDriver("10.0.0.20", "", "pw")
+ driver._connector = MagicMock(ports=2)
+ if isinstance(page, Exception):
+ driver._connector.fetch_page.side_effect = page
+ else:
+ driver._connector.fetch_page.return_value = page
+ return driver
+
+
+def _page(status: int, text: str) -> MagicMock:
+ return MagicMock(status_code=status, text=text)
+
+
+# --- reads Plus cannot do ---------------------------------------------------------
+
+
+@pytest.mark.parametrize("getter", NAPALM_GETTERS)
+def test_plus_leaves_a_read_it_cannot_do_to_napalm(getter):
+ """NAPALM's own stub: it raises, and an application can see it is not overridden."""
+ assert getattr(NetgearPlusDriver, getter) is getattr(NetworkDriver, getter)
+ with pytest.raises(NotImplementedError):
+ getattr(_plus(), getter)()
+
+
+@pytest.mark.parametrize("getter", SWITCH_ROLE_GETTERS)
+def test_plus_has_no_switch_role_read_it_cannot_do(getter):
+ assert not callable(getattr(NetgearPlusDriver, getter, None))
+
+
+def test_plus_still_reports_no_arp_table():
+ """An L2-only switch has no ARP table: empty is the true answer."""
+ assert _plus().get_arp_table() == []
+
+
+# --- Plus VLANs ---------------------------------------------------------------------
+
+
+def test_plus_reads_the_vlans_from_the_page():
+ assert _plus(_page(200, VLAN_PAGE)).get_vlans_detail() == {
+ "1": {"name": "Default", "tagged": [], "untagged": ["port1", "port2"]},
+ "24": {"name": "Guest", "tagged": ["port2"], "untagged": []},
+ }
+
+
+def test_plus_get_vlans_keys_are_ints():
+ vlans = _plus(_page(200, VLAN_PAGE)).get_vlans()
+ assert sorted(vlans) == [1, 24]
+ assert vlans[24] == {"name": "Guest", "interfaces": ["port2"]}
+
+
+def test_plus_vlans_raise_when_the_switch_does_not_answer():
+ with pytest.raises(ConnectionException, match="timed out"):
+ _plus(TimeoutError("timed out")).get_vlans_detail()
+
+
+@pytest.mark.parametrize("page", [None, _page(500, "error"), _page(200, "")])
+def test_plus_vlans_raise_on_an_answer_that_is_no_vlan_page(page):
+ with pytest.raises(RuntimeError, match="vlan.cgi"):
+ _plus(page).get_vlans_detail()
+
+
+# --- Smart SNMP ---------------------------------------------------------------------
+
+
+def test_smart_get_snmp_config_raises_when_show_snmp_fails():
+ driver = NetgearSmartDriver("10.0.0.21", "admin", "pw")
+ driver._send_command = MagicMock(side_effect=OSError("channel closed"))
+
+ with pytest.raises(OSError, match="channel closed"):
+ driver.get_snmp_config()