Skip to content

Commit 3f4142d

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 (cherry picked from commit 53debe7) (cherry picked from commit cbc64f9)
1 parent 53f1efa commit 3f4142d

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
@@ -2201,7 +2201,7 @@ def take_action(self, parsed_args):
22012201
)
22022202
raise exceptions.CommandError(msg)
22032203

2204-
search_opts['tags'] = parsed_args.tags
2204+
search_opts['tags'] = ','.join(parsed_args.tags)
22052205

22062206
if parsed_args.not_tags:
22072207
if compute_client.api_version < api_versions.APIVersion('2.26'):
@@ -2211,7 +2211,7 @@ def take_action(self, parsed_args):
22112211
)
22122212
raise exceptions.CommandError(msg)
22132213

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

22162216
if parsed_args.locked:
22172217
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
@@ -4269,7 +4269,7 @@ def test_server_list_with_tag(self):
42694269
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
42704270
columns, data = self.cmd.take_action(parsed_args)
42714271

4272-
self.search_opts['tags'] = ['tag1', 'tag2']
4272+
self.search_opts['tags'] = 'tag1,tag2'
42734273

42744274
self.servers_mock.list.assert_called_with(**self.kwargs)
42754275

@@ -4312,7 +4312,7 @@ def test_server_list_with_not_tag(self):
43124312
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
43134313
columns, data = self.cmd.take_action(parsed_args)
43144314

4315-
self.search_opts['not-tags'] = ['tag1', 'tag2']
4315+
self.search_opts['not-tags'] = 'tag1,tag2'
43164316

43174317
self.servers_mock.list.assert_called_with(**self.kwargs)
43184318

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)