test(facts): check get_facts against the gateway's recorded answers (#24)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m5s
driver / test (3.13) (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 2m35s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m5s
driver / test (3.13) (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Successful in 1m5s
CI / driver (pull_request) Successful in 2m35s
driver / publish (pull_request) Skipped
get_facts read SerialNumber, HostName, SystemUpTime and MacAddress from getBasicInformation, which a VMG4005-B50A (V5.17(ABQA.3.1)C0) answers with model, firmware and language settings only. The code was fixed by #26 (host name and domain from the System page) and #28 (serial number and uptime from cardpage_status); the tests still fed it an invented getBasicInformation (MOCK_BASIC_INFO) that carried those fields, with an invented serial number and firmware. MOCK_BASIC_INFO is now the recorded answer, and a new test reads the facts from the recorded, sealed status page and the System page: it fails against the driver before #26 with the symptoms of this issue (serial "", uptime 0, host name the connection address). The README names the sources get_facts reads. Closes #24
This commit is contained in:
1 parent
3213dfaaaa
commit
b6668eddbd
4 files changed
+42
-23
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
|
||||
`""` 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.
|
||||
- `get_facts()` reports the gateway's host name and domain: `hostname` is the name on
|
||||
the gateway's System page (`GET /cgi-bin/System?oid=snmp`), `fqdn` that name with its
|
||||
domain (`VMG4005-B50A.home`). Both were read from `getBasicInformation`, which a
|
||||
- `get_facts()` reports the gateway's host name and domain (#24): `hostname` is the
|
||||
name on the gateway's System page (`GET /cgi-bin/System?oid=snmp`), `fqdn` that name
|
||||
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
|
||||
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.
|
||||
|
||||
@@ -35,7 +35,7 @@ with driver("192.0.2.1", "admin", "secret", optional_args={"use_tls": True}) as
|
||||
|
||||
| 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_arp_table` | derived from the active LAN hosts |
|
||||
| `get_wan_status` | DAL `cardpage_status`: the DSL line and the WAN interfaces |
|
||||
|
||||
@@ -26,6 +26,7 @@ import pytest
|
||||
import requests
|
||||
|
||||
from napalm_zyxel import ZyxelVMGDriver
|
||||
from tests import gateway
|
||||
|
||||
BASIC_INFO: dict[str, Any] = {
|
||||
"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():
|
||||
with pytest.raises(RuntimeError, match="cardpage_status"):
|
||||
_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_zyxel import ZyxelVMGDriver
|
||||
from tests.gateway import fixture
|
||||
|
||||
MOCK_BASIC_INFO = {
|
||||
"ModelName": "VMG4005-B50A",
|
||||
"SoftwareVersion": "V5.13(ABKS.1)C0",
|
||||
"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",
|
||||
}
|
||||
#: The recorded getBasicInformation answer of a VMG4005-B50A: model and firmware, no
|
||||
#: serial number, host name, uptime, MAC or WAN state (#24). tests/gateway.py
|
||||
MOCK_BASIC_INFO = fixture("getBasicInformation")
|
||||
|
||||
MOCK_RSA_KEY = (
|
||||
"-----BEGIN PUBLIC KEY-----\n"
|
||||
@@ -86,10 +79,9 @@ class TestZyxelVMGDriver:
|
||||
if "getRSAPublickKey" in url:
|
||||
return MockResponse({"RSAPublicKey": MOCK_RSA_KEY})
|
||||
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
|
||||
device = {"SerialNumber": "S220L12345678", "UpTime": 1234567}
|
||||
return MockResponse({"result": "ZCFG_SUCCESS", "Object": [{"DeviceInfo": device}]})
|
||||
return MockResponse(fixture("cardpage_status"))
|
||||
if "UserLogout" in url:
|
||||
return MockResponse({})
|
||||
return MockResponse({})
|
||||
@@ -182,11 +174,11 @@ class TestZyxelVMGDriver:
|
||||
facts = self.driver.get_facts()
|
||||
assert facts["vendor"] == "Zyxel"
|
||||
assert facts["model"] == "VMG4005-B50A"
|
||||
assert facts["serial_number"] == "S220L12345678"
|
||||
assert facts["os_version"] == "V5.13(ABKS.1)C0"
|
||||
assert facts["hostname"] == "ZyxelVMG"
|
||||
assert facts["fqdn"] == "ZyxelVMG.home"
|
||||
assert facts["uptime"] == 1234567
|
||||
assert facts["serial_number"] == "S000Y00000001"
|
||||
assert facts["os_version"] == "V5.17(ABQA.3.1)C0"
|
||||
assert facts["hostname"] == "VMG4005-B50A"
|
||||
assert facts["fqdn"] == "VMG4005-B50A.home"
|
||||
assert facts["uptime"] == 13554213
|
||||
|
||||
def test_get_port_forwards_empty(self):
|
||||
self._setup_mocked_http()
|
||||
|
||||
Reference in new issue
Block a user