Skip to content

Commit 53debe7

Browse files
committed
compute: Fix filtering servers by tags
The nova API expects the 'tags' and 'not-tags' filters of the 'GET /servers' (list servers) API to be a CSV string [1]: tags (Optional) A list of tags to filter the server list by. Servers that match all tags in this list will be returned. Boolean expression in this case is 't1 AND t2'. Tags in query must be separated by comma. New in version 2.26 not-tags (Optional) A list of tags to filter the server list by. Servers that don’t match all tags in this list will be returned. Boolean expression in this case is 'NOT (t1 AND t2)'. Tags in query must be separated by comma. New in version 2.26 We were instead providing a Python list, which was simply being URL encoded. Correct this. [1] https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detail#list-servers Change-Id: Ie0251a0dccdf3385089e5bbaedf646a5e928cc48 Signed-off-by: Stephen Finucane <sfinucan@redhat.com> Closes-Bug: #1946816
1 parent e0c61f0 commit 53debe7

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ def take_action(self, parsed_args):
22572257
)
22582258
raise exceptions.CommandError(msg)
22592259

2260-
search_opts['tags'] = parsed_args.tags
2260+
search_opts['tags'] = ','.join(parsed_args.tags)
22612261

22622262
if parsed_args.not_tags:
22632263
if compute_client.api_version < api_versions.APIVersion('2.26'):
@@ -2267,7 +2267,7 @@ def take_action(self, parsed_args):
22672267
)
22682268
raise exceptions.CommandError(msg)
22692269

2270-
search_opts['not-tags'] = parsed_args.not_tags
2270+
search_opts['not-tags'] = ','.join(parsed_args.not_tags)
22712271

22722272
if parsed_args.locked:
22732273
if compute_client.api_version < api_versions.APIVersion('2.73'):

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,7 +4489,7 @@ def test_server_list_with_tag(self):
44894489
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
44904490
columns, data = self.cmd.take_action(parsed_args)
44914491

4492-
self.search_opts['tags'] = ['tag1', 'tag2']
4492+
self.search_opts['tags'] = 'tag1,tag2'
44934493

44944494
self.servers_mock.list.assert_called_with(**self.kwargs)
44954495

@@ -4532,7 +4532,7 @@ def test_server_list_with_not_tag(self):
45324532
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
45334533
columns, data = self.cmd.take_action(parsed_args)
45344534

4535-
self.search_opts['not-tags'] = ['tag1', 'tag2']
4535+
self.search_opts['not-tags'] = 'tag1,tag2'
45364536

45374537
self.servers_mock.list.assert_called_with(**self.kwargs)
45384538

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Filtering servers by tags (``server list --tag``,
5+
``server list --not-tag``) now works correctly.
6+
[Bug `1946816 <https://bugs.launchpad.net/bugs/1946816>`_]

0 commit comments

Comments
 (0)