Files
christianmanivong 0052ba7884 feat: Intel AMT driver over WS-Management (0.1.0)
An `amt` driver (napalm_amt.AmtDriver), a ManagementControllerDriver for the
management controller of Intel vPro machines, with its own lean WS-Management
client (requests + ElementTree, HTTP Digest, ports 16992/16993).

It reads the machine's identity, hardware with the SMBIOS system UUID, firmware
(AMT with build, BIOS), power state and the hardware event log, reports what AMT
listens on (plain HTTP or TLS, KVM incl. port 5900, IDE-R), and switches the
machine's power. AMT cannot be reset over WS-Management, so there is no
reboot_host. Discovery recognises AMT by its ports and its Server header.

Tested against Intel's published AMT 12 recordings (go-wsman-messages,
Apache-2.0, see NOTICE). `python -m napalm_amt.record` records a real AMT
read-only; the first test devices are two Lenovo ThinkCentre M910x.
2026-10-18 14:55:32 +02:00

74 lines
2.0 KiB
Python

"""The machine's power state and what AMT accepts, from the recorded NUC9."""
import pytest
from napalm_amt.parsers import POWER_REQUESTS, accepted_actions, parse_power_state
from ..conftest import instances
def test_power_state_of_a_running_machine():
(service,) = instances("CIM_AssociatedPowerManagementService.pull.xml")
assert parse_power_state(service) == {
"state": "On",
"available": [10, 8, 5, 11, 4, 7, 14, 12],
}
@pytest.mark.parametrize(
("code", "state"),
[
("2", "On"),
("8", "Off"),
("6", "Off"),
("13", "Off"),
# Asleep or hibernating: the OS is not running, On wakes it.
("3", "Off"),
("4", "Off"),
("7", "Off"),
("99", ""),
("", ""),
],
)
def test_power_state_codes(code, state):
assert parse_power_state({"PowerState": code})["state"] == state
def test_a_single_available_state_is_a_list():
assert parse_power_state({"PowerState": "8", "AvailableRequestedPowerStates": "2"})[
"available"
] == [2]
def test_running_machine_accepts_what_amt_offers_except_on():
assert accepted_actions("On", [10, 8, 5, 11, 4, 7, 14, 12]) == [
"GracefulShutdown",
"ForceOff",
"GracefulRestart",
"ForceRestart",
"PowerCycle",
]
def test_without_graceful_states_amt_offers_no_graceful_actions():
# AMT lists the graceful states only where the host can honour them.
assert accepted_actions("On", [10, 8, 5]) == ["ForceOff", "ForceRestart", "PowerCycle"]
def test_machine_that_is_off_accepts_on_only():
assert accepted_actions("Off", [2]) == ["On"]
assert accepted_actions("Off", []) == ["On"]
def test_unknown_state_accepts_nothing():
assert accepted_actions("", [2, 8, 10]) == []
def test_power_requests_cover_every_role_action():
from napalm_device_types.models import POWER_ACTIONS
assert set(POWER_REQUESTS) == set(POWER_ACTIONS)
assert POWER_REQUESTS["On"] == 2
assert POWER_REQUESTS["ForceOff"] == 8
assert POWER_REQUESTS["ForceRestart"] == 10