Skip to content

Commit d90bbbf

Browse files
committed
Split switch and HSCI speed checks out of the PAN-OS HA validator
1 parent 40ec25b commit d90bbbf

2 files changed

Lines changed: 81 additions & 49 deletions

File tree

‎python/ironic-understack/ironic_understack/drivers/panos_inspect.py‎

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,57 @@ def _handle_ha_configuration(
724724
return None
725725

726726

727+
def _switches_for_ports(ports) -> set[str]:
728+
"""Return the switches named in the ports' LLDP data."""
729+
switches = set()
730+
for port_obj in ports:
731+
llc = port_obj.local_link_connection or {}
732+
if hasattr(llc, "get"):
733+
switch_info = llc.get("switch_info")
734+
if switch_info and switch_info != "None":
735+
switches.add(switch_info)
736+
return switches
737+
738+
739+
def _warn_if_hsci_slower(node_uuid: str, ports, ha_iface_status: dict) -> None:
740+
"""Warn when the HSCI link is slower than the fastest data port."""
741+
# Get data plane interface speeds from discovered ports
742+
discovered_speeds = []
743+
for port_obj in ports:
744+
port_info = port_obj.local_link_connection or {}
745+
if hasattr(port_info, "get"):
746+
speed = port_info.get("port_speed")
747+
if speed:
748+
with suppress(ValueError, TypeError):
749+
discovered_speeds.append(int(speed))
750+
751+
if discovered_speeds:
752+
max_data_speed = max(discovered_speeds)
753+
hsci_speed_str = ha_iface_status.get("hsci", {}).get("speed", "0")
754+
try:
755+
# Convert speed string like "10000" or "10G" to Mbps
756+
if "G" in hsci_speed_str:
757+
hsci_speed = int(hsci_speed_str.replace("G", "")) * 1000
758+
else:
759+
hsci_speed = int(hsci_speed_str)
760+
761+
if hsci_speed < max_data_speed:
762+
LOG.warning(
763+
"[node:%s] HSCI speed (%s Mbps) < data plane (%s Mbps) - "
764+
"may impact HA statefulness",
765+
node_uuid,
766+
hsci_speed,
767+
max_data_speed,
768+
)
769+
# Don't fail, just warn
770+
except (ValueError, TypeError) as e:
771+
LOG.debug(
772+
"[node:%s] Could not parse interface speeds: %s",
773+
node_uuid,
774+
e,
775+
)
776+
777+
727778
def _validate_and_pair_ha(
728779
task,
729780
client: panos_api.PanosClient,
@@ -882,63 +933,18 @@ def _validate_and_pair_ha(
882933
LOG.info("[node:%s] Bidirectional HA validation passed", node.uuid)
883934

884935
# Step 6: Validate interface speeds (hsci >= data plane)
885-
# Get data plane interface speeds from discovered ports
886-
discovered_speeds = []
887-
for port_obj in task.ports:
888-
port_info = port_obj.local_link_connection or {}
889-
if hasattr(port_info, "get"):
890-
speed = port_info.get("port_speed")
891-
if speed:
892-
with suppress(ValueError, TypeError):
893-
discovered_speeds.append(int(speed))
894-
895-
if discovered_speeds:
896-
max_data_speed = max(discovered_speeds)
897-
hsci_speed_str = ha_iface_status.get("hsci", {}).get("speed", "0")
898-
try:
899-
# Convert speed string like "10000" or "10G" to Mbps
900-
if "G" in hsci_speed_str:
901-
hsci_speed = int(hsci_speed_str.replace("G", "")) * 1000
902-
else:
903-
hsci_speed = int(hsci_speed_str)
904-
905-
if hsci_speed < max_data_speed:
906-
LOG.warning(
907-
"[node:%s] HSCI speed (%s Mbps) < data plane (%s Mbps) - "
908-
"may impact HA statefulness",
909-
node.uuid,
910-
hsci_speed,
911-
max_data_speed,
912-
)
913-
# Don't fail, just warn
914-
except (ValueError, TypeError) as e:
915-
LOG.debug(
916-
"[node:%s] Could not parse interface speeds: %s",
917-
node.uuid,
918-
e,
919-
)
936+
_warn_if_hsci_slower(node.uuid, task.ports, ha_iface_status)
920937

921938
# Step 7: Validate HA pair switch diversity
922939
# Both devices must connect to different switches (true HA requirement)
923940
LOG.info("[node:%s] Validating HA pair switch diversity", node.uuid)
924941

925942
# Collect this device's switches from LLDP data
926-
my_switches = set()
927-
for port_obj in task.ports:
928-
llc = port_obj.local_link_connection or {}
929-
if hasattr(llc, "get"):
930-
switch_info = llc.get("switch_info")
931-
if switch_info and switch_info != "None":
932-
my_switches.add(switch_info)
943+
my_switches = _switches_for_ports(task.ports)
933944

934945
# Collect mate device's switches from LLDP data
935-
mate_switches = set()
936-
for port_obj in port.Port.list_by_node_id(task.context, mate.id):
937-
llc = port_obj.local_link_connection or {}
938-
if hasattr(llc, "get"):
939-
switch_info = llc.get("switch_info")
940-
if switch_info and switch_info != "None":
941-
mate_switches.add(switch_info)
946+
mate_ports = port.Port.list_by_node_id(task.context, mate.id)
947+
mate_switches = _switches_for_ports(mate_ports)
942948

943949
# Check for switch overlap (both devices on same switch = not true HA)
944950
switch_overlap = my_switches & mate_switches

‎python/ironic-understack/ironic_understack/tests/test_panos_inspect.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,29 @@ def test_existing_port_keeps_its_physical_network(
125125
panos_inspect._update_ports_from_neighbors(task, neighbors, macs)
126126

127127
assert [p.physical_network for p in task.ports] == [expected, expected]
128+
129+
130+
def test_switches_for_ports_skips_ports_without_a_switch():
131+
ports = [
132+
Mock(local_link_connection={"switch_info": "leaf-1"}),
133+
Mock(local_link_connection={"switch_info": "leaf-1"}),
134+
Mock(local_link_connection={"switch_info": "None"}),
135+
Mock(local_link_connection={}),
136+
Mock(local_link_connection=None),
137+
]
138+
139+
assert panos_inspect._switches_for_ports(ports) == {"leaf-1"}
140+
141+
142+
@pytest.mark.parametrize(
143+
("hsci_speed", "warns"),
144+
[("10G", True), ("25000", False), ("unknown", False)],
145+
ids=["slower", "same", "unparsable"],
146+
)
147+
def test_warns_only_when_hsci_is_slower_than_data_ports(mocker, hsci_speed, warns):
148+
log = mocker.patch.object(panos_inspect, "LOG")
149+
ports = [Mock(local_link_connection={"port_speed": "25000"})]
150+
151+
panos_inspect._warn_if_hsci_slower("n1", ports, {"hsci": {"speed": hsci_speed}})
152+
153+
assert log.warning.called is warns

0 commit comments

Comments
 (0)