fix(plus): stop reporting unread or failed reads as empty
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m16s
CI / driver (pull_request) Successful in 3m7s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m17s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m16s
CI / driver (pull_request) Successful in 3m7s
driver / publish (pull_request) Skipped
Netgear Plus answered reads its web interface cannot do (MAC table,
LLDP, config, users, SNMP, NTP) with empty values without asking the
switch; those now fall through to NAPALM's NotImplementedError, and the
switch-role getters that only returned {} (spanning tree, port channels,
802.1X, MAC ACL) are gone, as device-types reads capability from the
method being there. get_vlans_detail raises when vlan.cgi cannot be
read, get_vlans keys VLANs by int, and Smart get_snmp_config raises when
show snmp fails instead of reading as "no SNMP".
Closes #21
This commit is contained in:
1 parent
411fed5532
commit
7e3c7d6285
6 files changed
+169
-137
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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 = (
|
||||
'<span vid-4 class="x"><i class="y"></i>1</span><span vnm-4 class="z">Default</span>'
|
||||
'<span vid-4 class="x"><i class="y"></i>24</span><span vnm-4 class="z">Guest</span>'
|
||||
'<span class="p pvid-str">1*,</span>'
|
||||
'<span class="p pvid-str">1*, 24,</span>'
|
||||
)
|
||||
|
||||
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()
|
||||
Reference in new issue
Block a user