[RFE] Introspection rule actions value formatting for complex values

Bug #1670768 reported by Mark Goddard
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Ironic Inspector
Confirmed
Wishlist
Will Miller

Bug Description

Introspection rule actions cannot use formatting for non-string values. Sometimes we need to set a complex non-string value on a node via inspection rules. We may also want this non-string value to contain a reference to the introspection data.

Steps to reproduce

Here we use the example of setting a root device hint for the serial of the disk determined by inspection to be the root device. The properties.root_device attribute should be a dict mapping hint names (e.g. "serial") to hint values (e.g. a disk serial number).

$ cat > rule << EOF
{
    "actions": [
        {
            "action": "set-attribute",
            "path": "properties/root_device",
            "value": {
                "serial": "{data[root_device][serial]}"
            }
        }
    ],
    "conditions": [
        {
            "field": "node://properties.root_device",
            "op": "is-empty"
        }
    ]
}
$ openstack baremetal introspection rule import rule
+--------------------------------------+-------------+
| UUID | Description |
+--------------------------------------+-------------+
| 8e20fa94-cf46-4fcb-93f4-2dfeda4752dd | None |
+--------------------------------------+-------------+
$ openstack baremetal introspection rule show 8e20fa94-cf46-4fcb-93f4-2dfeda4752dd
+-------------+----------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+-------------+----------------------------------------------------------------------------------------------------------------------------+
| actions | [{u'action': u'set-attribute', u'path': u'properties/root_device', u'value': {u'serial': u'{data[root_device][serial]}'}}] |
| conditions | [{u'field': u'node://properties.root_device', u'op': u'is-empty'}] |
| description | None |
| uuid | 8e20fa94-cf46-4fcb-93f4-2dfeda4752dd |
+-------------+----------------------------------------------------------------------------------------------------------------------------+

Now start introspection on a node, for example:

$ ironic node-set-provision-state <node> inspect

Expected result:

The ironic node gets updated with properties/root_device={"serial": "<serial number>"}

Actual result:

The ironic node gets updated with properties/root_device={"serial": "{data[root_device][serial]}"}

Proposed solution:

For any action parameters marked as FORMATTED_PARAMS, inspector currently formats them if they are of type string. Inspector should also recursively check all non-string objects (dicts, lists) and format all strings contained nested within them.

Tags: rfe
Revision history for this message
Mark Goddard (mgoddard) wrote :

Workaround:

For those needing this capability in released versions of inspector, a workaround that works in the case described above is to use two actions as follows:

{
    "actions": [
        {
            "action": "set-attribute",
            "path": "properties/root_device",
            "value": {}
        },
        {
            "action": "set-attribute",
            "path": "properties/root_device/serial",
            "value": "{data[root_device][serial]}"
        }
    ],
    "conditions": [
        {
            "field": "node://properties.root_device",
            "op": "is-empty"
        }
    ]
}

Here we first initialise the properties/root_device value to an empty dict, which allows us to specify the serial item within this dict.

Dmitry Tantsur (divius)
summary: - Introspection rule actions cannot use formatting for non-string values
+ [RFE] Introspection rule actions value formatting for complex values
Changed in ironic-inspector:
status: New → Confirmed
importance: Undecided → Wishlist
tags: added: rfe
Will Miller (w-miller)
Changed in ironic-inspector:
assignee: nobody → Will Miller (w-miller)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.