One Redfish answer (the service root or the error a service refuses it with) and one landing page (Supermicro/ATEN, iDRAC or iLO) can match, never all of them. Grouped, the driver's maximum in netOrk's discovery is 21 instead of 41, and a Supermicro landing page alone (6 of 21) outranks the "linux" its BMC reports over SNMP (5 of 18). Requires napalm-device-types 4.8 for FingerprintRule.group.
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
"""What netOrk's discovery scores the driver on, checked against recorded pages.
|
|
|
|
netOrk lowercases the page (title, Server header, body) and matches each rule's
|
|
pattern as a substring; a port that answers adds its PortSpec weight.
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from napalm_redfish import RedfishDriver
|
|
|
|
X10 = Path(__file__).parent / "fixtures" / "supermicro-x10drl-i-3.91"
|
|
|
|
|
|
def _score(text: str) -> float:
|
|
text = " ".join(text.lower().split())
|
|
return sum(rule.weight for rule in RedfishDriver.HTTP_FINGERPRINT if rule.pattern in text)
|
|
|
|
|
|
def test_an_open_https_port_proves_nothing():
|
|
# Every switch with a web UI answers on 443; the port alone made six of
|
|
# them look like BMCs.
|
|
assert [spec.weight for spec in RedfishDriver.PORT_SPECS if spec.port == 443] == [0.0]
|
|
|
|
|
|
def test_service_root_is_still_probed():
|
|
assert any("/redfish/v1/" in spec.paths for spec in RedfishDriver.PORT_SPECS)
|
|
|
|
|
|
def test_supermicro_landing_page_is_recognised():
|
|
assert _score((X10 / "landing_page.html").read_text()) >= 6.0
|
|
|
|
|
|
def test_redfish_error_body_is_recognised():
|
|
# An unlicensed X10 refuses even the service root, but the refusal is
|
|
# unmistakably Redfish.
|
|
assert _score(json.dumps(json.loads((X10 / "service_root_403.json").read_text()))) >= 6.0
|
|
|
|
|
|
def test_idrac_and_ilo_landing_pages_are_recognised():
|
|
assert _score("<title>iDRAC9 - Login</title>") >= 6.0
|
|
assert _score("<title>iLO 5</title> HPE Integrated Lights-Out") >= 6.0
|
|
|
|
|
|
def test_a_switch_page_scores_nothing():
|
|
page = '<html><head><title>Loading...</title></head><body>Web Switch</body></html>'
|
|
assert _score(page) == 0.0
|
|
|
|
|
|
def test_alternatives_count_once_towards_the_maximum():
|
|
# One Redfish answer (service root or error), the service root's type marker, and one
|
|
# landing page: 10 + 5 + 6. Summing every alternative (41) let a bare "linux" in the
|
|
# BMC's SNMP sysDescr (5 of 18) beat the Supermicro landing page (6 of 41).
|
|
from napalm_device_types import rules_max_weight
|
|
|
|
assert rules_max_weight(RedfishDriver.HTTP_FINGERPRINT) == 21.0
|
|
|
|
|
|
def test_supermicro_landing_page_alone_outranks_a_linux_sysdescr():
|
|
from napalm_device_types import rules_max_weight
|
|
|
|
page = _score((X10 / "landing_page.html").read_text())
|
|
assert page / rules_max_weight(RedfishDriver.HTTP_FINGERPRINT) > 5.0 / 18.0
|