Add forward slash for node path patch

Ironic cli allow to patch attributes w/o forward slash
at the beginning:
    ironic node-update <node_id> add 'driver_info/attr'='my_attr'
Inspector fails if driver info in rules provided in same manner,
this change add head forward slash to path if it's missing.

Closes-Bug: #1529809
Change-Id: I4423184e15d5779c59a903b50554db0550ba3d83
This commit is contained in:
Anton Arefiev 2016-02-04 18:08:22 +02:00
parent b925717b06
commit 17274a613f
3 changed files with 37 additions and 2 deletions

View File

@ -264,6 +264,12 @@ class NodeInfo(object):
:param patches: JSON patches to apply
:raises: ironicclient exceptions
"""
# NOTE(aarefiev): support path w/o ahead forward slash
# as Ironic cli does
for patch in patches:
if patch.get('path') and not patch['path'].startswith('/'):
patch['path'] = '/' + patch['path']
LOG.debug('Updating node with patches %s', patches, node_info=self)
self._node = self.ironic.node.update(self.uuid, patches)

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import json
import time
import unittest
@ -502,9 +503,33 @@ class TestUpdate(test_base.NodeTest):
def test_patch(self):
self.ironic.node.update.return_value = mock.sentinel.node
self.node_info.patch(['patch'])
self.node_info.patch([{'patch': 'patch'}])
self.ironic.node.update.assert_called_once_with(self.uuid, ['patch'])
self.ironic.node.update.assert_called_once_with(self.uuid,
[{'patch': 'patch'}])
self.assertIs(mock.sentinel.node, self.node_info.node())
def test_patch_path_wo_leading_slash(self):
self.ironic.node.update.return_value = mock.sentinel.node
patch = [{'op': 'add', 'path': 'driver_info/test', 'value': 42}]
expected_patch = copy.deepcopy(patch)
expected_patch[0]['path'] = '/' + 'driver_info/test'
self.node_info.patch(patch)
self.ironic.node.update.assert_called_once_with(self.uuid,
expected_patch)
self.assertIs(mock.sentinel.node, self.node_info.node())
def test_patch_path_with_leading_slash(self):
self.ironic.node.update.return_value = mock.sentinel.node
patch = [{'op': 'add', 'path': '/driver_info/test', 'value': 42}]
self.node_info.patch(patch)
self.ironic.node.update.assert_called_once_with(self.uuid, patch)
self.assertIs(mock.sentinel.node, self.node_info.node())
def test_update_properties(self):

View File

@ -0,0 +1,4 @@
---
fixes:
- Introspection rules (e.g. set-attribute action) now accept 'path'
field without leading forward slash as Ironic cli does.