Skip to content

Commit d99ddcf

Browse files
moving provision state synchronization logic to sensor-ironic-oslo-event.yaml from sensor-ironic-node-update.yaml
1 parent b992e90 commit d99ddcf

File tree

6 files changed

+595
-20
lines changed

6 files changed

+595
-20
lines changed

components/site-workflows/sensors/sensor-ironic-node-update.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ metadata:
1111
- baremetal.node.create.end which happens when a baremetal node is created
1212
- baremetal.node.update.end which happens when node fields are updated
1313
- baremetal.node.delete.end which happens when a node is deleted
14-
- baremetal.node.provision_set.end which happens after a state change on the node
1514
1615
Resulting code should be very similar to:
1716
@@ -41,7 +40,6 @@ spec:
4140
- "baremetal.node.create.end"
4241
- "baremetal.node.update.end"
4342
- "baremetal.node.delete.end"
44-
- "baremetal.node.provision_set.end"
4543
template:
4644
serviceAccountName: sensor-submit-workflow
4745
triggers:

components/site-workflows/sensors/sensor-ironic-oslo-event.yaml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ metadata:
1010
1111
- baremetal.node.provision_set.end which happens after a state change on the node
1212
13+
This sensor handles ALL provision state changes. The event handlers internally
14+
filter for specific states:
15+
- deploying: Sets up storage (volume connectors) for instances with storage enabled
16+
- inspecting: Updates Nautobot device with inspection data (inventory, ports)
17+
1318
Resulting code should be very similar to:
1419
1520
```
1621
argo -n argo-events submit --from workflowtemplate/openstack-oslo-event \
17-
-p event-json "JSON-payload" -p device_id=<UUID> -p project_id=<UUID>
22+
-p event-json "JSON-payload"
1823
```
1924
2025
Defined in `components/site-workflows/sensors/sensor-ironic-oslo-event.yaml`
@@ -39,11 +44,6 @@ spec:
3944
type: "string"
4045
value:
4146
- "baremetal.node.provision_set.end"
42-
- path: "body.ironic_object.previous_provision_state"
43-
type: "string"
44-
value:
45-
- "deploying"
46-
- "inspecting"
4747
template:
4848
serviceAccountName: sensor-submit-workflow
4949
triggers:
@@ -57,18 +57,14 @@ spec:
5757
src:
5858
dataKey: body
5959
dependencyName: ironic-dep
60-
- dest: spec.arguments.parameters.1.value # device_id
60+
- dest: spec.arguments.parameters.1.value # previous_provision_state
6161
src:
62-
dataKey: body.ironic_object.uuid
62+
dataKey: body.ironic_object.previous_provision_state
6363
dependencyName: ironic-dep
6464
- dest: spec.arguments.parameters.2.value # project_id
6565
src:
6666
dataKey: body.ironic_object.lessee
6767
dependencyName: ironic-dep
68-
- dest: spec.arguments.parameters.3.value # previous_provision_state
69-
src:
70-
dataKey: body.ironic_object.previous_provision_state
71-
dependencyName: ironic-dep
7268
source:
7369
# create a workflow in argo-events prefixed with ironic-prov-
7470
resource:
@@ -84,9 +80,8 @@ spec:
8480
arguments:
8581
parameters:
8682
- name: event-json
87-
- name: device_id
88-
- name: project_id
8983
- name: previous_provision_state
84+
- name: project_id
9085
templates:
9186
- name: main
9287
steps:

python/understack-workflows/tests/test_oslo_event_ironic_node.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_from_event_dict_missing_uuid(self):
5959
"""Test event parsing with missing UUID field."""
6060
event_data = {"payload": {"ironic_object.data": {"name": "test-node"}}}
6161

62-
with pytest.raises(ValueError): # Pydantic will raise validation error
62+
with pytest.raises(KeyError): # KeyError when uuid is missing
6363
IronicNodeEvent.from_event_dict(event_data)
6464

6565
def test_direct_initialization(self):
@@ -182,6 +182,7 @@ def valid_event_data(self):
182182
"lessee": uuid.uuid4(),
183183
"event": "provision_end",
184184
"uuid": uuid.uuid4(),
185+
"previous_provision_state": "deploying",
185186
}
186187
},
187188
}
@@ -322,9 +323,26 @@ def test_handle_provision_end_storage_metadata_missing(
322323
mock_server.metadata = {"other_key": "value"}
323324
mock_conn.get_server_by_id.return_value = mock_server
324325

325-
# This should raise a KeyError when accessing metadata["storage"]
326-
with pytest.raises(KeyError):
327-
handle_provision_end(mock_conn, mock_nautobot, valid_event_data)
326+
# When storage key is missing, it should treat it as "not-set"
327+
result = handle_provision_end(mock_conn, mock_nautobot, valid_event_data)
328+
329+
assert result == 0
330+
ironic_data = valid_event_data["payload"]["ironic_object.data"]
331+
instance_uuid = ironic_data["instance_uuid"]
332+
node_uuid = ironic_data["uuid"]
333+
334+
mock_conn.get_server_by_id.assert_called_once_with(instance_uuid)
335+
336+
# Check save_output calls - storage should be "not-set" when key is missing
337+
expected_calls = [
338+
("storage", "not-set"),
339+
("node_uuid", str(node_uuid)),
340+
("instance_uuid", str(instance_uuid)),
341+
]
342+
actual_calls = [call.args for call in mock_save_output.call_args_list]
343+
assert actual_calls == expected_calls
344+
345+
mock_create_connector.assert_called_once()
328346

329347
@patch("understack_workflows.oslo_event.ironic_node.is_project_svm_enabled")
330348
def test_handle_provision_end_invalid_event_data(

0 commit comments

Comments
 (0)