Add "fields" parameter to ListSecurityGroup query

This new query parameter will allow to send a query sending the
"fields" parameter. This "fields" parameter contains the needed
API fields, translated into OVO fields in Neutron server, that
require to be retrieved from the DB.

As commented in the related bug, the OSC "list" command only
prints five parameters, none of them the security group rules. In
systems with a reasonable amount of security groups, skipping the
unnecessary rule load can save a lot of time.

Depends-On: https://review.opendev.org/#/c/710820/
Change-Id: I16f48e292997d029d68f66365db949b9f4b5a0c8
Closes-Bug: #1865223
This commit is contained in:
Rodolfo Alonso Hernandez 2020-03-02 16:40:15 +00:00
parent 962efd949f
commit 711b9c9405
2 changed files with 15 additions and 6 deletions
openstackclient

@ -202,6 +202,7 @@ class DeleteSecurityGroup(common.NetworkAndComputeDelete):
# the OSC minimum requirements include SDK 1.0.
class ListSecurityGroup(common.NetworkAndComputeLister):
_description = _("List security groups")
FIELDS_TO_RETRIEVE = ['id', 'name', 'description', 'project_id', 'tags']
def update_parser_network(self, parser):
if not self.is_docs_build:
@ -251,7 +252,8 @@ class ListSecurityGroup(common.NetworkAndComputeLister):
filters['project_id'] = project_id
_tag.get_tag_filtering_args(parsed_args, filters)
data = client.security_groups(**filters)
data = client.security_groups(fields=self.FIELDS_TO_RETRIEVE,
**filters)
columns = (
"ID",

@ -285,7 +285,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
self.network.security_groups.assert_called_once_with()
self.network.security_groups.assert_called_once_with(
fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
self.assertEqual(self.columns, columns)
self.assertListItemEqual(self.data, list(data))
@ -300,7 +301,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
columns, data = self.cmd.take_action(parsed_args)
self.network.security_groups.assert_called_once_with()
self.network.security_groups.assert_called_once_with(
fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
self.assertEqual(self.columns, columns)
self.assertListItemEqual(self.data, list(data))
@ -316,7 +318,9 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'tenant_id': project.id, 'project_id': project.id}
filters = {
'tenant_id': project.id, 'project_id': project.id,
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
self.network.security_groups.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@ -336,7 +340,9 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'tenant_id': project.id, 'project_id': project.id}
filters = {
'tenant_id': project.id, 'project_id': project.id,
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
self.network.security_groups.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@ -362,7 +368,8 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
**{'tags': 'red,blue',
'any_tags': 'red,green',
'not_tags': 'orange,yellow',
'not_any_tags': 'black,white'}
'not_any_tags': 'black,white',
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))