fix: IPMI polls after the first failed; BMC drivers collect SNMP health (0.2.1)

The second IPMI poll of a BMC in the same worker process failed with
"'<' not supported between instances of 'float' and 'NoneType'".
pyghmi files a session in Session.initting_sessions under the
credentials as str and deletes it only under bytes, so the entry stays
and the next Command got the old, logged-out session back. The driver
drops that entry itself before open() and after close(). Reproduced and
verified live against the Supermicro X10DRL-i: three polls in one
process now succeed.

IpmiDriver and RedfishDriver mix in HealthMetricsMixin, so netOrk's
SNMP health poll reads the BMC's own load, memory and interfaces where
the BMC runs net-snmp with the UCD-MIB, as the X10's does.
This commit is contained in:
christianmanivong committed 2026-10-13 11:24:29 +02:00
1 parent 332e6090a7
commit 0e38e18e26
6 files changed
+81 -10

No files matched your search

+35 -1
View File
@@ -28,7 +28,7 @@ class FakeCommand:
instances: list = []
def __init__(self, bmc=None, userid=None, password=None, port=623, keepalive=True, **kw):
def __init__(self, bmc=None, userid=None, password=None, port=623, **kw):
self.args = {"bmc": bmc, "userid": userid, "password": password, "port": port}
self.logged_out = False
self.ipmi_session = SimpleNamespace(logout=self._logout)
@@ -246,3 +246,37 @@ def test_napalm_still_finds_redfish_by_name():
from napalm_redfish import RedfishDriver
assert napalm.get_network_driver("redfish") is RedfishDriver
def test_each_open_and_close_forgets_pyghmis_cached_session(monkeypatch):
# pyghmi files a session in Session.initting_sessions under the credentials as str
# and deletes it only under bytes, so it stays; the next Command for the BMC in the
# same process got the old, logged-out one back and failed with "'<' not supported
# between float and NoneType". Reproduced live against the X10, fixed by this.
cache = {}
monkeypatch.setattr(ipmi, "Session", SimpleNamespace(initting_sessions=cache))
key = ("192.0.2.150", "netork", "s3cret", 623, None)
cache[key] = "stale session of an earlier poll"
d = IpmiDriver("192.0.2.150", "netork", "s3cret")
d.open()
assert key not in cache
cache[key] = "this poll's session"
d.close()
assert key not in cache
assert FakeCommand.instances[0].logged_out
def test_both_drivers_collect_the_bmcs_own_snmp_health():
# Many BMCs run net-snmp with the UCD-MIB (the X10's answers load, memory, CPU idle and
# five interfaces), so netOrk's SNMP health poll covers the BMC itself. The managed
# server's sensors stay with get_environment.
from napalm_device_types import HealthMetricsMixin
from napalm_device_types.roles import role_keys_of
from napalm_redfish import RedfishDriver
for cls in (IpmiDriver, RedfishDriver):
assert issubclass(cls, HealthMetricsMixin), cls.__name__
assert role_keys_of(cls) == ["management_controller"]