Files
napalm-redfish/tests/parsers/test_accounts.py
T
Christian Manivong cab1c84cba Add parsers for the Redfish resources in redfish-map.md
Pure functions for ServiceRoot, ComputerSystem (facts, power state, reset action and ActionInfo), Processors, Memory, Storage/Drives/SimpleStorage, Chassis Thermal and Power as well as ThermalSubsystem/PowerSubsystem/Sensors (with environment_sources to pick whichever exists), Manager, EthernetInterfaces, ManagerNetworkProtocol, accounts, firmware inventory and log services/entries.
2026-10-12 23:42:14 +00:00

53 lines
2.1 KiB
Python

from napalm_redfish.parsers import parse_account, to_napalm_users
def test_account(rackmount):
acc = parse_account(rackmount("/redfish/v1/AccountService/Accounts/1"))
assert acc == {
"id": "1",
"username": "Administrator",
"role_id": "Administrator",
"enabled": True,
"locked": False,
"account_types": ["Redfish"],
}
def test_account_snmp_user(rackmount):
acc = parse_account(rackmount("/redfish/v1/AccountService/Accounts/2"))
assert acc["username"] == "contoso_employee457"
assert acc["account_types"] == ["Redfish", "SNMP"]
def test_empty_account_slot_is_none():
# iDRAC and Supermicro list every slot, unused ones with an empty UserName.
assert parse_account({"Id": "3", "UserName": "", "Enabled": False, "RoleId": "None"}) is None
assert parse_account({"Id": "4"}) is None
def test_account_defaults():
acc = parse_account({"Id": "2", "UserName": "ADMIN"})
assert acc["enabled"] is None
assert acc["locked"] is None
assert acc["role_id"] is None
assert acc["account_types"] == []
def test_to_napalm_users(rackmount):
accounts = [parse_account(rackmount(f"/redfish/v1/AccountService/Accounts/{i}"))
for i in (1, 2)]
accounts.append({"id": "3", "username": "netork", "role_id": "ReadOnly", "enabled": True,
"locked": False, "account_types": []})
accounts.append({"id": "4", "username": "ops", "role_id": "Operator", "enabled": False,
"locked": False, "account_types": []})
accounts.append({"id": "5", "username": "custom", "role_id": "OemSpecial", "enabled": True,
"locked": False, "account_types": []})
accounts.append(None)
assert to_napalm_users(accounts) == {
"Administrator": {"level": 15, "password": "", "sshkeys": []},
"contoso_employee457": {"level": 15, "password": "", "sshkeys": []},
"netork": {"level": 1, "password": "", "sshkeys": []},
"ops": {"level": 5, "password": "", "sshkeys": []},
"custom": {"level": 0, "password": "", "sshkeys": []},
}