"""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 from napalm_redfish.bmc import BmcDriver from napalm_redfish.ipmi import IpmiDriver 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 BmcDriver.HTTP_FINGERPRINT if rule.pattern in text) def test_discovery_suggests_the_bmc_driver_only(): # bmc works with and without a license; two drivers on the same rules would tie. assert BmcDriver.HTTP_FINGERPRINT assert RedfishDriver.HTTP_FINGERPRINT == [] assert not RedfishDriver.PORT_SPECS assert IpmiDriver.HTTP_FINGERPRINT == [] 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 BmcDriver.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 BmcDriver.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("