Merge "Extend slash notation support to plugin-data paths"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2026-10-01 12:49:59 +00:00
commit 70f61fe42a
3 files changed
+32 -3

No files matched your search

+6 -3
View File
@@ -59,7 +59,8 @@ def get_action(op_name):
def update_nested_dict(d, key_path, value):
keys = key_path.split('.') if isinstance(key_path, str) else key_path
keys = (utils.normalize_path(key_path)
if isinstance(key_path, str) else key_path)
current = d
for key in keys[:-1]:
current = current.setdefault(key, {})
@@ -289,7 +290,8 @@ class ExtendPluginDataAction(ActionBase):
@staticmethod
def _get_nested_value(d, key_path, default=None):
keys = key_path.split('.') if isinstance(key_path, str) else key_path
keys = (utils.normalize_path(key_path)
if isinstance(key_path, str) else key_path)
current = d
try:
for key in keys:
@@ -314,7 +316,8 @@ class UnsetPluginDataAction(ActionBase):
@staticmethod
def _unset_nested_dict(d, key_path):
keys = key_path.split('.') if isinstance(key_path, str) else key_path
keys = (utils.normalize_path(key_path)
if isinstance(key_path, str) else key_path)
current = d
for key in keys[:-1]:
if not isinstance(current, dict) or key not in current:
@@ -17,6 +17,7 @@ from oslo_utils import uuidutils
from ironic.common import exception
from ironic.common import inspection_rules
from ironic.common.inspection_rules import actions
from ironic.common.inspection_rules import base
from ironic.common.inspection_rules import engine
from ironic.common.inspection_rules import utils
@@ -344,6 +345,24 @@ class TestOperators(TestInspectionRules):
def setUp(self):
super(TestOperators, self).setUp()
def test_plugin_data_paths_accept_slash_notation(self):
"""Plugin-data paths support slash notation, as attributes do."""
# Slash and dot notation must produce the same nesting.
for path in ('foo/bar', 'foo.bar', '/foo/bar'):
data = {}
actions.update_nested_dict(data, path, 'v')
self.assertEqual({'foo': {'bar': 'v'}}, data,
'path %r did not nest' % path)
# Reading back and unsetting agree with it.
data = {'foo': {'bar': 'v', 'keep': 1}}
self.assertEqual(
'v',
actions.ExtendPluginDataAction._get_nested_value(data, 'foo/bar'))
self.assertTrue(
actions.UnsetPluginDataAction._unset_nested_dict(data, 'foo/bar'))
self.assertEqual({'foo': {'keep': 1}}, data)
def test_operator_exceptions(self):
"""Test that operators raise proper exceptions for invalid inputs."""
with task_manager.acquire(self.context, self.node.uuid) as task:
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixes the inspection rule plugin data actions (``set-plugin-data``,
``extend-plugin-data`` and ``unset-plugin-data``) ignoring slash
notation in ``path``, so that they now accept the same dot or slash
notation as the node attribute actions.