Fixes the description filter

--description-contains is added for listing node with description filtering,
but it's actually not working due to missing support from the node list interface.
This patch fixes it.

Change-Id: Ie5c12ba9c00be3d117313c5617da28063e00185f
Closes-Bug: #2071446
This commit is contained in:
Kaifeng Wang
2024-06-29 23:32:16 +08:00
parent c5aa22077b
commit b35b79b15f
3 changed files with 30 additions and 2 deletions

View File

@@ -55,7 +55,8 @@ NODE2 = {'uuid': '66666666-7777-8888-9999-111111111111',
'retired': True, 'retired': True,
'lessee': '77777777-8888-5555-2222-999999999999', 'lessee': '77777777-8888-5555-2222-999999999999',
'shard': 'myshard', 'shard': 'myshard',
'parent_node': NODE1['uuid']} 'parent_node': NODE1['uuid'],
'description': 'foo bar'}
PORT = {'uuid': '11111111-2222-3333-4444-555555555555', PORT = {'uuid': '11111111-2222-3333-4444-555555555555',
'node_uuid': '66666666-7777-8888-9999-000000000000', 'node_uuid': '66666666-7777-8888-9999-000000000000',
'address': 'AA:AA:AA:AA:AA:AA', 'address': 'AA:AA:AA:AA:AA:AA',
@@ -298,6 +299,13 @@ fake_responses = {
{"nodes": [NODE2]} {"nodes": [NODE2]}
) )
}, },
'/v1/nodes/?description_contains=foo':
{
'GET': (
{},
{"nodes": [NODE2]}
)
},
'/v1/nodes/%s/children' % NODE1['uuid']: '/v1/nodes/%s/children' % NODE1['uuid']:
{ {
'GET': ( 'GET': (
@@ -1068,6 +1076,16 @@ class NodeManagerTest(testtools.TestCase):
self.assertEqual(1, len(children)) self.assertEqual(1, len(children))
self.assertEqual(NODE2['uuid'], children[0]) self.assertEqual(NODE2['uuid'], children[0])
def test_node_list_by_description(self):
nodes = self.mgr.list(description_contains='foo')
expect = [
('GET', '/v1/nodes/?description_contains=foo', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(nodes, HasLength(1))
self.assertEqual(NODE2['description'],
getattr(nodes[0], 'description'))
def test_node_list_detail(self): def test_node_list_detail(self):
nodes = self.mgr.list(detail=True) nodes = self.mgr.list(detail=True)
expect = [ expect = [

View File

@@ -65,7 +65,8 @@ class NodeManager(base.CreateManager):
os_ironic_api_version=None, conductor_group=None, os_ironic_api_version=None, conductor_group=None,
conductor=None, owner=None, retired=None, lessee=None, conductor=None, owner=None, retired=None, lessee=None,
shards=None, sharded=None, parent_node=None, shards=None, sharded=None, parent_node=None,
include_children=None, global_request_id=None): include_children=None, description_contains=None,
global_request_id=None):
"""Retrieve a list of nodes. """Retrieve a list of nodes.
:param associated: Optional. Either a Boolean or a string :param associated: Optional. Either a Boolean or a string
@@ -144,6 +145,8 @@ class NodeManager(base.CreateManager):
Tells the ironic API to enumerate all child Tells the ironic API to enumerate all child
nodes which are normally hidden from the nodes which are normally hidden from the
node list. node list.
:param description_contains: Optional. String value to get nodes
with description contains specified value.
:returns: A list of nodes. :returns: A list of nodes.
""" """
@@ -189,6 +192,8 @@ class NodeManager(base.CreateManager):
if include_children: if include_children:
# NOTE(TheJulia): Only valid if True. # NOTE(TheJulia): Only valid if True.
filters.append('include_children=True') filters.append('include_children=True')
if description_contains is not None:
filters.append('description_contains=%s' % description_contains)
path = '' path = ''
if detail: if detail:

View File

@@ -0,0 +1,5 @@
---
fixes:
- |
Fixes the issue that ``--description-contains`` does not work when trying
to query nodes with description filter.