feat(system-identity): read the system firmware with the identity
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Failing after 15s
driver / types (pull_request) Successful in 52s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / lowest (pull_request) Successful in 39s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Failing after 2m17s
driver / publish (pull_request) Skipped

get_system_identity() also reads bios_vendor, bios_version and bios_date
from /sys/class/dmi/id, in the same round trip as the SMBIOS identity.
The date is given as ISO 8601; anything that is no MM/DD/YYYY reads as
empty. Only the vendors' text defaults are placeholders for the firmware:
a version of "1" is a version, unlike a serial of one repeated character.

Output of the three identity fields alone still parses, with the firmware
empty.

NetOrk/netork#2518
This commit is contained in:
christianmanivong committed 2026-11-13 23:00:23 +01:00
1 parent e43926f1d5
commit 9ecc6823c8
5 files changed
+135 -18

No files matched your search

+71 -4
View File
@@ -14,8 +14,19 @@ from napalm_device_types import (
UUID = "31303043-534D-C40C-7A72-6F1300000000"
def _out(uuid: str, product_serial: str, board_serial: str) -> str:
return f"IDBEGIN\n{uuid}\n{product_serial}\n{board_serial}\nIDEND\n"
def _out(
uuid: str,
product_serial: str,
board_serial: str,
bios: tuple[str, str, str] = ("", "", ""),
) -> str:
vendor, version, date = bios
return (
f"IDBEGIN\n{uuid}\n{product_serial}\n{board_serial}\n{vendor}\n{version}\n{date}\nIDEND\n"
)
_NO_FIRMWARE = {"bios_vendor": "", "bios_version": "", "bios_date": ""}
# ── parsing ───────────────────────────────────────────────────────────────────
@@ -26,6 +37,7 @@ def test_reads_uuid_and_both_serials():
"system_uuid": "31303043-534d-c40c-7a72-6f1300000000",
"product_serial": "S123",
"board_serial": "ZM155S026022",
**_NO_FIRMWARE,
}
@@ -81,9 +93,57 @@ def test_unreadable_files_read_as_empty():
"system_uuid": "",
"product_serial": "",
"board_serial": "BS1",
**_NO_FIRMWARE,
}
# ── the system firmware ───────────────────────────────────────────────────────
def test_reads_the_system_firmware():
# pve-dual, a Supermicro X10DRL-i
out = _out(UUID, "", "ZM155S026022", ("American Megatrends Inc.", "3.4", "11/22/2021"))
identity = parse_system_identity(out)
assert identity["bios_vendor"] == "American Megatrends Inc."
assert identity["bios_version"] == "3.4"
assert identity["bios_date"] == "2021-11-22"
def test_a_virtual_machines_firmware_is_read_like_any_other():
out = _out(UUID, "", "", ("EDK II", "4.2023.08-4", "02/15/2024"))
assert parse_system_identity(out)["bios_version"] == "4.2023.08-4"
@pytest.mark.parametrize("version", ["1", "0", "1.0", "A"])
def test_a_short_firmware_version_is_no_placeholder(version):
# Serials of one repeated character are placeholders, versions are not.
out = _out(UUID, "", "", ("Vendor", version, ""))
assert parse_system_identity(out)["bios_version"] == version
@pytest.mark.parametrize("value", ["", "To be filled by O.E.M.", "Default string", "Not Specified"])
def test_a_placeholder_firmware_version_reads_as_empty(value):
out = _out(UUID, "", "", (value, value, ""))
identity = parse_system_identity(out)
assert identity["bios_vendor"] == ""
assert identity["bios_version"] == ""
@pytest.mark.parametrize("date", ["", "not a date", "13/45/2021", "2021-11-22"])
def test_a_firmware_date_that_is_no_smbios_date_reads_as_empty(date):
# sysfs writes the SMBIOS date as MM/DD/YYYY; anything else is no reading of it.
out = _out(UUID, "", "", ("Vendor", "1.2", date))
assert parse_system_identity(out)["bios_date"] == ""
def test_output_of_the_identity_alone_has_no_firmware():
# What a host answered before the firmware was read with it: three fields.
old = f"IDBEGIN\n{UUID}\nS1\nB1\nIDEND\n"
identity = parse_system_identity(old)
assert identity["board_serial"] == "B1"
assert {k: identity[k] for k in _NO_FIRMWARE} == _NO_FIRMWARE
def test_output_without_its_frame_is_not_a_reading():
with pytest.raises(ValueError):
parse_system_identity("sudo: a password is required\n")
@@ -115,6 +175,13 @@ def test_the_driver_only_carries_the_command_across():
assert privileged is True
def test_the_command_reads_the_three_dmi_files():
for name in ("product_uuid", "product_serial", "board_serial"):
def test_the_command_reads_the_dmi_files():
for name in (
"product_uuid",
"product_serial",
"board_serial",
"bios_vendor",
"bios_version",
"bios_date",
):
assert f"/sys/class/dmi/id/{name}" in SYSTEM_IDENTITY_COMMAND