Skip to content

Commit ba7f718

Browse files
authored
Merge pull request #2779 from rackerlabs/panos_hsci_check
fix(panos): hsci interface validation
2 parents 97439ed + 90a30b6 commit ba7f718

4 files changed

Lines changed: 97 additions & 25 deletions

File tree

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ def _validate_and_pair_ha(
786786
"""Validate HA pairing and set ha_operational flag for this device.
787787
788788
Performs comprehensive validation:
789-
1. HA interface states (ha1-a, ha1-b, hsci)
789+
1. HA1 interface states and HA2/HSCI link status
790790
2. Peer connection status
791791
3. Bidirectional serial validation (checks mate device too)
792792
4. Interface speed validation (hsci vs data plane)
@@ -805,26 +805,37 @@ def _validate_and_pair_ha(
805805
extra["ha_operational"] = False
806806

807807
try:
808-
# Step 1: Check HA interface states
808+
# HSCI can report an unknown state through the generic interface API
809+
# even when PAN-OS reports the HA2 link as up.
809810
ha_iface_status = client.get_ha_interface_status()
810811
ha1_a_state = ha_iface_status.get("ha1-a", {}).get("state")
811812
ha1_b_state = ha_iface_status.get("ha1-b", {}).get("state")
812-
hsci_state = ha_iface_status.get("hsci", {}).get("state")
813813

814-
if ha1_a_state != "up" or ha1_b_state != "up" or hsci_state != "up":
814+
if ha1_a_state != "up" or ha1_b_state != "up":
815+
link_states = f"ha1-a={ha1_a_state}, ha1-b={ha1_b_state}"
816+
reason = f"HA1 interfaces not all up: {link_states}"
817+
_record_ha_reason(node, reason, LOG.info)
818+
return
819+
820+
# Step 2: Validate HA configuration, HA2/HSCI, and peer connection.
821+
ha_status = client.get_ha_status()
822+
if str(ha_status.get("enabled", "")).strip().lower() != "yes":
815823
reason = (
816-
f"HA interfaces not all up: ha1-a={ha1_a_state}, "
817-
f"ha1-b={ha1_b_state}, hsci={hsci_state}"
824+
"HA is not enabled on this device: "
825+
f"{ha_status.get('enabled', 'unknown')}"
818826
)
819827
_record_ha_reason(node, reason, LOG.info)
820828
return
821829

822-
LOG.info("[node:%s] HA interfaces operational", node.uuid)
830+
peer_status = ha_status.get("peer") or {}
831+
ha2_status = peer_status.get("conn_ha2_status", "unknown")
832+
if str(ha2_status).strip().lower() != "up":
833+
reason = f"HA2/HSCI link not up: conn-ha2={ha2_status}"
834+
_record_ha_reason(node, reason, LOG.info)
835+
return
823836

824-
# Step 2: Query HA status and check peer connection
825-
ha_status = client.get_ha_status()
826-
peer_serial = ha_status.get("peer", {}).get("serial")
827-
peer_conn = ha_status.get("peer", {}).get("conn_status")
837+
peer_serial = peer_status.get("serial")
838+
peer_conn = peer_status.get("conn_status")
828839

829840
if peer_conn != "up":
830841
reason = (
@@ -906,8 +917,15 @@ def _validate_and_pair_ha(
906917
mate_client = panos_api.PanosClient(mate_address)
907918
mate_client.login()
908919
mate_ha_status = mate_client.get_ha_status()
909-
mate_peer_serial = mate_ha_status.get("peer", {}).get("serial")
910-
mate_peer_conn = mate_ha_status.get("peer", {}).get("conn_status")
920+
if str(mate_ha_status.get("enabled", "")).strip().lower() != "yes":
921+
mate_ha_enabled = mate_ha_status.get("enabled", "unknown")
922+
reason = f"HA is not enabled on mate: {mate_ha_enabled}"
923+
_record_ha_reason(node, reason)
924+
return
925+
926+
mate_peer_status = mate_ha_status.get("peer") or {}
927+
mate_peer_serial = mate_peer_status.get("serial")
928+
mate_peer_conn = mate_peer_status.get("conn_status")
911929

912930
if mate_peer_serial != my_serial:
913931
reason = (
@@ -922,6 +940,12 @@ def _validate_and_pair_ha(
922940
_record_ha_reason(node, reason)
923941
return
924942

943+
mate_ha2_status = mate_peer_status.get("conn_ha2_status", "unknown")
944+
if str(mate_ha2_status).strip().lower() != "up":
945+
reason = f"Mate HA2/HSCI link not up: conn-ha2={mate_ha2_status}"
946+
_record_ha_reason(node, reason)
947+
return
948+
925949
LOG.info("[node:%s] Bidirectional HA validation passed", node.uuid)
926950

927951
# Step 6: Validate interface speeds (hsci >= data plane)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<serial>000000000001</serial>
1818
<sw-version>11.0.0</sw-version>
1919
</system></result></response>"""
20+
HA_STATUS = b"""<response status="success"><result><enabled>yes</enabled><group>
21+
<local-info><state>active</state></local-info>
22+
<peer-info><conn-ha2><conn-status>up</conn-status></conn-ha2>
23+
<conn-status>up</conn-status><serial-num>000000000002</serial-num></peer-info>
24+
</group></result></response>"""
2025

2126

2227
def _resp(status_code, content):
@@ -156,3 +161,15 @@ def test_op_error_status_is_raised(conf):
156161

157162
with pytest.raises(panos_api.PanosApiError, match="bad command"):
158163
client.op("<show><nope/></show>")
164+
165+
166+
def test_ha_status_reads_ha2_link_status_from_peer_info(conf):
167+
session = Mock()
168+
session.post.return_value = _resp(200, HA_STATUS)
169+
client = panos_api.PanosClient("192.0.2.10", session=session)
170+
client.api_key = "KEY"
171+
172+
status = client.get_ha_status()
173+
174+
assert status["enabled"] == "yes"
175+
assert status["peer"]["conn_ha2_status"] == "up"

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,30 @@ def test_warns_only_when_hsci_is_slower_than_data_ports(mocker, hsci_speed, warn
170170
assert log.warning.called is warns
171171

172172

173-
def _ha_status(serial, conn):
174-
return {"peer": {"serial": serial, "conn_status": conn}}
173+
def _ha_status(serial, conn, ha2="up", enabled="yes"):
174+
return {
175+
"enabled": enabled,
176+
"peer": {
177+
"serial": serial,
178+
"conn_status": conn,
179+
"conn_ha2_status": ha2,
180+
},
181+
}
175182

176183

177184
def _ha_pair(
178185
mocker,
179186
task,
180187
*,
181188
hsci="up",
189+
ha1_a="up",
190+
ha1_b="up",
182191
peer=("S2", "up"),
183192
mate_peer=("S1", "up"),
193+
ha2="up",
194+
mate_ha2="up",
195+
enabled="yes",
196+
mate_enabled="yes",
184197
mate_switch="leaf-2",
185198
):
186199
"""A primary, its secondary in Ironic and both devices; returns this device."""
@@ -204,13 +217,15 @@ def _ha_pair(
204217
)
205218
device = Mock()
206219
device.get_ha_interface_status.return_value = {
207-
"ha1-a": {"state": "up"},
208-
"ha1-b": {"state": "up"},
220+
"ha1-a": {"state": ha1_a},
221+
"ha1-b": {"state": ha1_b},
209222
"hsci": {"state": hsci},
210223
}
211-
device.get_ha_status.return_value = _ha_status(*peer)
224+
device.get_ha_status.return_value = _ha_status(*peer, ha2=ha2, enabled=enabled)
212225
mate_device = mocker.patch.object(panos_api, "PanosClient").return_value
213-
mate_device.get_ha_status.return_value = _ha_status(*mate_peer)
226+
mate_device.get_ha_status.return_value = _ha_status(
227+
*mate_peer, ha2=mate_ha2, enabled=mate_enabled
228+
)
214229
mocker.patch.object(panos_inspect.conductor_utils.node_history, "NodeHistory")
215230
return device
216231

@@ -232,7 +247,7 @@ def _validate_ha(task, device):
232247

233248

234249
def test_a_healthy_pair_is_operational(mocker, task):
235-
device = _ha_pair(mocker, task)
250+
device = _ha_pair(mocker, task, hsci="ukn")
236251
task.node.last_error = "stale"
237252

238253
node = _validate_ha(task, device)
@@ -247,8 +262,20 @@ def test_a_healthy_pair_is_operational(mocker, task):
247262
({"peer": ("S2", "down")}, "HA peer connection not up"),
248263
({"mate_peer": ("S9", "up")}, "Mate peer serial mismatch"),
249264
({"mate_peer": ("S1", "down")}, "Mate peer connection not up"),
265+
({"ha2": "down"}, "HA2/HSCI link not up"),
266+
({"mate_ha2": "down"}, "Mate HA2/HSCI link not up"),
267+
({"enabled": "no"}, "HA is not enabled on this device"),
268+
({"mate_enabled": "no"}, "HA is not enabled on mate"),
269+
],
270+
ids=[
271+
"peer-down",
272+
"mate-sees-other",
273+
"mate-down",
274+
"ha2-down",
275+
"mate-ha2-down",
276+
"local-ha-disabled",
277+
"mate-ha-disabled",
250278
],
251-
ids=["peer-down", "mate-sees-other", "mate-down"],
252279
)
253280
def test_an_unhealthy_pair_is_not_operational(mocker, task, change, reason):
254281
device = _ha_pair(mocker, task, **change)
@@ -280,13 +307,13 @@ def test_a_cabling_fault_fails_inspection(mocker, task, change, reason):
280307
task.node.save.assert_called_once()
281308

282309

283-
def test_a_local_link_down_never_contacts_the_mate(mocker, task):
284-
device = _ha_pair(mocker, task, hsci="down")
310+
def test_a_local_ha1_link_down_never_contacts_the_mate(mocker, task):
311+
device = _ha_pair(mocker, task, ha1_a="down")
285312

286313
node = _validate_ha(task, device)
287314

288315
assert node.extra["ha_operational"] is False
289-
assert "HA interfaces not all up" in node.last_error
316+
assert "HA1 interfaces not all up" in node.last_error
290317
panos_api.PanosClient.assert_not_called()
291318

292319

‎python/ironic-understack/ironic_understack/utils/panos_api.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def get_ha_status(self) -> dict[str, any]:
362362
- enabled: "yes" or "no"
363363
- local: dict with state, version, mode, priority
364364
- peer: dict with state, conn_status, conn_ha1_up, conn_ha1_backup_up,
365-
version, serial, mgmt_ip
365+
conn_ha2_status, version, serial, mgmt_ip
366366
- group_id: HA group ID
367367
- error: error message if query fails
368368
"""
@@ -398,6 +398,10 @@ def get_ha_status(self) -> dict[str, any]:
398398
result.findtext(".//peer-info/conn-ha1-backup/conn-status")
399399
== "up"
400400
),
401+
"conn_ha2_status": (
402+
result.findtext(".//peer-info/conn-ha2/conn-status")
403+
or "unknown"
404+
),
401405
"version": result.findtext(".//peer-info/build-rel") or "unknown",
402406
"serial": result.findtext(".//peer-info/serial-num") or "unknown",
403407
"mgmt_ip": result.findtext(".//peer-info/mgmt-ip") or "unknown",

0 commit comments

Comments
 (0)