fix: decrypt DAL reads, read the uplink and facts from the gateway's answers #31
No files matched your search
+3
-3
@@ -41,9 +41,9 @@ All notable changes to this driver. The format follows
|
|||||||
from `getBasicInformation`, which a VMG4005-B50A does not send them in, and reported
|
from `getBasicInformation`, which a VMG4005-B50A does not send them in, and reported
|
||||||
`""` and `0`. They now come from `DeviceInfo` in the DAL's `cardpage_status`, the
|
`""` and `0`. They now come from `DeviceInfo` in the DAL's `cardpage_status`, the
|
||||||
answer the interfaces are read from; `get_facts()` reads that answer once for both.
|
answer the interfaces are read from; `get_facts()` reads that answer once for both.
|
||||||
- `get_facts()` reports the gateway's host name and domain: `hostname` is the name on
|
- `get_facts()` reports the gateway's host name and domain (#24): `hostname` is the
|
||||||
the gateway's System page (`GET /cgi-bin/System?oid=snmp`), `fqdn` that name with its
|
name on the gateway's System page (`GET /cgi-bin/System?oid=snmp`), `fqdn` that name
|
||||||
domain (`VMG4005-B50A.home`). Both were read from `getBasicInformation`, which a
|
with its domain (`VMG4005-B50A.home`). Both were read from `getBasicInformation`, which a
|
||||||
VMG4005-B50A does not send them in, so they fell back to the address the driver
|
VMG4005-B50A does not send them in, so they fell back to the address the driver
|
||||||
connects to and netOrk kept the device named `192.168.1.1`. A gateway with no name
|
connects to and netOrk kept the device named `192.168.1.1`. A gateway with no name
|
||||||
set reports `""`; `get_facts()` raises when the System page cannot be read.
|
set reports `""`; `get_facts()` raises when the System page cannot be read.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ with driver("192.0.2.1", "admin", "secret", optional_args={"use_tls": True}) as
|
|||||||
|
|
||||||
| Getter / action | Source |
|
| Getter / action | Source |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `get_facts` | basic device information |
|
| `get_facts` | basic device information (model, firmware), the System page (host name, domain), DAL `cardpage_status` (serial number, uptime, interfaces) |
|
||||||
| `get_interfaces`, `get_interfaces_ip` | basic device information (WAN, LAN, Wi-Fi) |
|
| `get_interfaces`, `get_interfaces_ip` | basic device information (WAN, LAN, Wi-Fi) |
|
||||||
| `get_arp_table` | derived from the active LAN hosts |
|
| `get_arp_table` | derived from the active LAN hosts |
|
||||||
| `get_wan_status` | DAL `cardpage_status`: the DSL line and the WAN interfaces |
|
| `get_wan_status` | DAL `cardpage_status`: the DSL line and the WAN interfaces |
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import pytest
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from napalm_zyxel import ZyxelVMGDriver
|
from napalm_zyxel import ZyxelVMGDriver
|
||||||
|
from tests import gateway
|
||||||
|
|
||||||
BASIC_INFO: dict[str, Any] = {
|
BASIC_INFO: dict[str, Any] = {
|
||||||
"result": "ZCFG_SUCCESS",
|
"result": "ZCFG_SUCCESS",
|
||||||
@@ -174,3 +175,29 @@ def test_get_facts_reads_the_status_page_once():
|
|||||||
def test_get_facts_raises_when_the_status_page_cannot_be_read():
|
def test_get_facts_raises_when_the_status_page_cannot_be_read():
|
||||||
with pytest.raises(RuntimeError, match="cardpage_status"):
|
with pytest.raises(RuntimeError, match="cardpage_status"):
|
||||||
_driver(status=_response(500)).get_facts()
|
_driver(status=_response(500)).get_facts()
|
||||||
|
|
||||||
|
|
||||||
|
# --- the recorded answers (#24) ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_facts_of_the_recorded_gateway():
|
||||||
|
"""``getBasicInformation`` gives model and firmware only; nothing else is read from
|
||||||
|
it. The status page is the full recorded one, sealed (``tests/gateway.py``)."""
|
||||||
|
drv = gateway.driver(
|
||||||
|
{gateway.dal("cardpage_status"): gateway.fixture("cardpage_status"), SYSTEM_PATH: SYSTEM}
|
||||||
|
)
|
||||||
|
assert drv._device_info == gateway.fixture("getBasicInformation")
|
||||||
|
assert drv.get_facts() == {
|
||||||
|
"vendor": "Zyxel",
|
||||||
|
"model": "VMG4005-B50A",
|
||||||
|
"serial_number": "S000Y00000001",
|
||||||
|
"os_version": "V5.17(ABQA.3.1)C0",
|
||||||
|
"hostname": "VMG4005-B50A",
|
||||||
|
"fqdn": "VMG4005-B50A.home",
|
||||||
|
"uptime": 13554213,
|
||||||
|
"interface_list": ["br0", "atm0.1", "ptm0.2", "eth1"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_basic_information_is_the_recorded_answer():
|
||||||
|
assert BASIC_INFO == gateway.fixture("getBasicInformation")
|
||||||
+11
-19
@@ -6,18 +6,11 @@ import requests
|
|||||||
from napalm.base.exceptions import ConnectionException
|
from napalm.base.exceptions import ConnectionException
|
||||||
|
|
||||||
from napalm_zyxel import ZyxelVMGDriver
|
from napalm_zyxel import ZyxelVMGDriver
|
||||||
|
from tests.gateway import fixture
|
||||||
|
|
||||||
MOCK_BASIC_INFO = {
|
#: The recorded getBasicInformation answer of a VMG4005-B50A: model and firmware, no
|
||||||
"ModelName": "VMG4005-B50A",
|
#: serial number, host name, uptime, MAC or WAN state (#24). tests/gateway.py
|
||||||
"SoftwareVersion": "V5.13(ABKS.1)C0",
|
MOCK_BASIC_INFO = fixture("getBasicInformation")
|
||||||
"WanIp": "85.2.34.56",
|
|
||||||
"LanIp": "192.168.1.1",
|
|
||||||
"MacAddress": "00:1A:2B:3C:4D:5E",
|
|
||||||
"SystemUpTime": "1234567",
|
|
||||||
"WanAccessType": "VDSL",
|
|
||||||
"MaxUpstream": "30000000",
|
|
||||||
"MaxDownstream": "100000000",
|
|
||||||
}
|
|
||||||
|
|
||||||
MOCK_RSA_KEY = (
|
MOCK_RSA_KEY = (
|
||||||
"-----BEGIN PUBLIC KEY-----\n"
|
"-----BEGIN PUBLIC KEY-----\n"
|
||||||
@@ -86,10 +79,9 @@ class TestZyxelVMGDriver:
|
|||||||
if "getRSAPublickKey" in url:
|
if "getRSAPublickKey" in url:
|
||||||
return MockResponse({"RSAPublicKey": MOCK_RSA_KEY})
|
return MockResponse({"RSAPublicKey": MOCK_RSA_KEY})
|
||||||
if "cgi-bin/System?oid=snmp" in url: # tests/test_facts.py
|
if "cgi-bin/System?oid=snmp" in url: # tests/test_facts.py
|
||||||
return MockResponse([{"HostName": "ZyxelVMG", "DomainName": "home"}])
|
return MockResponse([{"HostName": "VMG4005-B50A", "DomainName": "home"}])
|
||||||
if "cgi-bin/DAL?oid=cardpage_status" in url: # tests/test_facts.py
|
if "cgi-bin/DAL?oid=cardpage_status" in url: # tests/test_facts.py
|
||||||
device = {"SerialNumber": "S220L12345678", "UpTime": 1234567}
|
return MockResponse(fixture("cardpage_status"))
|
||||||
return MockResponse({"result": "ZCFG_SUCCESS", "Object": [{"DeviceInfo": device}]})
|
|
||||||
if "UserLogout" in url:
|
if "UserLogout" in url:
|
||||||
return MockResponse({})
|
return MockResponse({})
|
||||||
return MockResponse({})
|
return MockResponse({})
|
||||||
@@ -182,11 +174,11 @@ class TestZyxelVMGDriver:
|
|||||||
facts = self.driver.get_facts()
|
facts = self.driver.get_facts()
|
||||||
assert facts["vendor"] == "Zyxel"
|
assert facts["vendor"] == "Zyxel"
|
||||||
assert facts["model"] == "VMG4005-B50A"
|
assert facts["model"] == "VMG4005-B50A"
|
||||||
assert facts["serial_number"] == "S220L12345678"
|
assert facts["serial_number"] == "S000Y00000001"
|
||||||
assert facts["os_version"] == "V5.13(ABKS.1)C0"
|
assert facts["os_version"] == "V5.17(ABQA.3.1)C0"
|
||||||
assert facts["hostname"] == "ZyxelVMG"
|
assert facts["hostname"] == "VMG4005-B50A"
|
||||||
assert facts["fqdn"] == "ZyxelVMG.home"
|
assert facts["fqdn"] == "VMG4005-B50A.home"
|
||||||
assert facts["uptime"] == 1234567
|
assert facts["uptime"] == 13554213
|
||||||
|
|
||||||
def test_get_port_forwards_empty(self):
|
def test_get_port_forwards_empty(self):
|
||||||
self._setup_mocked_http()
|
self._setup_mocked_http()
|
||||||
|
|||||||
Reference in new issue
Block a user