Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions python/understack-workflows/tests/test_enroll_fw.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,14 @@ def _pair(this_role, *, this=None, mate=None, traits=None, ports=None):


def _promote(mocker, ironic, ha_role):
transition = mocker.patch.object(enroll_fw.ironic_node, "transition")
def transition(node, target_state, **_):
# A healthy mate passes its own HA check when inspected again.
if (node.uuid, target_state) == ("fw-mate", "inspect"):
node.extra["ha_operational"] = True

transition = mocker.patch.object(
enroll_fw.ironic_node, "transition", side_effect=transition
)
enroll_fw._inspect_and_provide(ironic, "fw-this", PHYSNET, ha_role)
return [(c.args[0].uuid, c.kwargs["target_state"]) for c in transition.mock_calls]

Expand Down Expand Up @@ -774,12 +781,10 @@ def test_ha_pair_is_linked_then_both_are_provided(
steps = _promote(mocker, ironic, this_role)

# One update links the secondary with power coupling off, before provide.
assert ironic.updates == [
(secondary, _link_to(primary)),
("fw-mate", SET_HA_OPERATIONAL),
]
assert ironic.updates == [(secondary, _link_to(primary))]
assert steps == [
("fw-this", "inspect"),
("fw-mate", "inspect"),
("fw-mate", "provide"),
("fw-this", "provide"),
]
Expand Down
22 changes: 17 additions & 5 deletions python/understack-workflows/understack_workflows/main/enroll_fw.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def _inspect_and_provide(
(extra.ha_operational); then both units are linked and provided together.
"""
node = client.get_node(node_uuid)
logger.info("[node:%s] Inspecting to discover and check the ports", node.uuid)
ironic_node.transition(node, target_state="inspect", expected_state="manageable")
_inspect(node)
role_ports = _checked_role_ports(client, node)
_set_physical_network(client, node, role_ports.values(), physical_network)

Expand Down Expand Up @@ -295,11 +294,18 @@ def _promote_ha_pair(
"""Link a confirmed HA pair, and provide both units.

This node's inspection checked both boxes, so the mate's ha_operational
is set from here. Every check runs before the first write, so a failed
check leaves both units as they were. The mate is provided first. An
active mate (carrying a router) only gets its metadata updated.
is set from here. A manageable mate is inspected again first. Every
check runs before the first write, so a failed check leaves both units
as they were. The mate is provided first. An active mate (carrying a
router) only gets its metadata updated.
"""
mate = _find_mate(client, node)
if mate.provision_state == "manageable":
# Inspection rebuilds its HA, so its own check must pass.
_inspect(mate)
mate = client.get_node(mate.uuid)
if _extra(mate).get("ha_operational") is not True:
raise _left_manageable(node, f"The mate's HA check: {mate.last_error}")
if ha_role == "primary":
primary, secondary, mate_role = node, mate, "secondary"
else:
Expand Down Expand Up @@ -490,6 +496,12 @@ def _add(path: str, value) -> dict:
return {"op": "add", "path": path, "value": value}


def _inspect(node) -> None:
"""Inspect a manageable node."""
logger.info("[node:%s] Inspecting to discover and check the ports", node.uuid)
ironic_node.transition(node, target_state="inspect", expected_state="manageable")


def _provide(node) -> None:
"""Make a manageable node available."""
ironic_node.transition(node, target_state="provide", expected_state="available")
Expand Down
Loading