From 5eb2be81d64670f7ada654f5535a585dbc8c6e9a Mon Sep 17 00:00:00 2001 From: Nidhi Rai Date: Thu, 19 Nov 2026 01:51:12 +0530 Subject: [PATCH 1/2] fix(ironic): put HA cabling faults in maintenance, not last_error --- .../drivers/panos_inspect.py | 24 ++++++++--- .../tests/test_panos_inspect.py | 42 +++++++++++++++++-- .../tests/test_enroll_fw.py | 17 ++++++++ .../understack_workflows/main/enroll_fw.py | 2 + 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/python/ironic-understack/ironic_understack/drivers/panos_inspect.py b/python/ironic-understack/ironic_understack/drivers/panos_inspect.py index 7bddfb21f..fed3831af 100644 --- a/python/ironic-understack/ironic_understack/drivers/panos_inspect.py +++ b/python/ironic-understack/ironic_understack/drivers/panos_inspect.py @@ -775,6 +775,19 @@ def _warn_if_hsci_slower(node_uuid: str, ports, ha_iface_status: dict) -> None: ) +def _hold_for_cabling_fault(node, reason: str) -> None: + """Put the node in maintenance for a cabling fault that DC ops must fix. + + A reason already there (another hold, or this fault from an earlier run) + is kept. + """ + LOG.error("[node:%s] %s; putting it in maintenance", node.uuid, reason) + current = (node.maintenance and node.maintenance_reason) or "" + if reason not in current: + node.maintenance_reason = f"{current}; {reason}" if current else reason + node.maintenance = True + + def _validate_and_pair_ha( task, client: panos_api.PanosClient, @@ -793,7 +806,8 @@ def _validate_and_pair_ha( 5. Pre-flight compatibility checks (resource_class, roles) Sets extra.ha_operational = True only when ALL checks pass; - otherwise the reason goes in last_error. + otherwise the reason goes in last_error. A cabling fault (wrong peer, + same switch) puts the node in maintenance with maintenance_reason instead. Does NOT modify mate node's extra fields or transition states. The enroll-fw workflow will read ha_operational from both devices and decide whether to promote. @@ -840,8 +854,7 @@ def _validate_and_pair_ha( f"HA peer serial mismatch: got {peer_serial}, " f"expected {mate_serial}" ) - LOG.warning("[node:%s] %s", node.uuid, reason) - node.last_error = reason + _hold_for_cabling_fault(node, reason) return LOG.info("[node:%s] HA peer connected: %s", node.uuid, peer_serial) @@ -955,9 +968,8 @@ def _validate_and_pair_ha( f"({', '.join(sorted(switch_overlap))}). " "HA pair must be on different switches." ) - LOG.error("[node:%s] %s", node.uuid, error_msg) - node.last_error = error_msg - raise exception.HardwareInspectionFailure(error_msg) + _hold_for_cabling_fault(node, error_msg) + return LOG.info( "[node:%s] Switch diversity validated: %d switches on this device, " diff --git a/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py b/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py index b8ca95c8d..e73ffed5f 100644 --- a/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py +++ b/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py @@ -170,6 +170,8 @@ def _ha_pair( task.node.traits = ["CUSTOM_PRIMARY"] task.node.extra = {"serial": "S1", "mate_serial": "S2"} task.node.resource_class = "pa1410" + task.node.last_error = None # Ironic clears it when inspection starts + task.node.maintenance = False task.ports = [Mock(local_link_connection={"switch_info": "leaf-1"})] mate = Mock( id=2, @@ -221,12 +223,10 @@ def test_a_healthy_pair_is_operational(mocker, task): ("change", "reason"), [ ({"peer": ("S2", "down")}, "HA peer connection not up"), - ({"peer": ("S9", "up")}, "HA peer serial mismatch"), ({"mate_peer": ("S9", "up")}, "Mate peer serial mismatch"), ({"mate_peer": ("S1", "down")}, "Mate peer connection not up"), - ({"mate_switch": "leaf-1"}, "same switch"), ], - ids=["peer-down", "wrong-peer", "mate-sees-other", "mate-down", "same-switch"], + ids=["peer-down", "mate-sees-other", "mate-down"], ) def test_an_unhealthy_pair_is_not_operational(mocker, task, change, reason): device = _ha_pair(mocker, task, **change) @@ -235,6 +235,42 @@ def test_an_unhealthy_pair_is_not_operational(mocker, task, change, reason): assert node.extra["ha_operational"] is False assert reason in node.last_error + assert node.maintenance is False + + +@pytest.mark.parametrize( + ("change", "reason"), + [ + ({"peer": ("S9", "up")}, "HA peer serial mismatch"), + ({"mate_switch": "leaf-1"}, "same switch"), + ], + ids=["wrong-peer", "same-switch"], +) +def test_a_cabling_fault_puts_the_node_in_maintenance(mocker, task, change, reason): + device = _ha_pair(mocker, task, **change) + + node = _validate_ha(task, device) + + assert node.extra["ha_operational"] is False + assert node.maintenance is True + assert reason in node.maintenance_reason + assert node.last_error is None + + +@pytest.mark.parametrize( + ("held", "expected"), + [ + ("Replace failed PSU", "Replace failed PSU; wrong peer"), + ("Replace failed PSU; wrong peer", "Replace failed PSU; wrong peer"), + ], + ids=["another-hold", "same-fault-again"], +) +def test_a_cabling_fault_keeps_an_existing_hold(held, expected): + node = Mock(maintenance=True, maintenance_reason=held) + + panos_inspect._hold_for_cabling_fault(node, "wrong peer") + + assert node.maintenance_reason == expected def test_a_local_link_down_never_contacts_the_mate(mocker, task): diff --git a/python/understack-workflows/tests/test_enroll_fw.py b/python/understack-workflows/tests/test_enroll_fw.py index d09bfcdae..4a176c50c 100644 --- a/python/understack-workflows/tests/test_enroll_fw.py +++ b/python/understack-workflows/tests/test_enroll_fw.py @@ -38,6 +38,7 @@ def _node( driver_info=driver_info or {}, extra=extra or {}, last_error=None, + maintenance=False, ) @@ -751,6 +752,22 @@ def test_ha_unit_waits_for_its_mate_until_the_pair_is_confirmed(mocker): assert ironic.updates == [] +def test_ha_unit_in_maintenance_fails_with_the_reason(mocker): + # Inspection found a cabling fault; DC ops must fix it before a re-run. + ironic = _pair( + "primary", + this={ + "ha_operational": False, + "maintenance": True, + "maintenance_reason": "HA pair cabling error: same switch", + }, + ) + + with pytest.raises(RuntimeError, match="In maintenance: HA pair cabling error"): + _promote(mocker, ironic, "primary") + assert ironic.updates == [] + + @pytest.mark.parametrize( ("this_role", "secondary", "primary"), [("primary", "fw-mate", "fw-this"), ("secondary", "fw-this", "fw-mate")], diff --git a/python/understack-workflows/understack_workflows/main/enroll_fw.py b/python/understack-workflows/understack_workflows/main/enroll_fw.py index 20ce1deb7..363c9084d 100644 --- a/python/understack-workflows/understack_workflows/main/enroll_fw.py +++ b/python/understack-workflows/understack_workflows/main/enroll_fw.py @@ -244,6 +244,8 @@ def _inspect_and_provide( # Inspection wrote extra.ha_operational, so read the node again. node = client.get_node(node.uuid) if _extra(node).get("ha_operational") is not True: + if node.maintenance: + raise _left_manageable(node, f"In maintenance: {node.maintenance_reason}") logger.warning( "[node:%s] Left manageable: HA pair not confirmed yet. It is waiting " "for its mate, or the HA checks failed: %s", From 015dfb8d8053902078dce0a8732464a2c7269335 Mon Sep 17 00:00:00 2001 From: Nidhi Rai Date: Thu, 19 Nov 2026 16:18:19 +0530 Subject: [PATCH 2/2] fix(ironic): fail inspection on HA cabling faults --- .../drivers/panos_inspect.py | 31 +++++++------------ .../tests/test_panos_inspect.py | 31 ++++--------------- .../tests/test_enroll_fw.py | 17 ---------- .../understack_workflows/main/enroll_fw.py | 2 -- 4 files changed, 17 insertions(+), 64 deletions(-) diff --git a/python/ironic-understack/ironic_understack/drivers/panos_inspect.py b/python/ironic-understack/ironic_understack/drivers/panos_inspect.py index fed3831af..584285e97 100644 --- a/python/ironic-understack/ironic_understack/drivers/panos_inspect.py +++ b/python/ironic-understack/ironic_understack/drivers/panos_inspect.py @@ -775,19 +775,6 @@ def _warn_if_hsci_slower(node_uuid: str, ports, ha_iface_status: dict) -> None: ) -def _hold_for_cabling_fault(node, reason: str) -> None: - """Put the node in maintenance for a cabling fault that DC ops must fix. - - A reason already there (another hold, or this fault from an earlier run) - is kept. - """ - LOG.error("[node:%s] %s; putting it in maintenance", node.uuid, reason) - current = (node.maintenance and node.maintenance_reason) or "" - if reason not in current: - node.maintenance_reason = f"{current}; {reason}" if current else reason - node.maintenance = True - - def _validate_and_pair_ha( task, client: panos_api.PanosClient, @@ -806,13 +793,13 @@ def _validate_and_pair_ha( 5. Pre-flight compatibility checks (resource_class, roles) Sets extra.ha_operational = True only when ALL checks pass; - otherwise the reason goes in last_error. A cabling fault (wrong peer, - same switch) puts the node in maintenance with maintenance_reason instead. + otherwise the reason goes in last_error. Does NOT modify mate node's extra fields or transition states. The enroll-fw workflow will read ha_operational from both devices and decide whether to promote. - :raises: Logs warnings but does not raise - allows inspection to complete + :raises: HardwareInspectionFailure for a cabling fault (wrong peer, same + switch). Other failures are recorded and inspection completes. """ # Default to False - only set True if all checks pass extra["ha_operational"] = False @@ -854,8 +841,9 @@ def _validate_and_pair_ha( f"HA peer serial mismatch: got {peer_serial}, " f"expected {mate_serial}" ) - _hold_for_cabling_fault(node, reason) - return + LOG.warning("[node:%s] %s", node.uuid, reason) + node.last_error = reason + raise exception.HardwareInspectionFailure(reason) LOG.info("[node:%s] HA peer connected: %s", node.uuid, peer_serial) @@ -968,8 +956,9 @@ def _validate_and_pair_ha( f"({', '.join(sorted(switch_overlap))}). " "HA pair must be on different switches." ) - _hold_for_cabling_fault(node, error_msg) - return + LOG.error("[node:%s] %s", node.uuid, error_msg) + node.last_error = error_msg + raise exception.HardwareInspectionFailure(error_msg) LOG.info( "[node:%s] Switch diversity validated: %d switches on this device, " @@ -995,6 +984,8 @@ def _validate_and_pair_ha( # Clear any previous failure reason node.last_error = None + except exception.HardwareInspectionFailure: + raise # a cabling fault stops inspection except Exception as e: LOG.exception( "[node:%s] HA validation/pairing failed: %s", diff --git a/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py b/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py index e73ffed5f..65d36807c 100644 --- a/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py +++ b/python/ironic-understack/ironic_understack/tests/test_panos_inspect.py @@ -170,8 +170,6 @@ def _ha_pair( task.node.traits = ["CUSTOM_PRIMARY"] task.node.extra = {"serial": "S1", "mate_serial": "S2"} task.node.resource_class = "pa1410" - task.node.last_error = None # Ironic clears it when inspection starts - task.node.maintenance = False task.ports = [Mock(local_link_connection={"switch_info": "leaf-1"})] mate = Mock( id=2, @@ -235,7 +233,6 @@ def test_an_unhealthy_pair_is_not_operational(mocker, task, change, reason): assert node.extra["ha_operational"] is False assert reason in node.last_error - assert node.maintenance is False @pytest.mark.parametrize( @@ -246,31 +243,15 @@ def test_an_unhealthy_pair_is_not_operational(mocker, task, change, reason): ], ids=["wrong-peer", "same-switch"], ) -def test_a_cabling_fault_puts_the_node_in_maintenance(mocker, task, change, reason): +def test_a_cabling_fault_fails_inspection(mocker, task, change, reason): device = _ha_pair(mocker, task, **change) - node = _validate_ha(task, device) - - assert node.extra["ha_operational"] is False - assert node.maintenance is True - assert reason in node.maintenance_reason - assert node.last_error is None - - -@pytest.mark.parametrize( - ("held", "expected"), - [ - ("Replace failed PSU", "Replace failed PSU; wrong peer"), - ("Replace failed PSU; wrong peer", "Replace failed PSU; wrong peer"), - ], - ids=["another-hold", "same-fault-again"], -) -def test_a_cabling_fault_keeps_an_existing_hold(held, expected): - node = Mock(maintenance=True, maintenance_reason=held) - - panos_inspect._hold_for_cabling_fault(node, "wrong peer") + with pytest.raises(exception.HardwareInspectionFailure, match=reason): + _validate_ha(task, device) - assert node.maintenance_reason == expected + assert task.node.extra["ha_operational"] is False + assert reason in task.node.last_error + task.node.save.assert_called_once() def test_a_local_link_down_never_contacts_the_mate(mocker, task): diff --git a/python/understack-workflows/tests/test_enroll_fw.py b/python/understack-workflows/tests/test_enroll_fw.py index 4a176c50c..d09bfcdae 100644 --- a/python/understack-workflows/tests/test_enroll_fw.py +++ b/python/understack-workflows/tests/test_enroll_fw.py @@ -38,7 +38,6 @@ def _node( driver_info=driver_info or {}, extra=extra or {}, last_error=None, - maintenance=False, ) @@ -752,22 +751,6 @@ def test_ha_unit_waits_for_its_mate_until_the_pair_is_confirmed(mocker): assert ironic.updates == [] -def test_ha_unit_in_maintenance_fails_with_the_reason(mocker): - # Inspection found a cabling fault; DC ops must fix it before a re-run. - ironic = _pair( - "primary", - this={ - "ha_operational": False, - "maintenance": True, - "maintenance_reason": "HA pair cabling error: same switch", - }, - ) - - with pytest.raises(RuntimeError, match="In maintenance: HA pair cabling error"): - _promote(mocker, ironic, "primary") - assert ironic.updates == [] - - @pytest.mark.parametrize( ("this_role", "secondary", "primary"), [("primary", "fw-mate", "fw-this"), ("secondary", "fw-this", "fw-mate")], diff --git a/python/understack-workflows/understack_workflows/main/enroll_fw.py b/python/understack-workflows/understack_workflows/main/enroll_fw.py index 363c9084d..20ce1deb7 100644 --- a/python/understack-workflows/understack_workflows/main/enroll_fw.py +++ b/python/understack-workflows/understack_workflows/main/enroll_fw.py @@ -244,8 +244,6 @@ def _inspect_and_provide( # Inspection wrote extra.ha_operational, so read the node again. node = client.get_node(node.uuid) if _extra(node).get("ha_operational") is not True: - if node.maintenance: - raise _left_manageable(node, f"In maintenance: {node.maintenance_reason}") logger.warning( "[node:%s] Left manageable: HA pair not confirmed yet. It is waiting " "for its mate, or the HA checks failed: %s",