Skip to content

Commit b992e90

Browse files
using enriched data updated by inspect hooks from both agent and redfish interfaces
1 parent 6e87796 commit b992e90

File tree

13 files changed

+1296
-112
lines changed

13 files changed

+1296
-112
lines changed

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ metadata:
88
workflows.argoproj.io/description: |+
99
Triggers on the following Ironic Events:
1010
11+
- baremetal.node.create.end which happens when a baremetal node is created
12+
- baremetal.node.update.end which happens when node fields are updated
13+
- baremetal.node.delete.end which happens when a node is deleted
1114
- baremetal.node.provision_set.end which happens after a state change on the node
12-
- baremetal.node.update.end which happens when node fields are updated.
13-
14-
Currently parses out the following fields:
15-
16-
- provision_state
1715
1816
Resulting code should be very similar to:
1917
2018
```
21-
argo -n argo-events submit --from workflowtemplate/sync-provision-state-to-nautobot \
22-
-p device_uuid=00000000-0000-0000-0000-000000000000 -p provision_state=available
19+
argo -n argo-events submit --from workflowtemplate/openstack-oslo-event \
20+
-p event-json "JSON-payload"
2321
```
2422
2523
Defined in `workflows/argo-events/sensors/ironic-node-update.yaml`
@@ -30,15 +28,19 @@ spec:
3028
name: ironic-dep
3129
transform:
3230
# the event is a string-ified JSON so we need to decode it
33-
jq: ".body[\"oslo.message\"] | fromjson"
31+
# replace the whole event body
32+
jq: |
33+
.body = (.body["oslo.message"] | fromjson)
3434
filters:
3535
# applies each of the items in data with 'and' but there's only one
3636
dataLogicalOperator: "and"
3737
data:
38-
- path: "event_type"
38+
- path: "body.event_type"
3939
type: "string"
4040
value:
41+
- "baremetal.node.create.end"
4142
- "baremetal.node.update.end"
43+
- "baremetal.node.delete.end"
4244
- "baremetal.node.provision_set.end"
4345
template:
4446
serviceAccountName: sensor-submit-workflow
@@ -49,25 +51,10 @@ spec:
4951
k8s:
5052
operation: create
5153
parameters:
52-
# first parameter's value is replaced with the uuid
54+
# first parameter is the parsed oslo.message
5355
- dest: spec.arguments.parameters.0.value
5456
src:
55-
dataKey: payload.ironic_object\.data.uuid
56-
dependencyName: ironic-dep
57-
# second parameter's value is replaced with the provision_state
58-
- dest: spec.arguments.parameters.1.value
59-
src:
60-
dataKey: payload.ironic_object\.data.provision_state
61-
dependencyName: ironic-dep
62-
# third parameter's value is replaced with the lessee
63-
- dest: spec.arguments.parameters.2.value
64-
src:
65-
dataKey: payload.ironic_object\.data.lessee
66-
dependencyName: ironic-dep
67-
# fourth parameter's value is replaced with the resource_class
68-
- dest: spec.arguments.parameters.3.value
69-
src:
70-
dataKey: payload.ironic_object\.data.resource_class
57+
dataKey: body
7158
dependencyName: ironic-dep
7259
source:
7360
# create a workflow in argo-events prefixed with ironic-node-update-
@@ -81,10 +68,7 @@ spec:
8168
# defines the parameters being replaced above
8269
arguments:
8370
parameters:
84-
- name: device_uuid
85-
- name: provision_state
86-
- name: lessee
87-
- name: resource_class
71+
- name: event-json
8872
# references the workflow
8973
workflowTemplateRef:
90-
name: sync-provision-state-to-nautobot
74+
name: openstack-oslo-event

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ metadata:
1313
Resulting code should be very similar to:
1414
1515
```
16-
argo -n argo-events submit --from workflowtemplate/ironic-oslo-event \
16+
argo -n argo-events submit --from workflowtemplate/openstack-oslo-event \
1717
-p event-json "JSON-payload" -p device_id=<UUID> -p project_id=<UUID>
1818
```
1919
20-
Defined in `workflows/argo-events/sensors/sensor-ironic-oslo-event.yaml`
20+
Defined in `components/site-workflows/sensors/sensor-ironic-oslo-event.yaml`
2121
spec:
2222
dependencies:
2323
- eventName: openstack
@@ -43,6 +43,7 @@ spec:
4343
type: "string"
4444
value:
4545
- "deploying"
46+
- "inspecting"
4647
template:
4748
serviceAccountName: sensor-submit-workflow
4849
triggers:
@@ -64,6 +65,10 @@ spec:
6465
src:
6566
dataKey: body.ironic_object.lessee
6667
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
6772
source:
6873
# create a workflow in argo-events prefixed with ironic-prov-
6974
resource:
@@ -81,6 +86,7 @@ spec:
8186
- name: event-json
8287
- name: device_id
8388
- name: project_id
89+
- name: previous_provision_state
8490
templates:
8591
- name: main
8692
steps:
@@ -93,6 +99,7 @@ spec:
9399
- name: event-json
94100
value: "{{workflow.parameters.event-json}}"
95101
- name: convert-project-id
102+
when: "\"{{workflow.parameters.previous_provision_state}}\" == deploying"
96103
inline:
97104
script:
98105
image: python:alpine
@@ -102,7 +109,7 @@ spec:
102109
project_id_without_dashes = "{{workflow.parameters.project_id}}"
103110
print(str(uuid.UUID(project_id_without_dashes)))
104111
- - name: ansible-storage-update
105-
when: "\"{{steps.oslo-events.outputs.parameters.storage}}\" == wanted"
112+
when: "\"{{steps.oslo-events.outputs.parameters.storage}}\" == wanted && \"{{workflow.parameters.previous_provision_state}}\" == deploying"
106113
templateRef:
107114
name: ansible-workflow-template
108115
template: ansible-run

python/understack-workflows/tests/test_oslo_event_ironic_node.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,70 @@
55

66
import pytest
77

8+
from understack_workflows.oslo_event.ironic_node import IronicNodeEvent
89
from understack_workflows.oslo_event.ironic_node import IronicProvisionSetEvent
910
from understack_workflows.oslo_event.ironic_node import create_volume_connector
1011
from understack_workflows.oslo_event.ironic_node import handle_provision_end
1112
from understack_workflows.oslo_event.ironic_node import instance_nqn
1213

1314

15+
class TestIronicNodeEvent:
16+
"""Test cases for IronicNodeEvent class."""
17+
18+
def test_from_event_dict_success(self):
19+
"""Test successful node event parsing."""
20+
event_data = {
21+
"payload": {
22+
"ironic_object.data": {
23+
"uuid": "test-uuid-123",
24+
"name": "test-node",
25+
"provision_state": "available",
26+
}
27+
}
28+
}
29+
30+
event = IronicNodeEvent.from_event_dict(event_data)
31+
32+
assert event.uuid == "test-uuid-123"
33+
34+
def test_from_event_dict_minimal_data(self):
35+
"""Test parsing with only required UUID field."""
36+
event_data = {"payload": {"ironic_object.data": {"uuid": "minimal-uuid"}}}
37+
38+
event = IronicNodeEvent.from_event_dict(event_data)
39+
40+
assert event.uuid == "minimal-uuid"
41+
42+
def test_from_event_dict_no_payload(self):
43+
"""Test event parsing with missing payload."""
44+
event_data = {}
45+
46+
with pytest.raises(ValueError, match="Invalid event. No 'payload'"):
47+
IronicNodeEvent.from_event_dict(event_data)
48+
49+
def test_from_event_dict_no_ironic_object_data(self):
50+
"""Test event parsing with missing ironic_object.data."""
51+
event_data = {"payload": {"other_field": "value"}}
52+
53+
with pytest.raises(
54+
ValueError, match="Invalid event. No 'ironic_object.data' in payload"
55+
):
56+
IronicNodeEvent.from_event_dict(event_data)
57+
58+
def test_from_event_dict_missing_uuid(self):
59+
"""Test event parsing with missing UUID field."""
60+
event_data = {"payload": {"ironic_object.data": {"name": "test-node"}}}
61+
62+
with pytest.raises(ValueError): # Pydantic will raise validation error
63+
IronicNodeEvent.from_event_dict(event_data)
64+
65+
def test_direct_initialization(self):
66+
"""Test direct initialization of IronicNodeEvent."""
67+
event = IronicNodeEvent(uuid="direct-uuid")
68+
69+
assert event.uuid == "direct-uuid"
70+
71+
1472
class TestIronicProvisionSetEvent:
1573
"""Test cases for IronicProvisionSetEvent class."""
1674

0 commit comments

Comments
 (0)