Merge "Add forward slash for node path patch"

This commit is contained in:
Jenkins 2016-02-10 16:08:28 +00:00 committed by Gerrit Code Review
commit e2eb6bed5e
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.