Skip to content

Commit a0d7f98

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add "fields" parameter to ListSecurityGroup query"
2 parents 9e8960b + 711b9c9 commit a0d7f98

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

openstackclient/network/v2/security_group.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def take_action_compute(self, client, parsed_args):
202202
# the OSC minimum requirements include SDK 1.0.
203203
class ListSecurityGroup(common.NetworkAndComputeLister):
204204
_description = _("List security groups")
205+
FIELDS_TO_RETRIEVE = ['id', 'name', 'description', 'project_id', 'tags']
205206

206207
def update_parser_network(self, parser):
207208
if not self.is_docs_build:
@@ -251,7 +252,8 @@ def take_action_network(self, client, parsed_args):
251252
filters['project_id'] = project_id
252253

253254
_tag.get_tag_filtering_args(parsed_args, filters)
254-
data = client.security_groups(**filters)
255+
data = client.security_groups(fields=self.FIELDS_TO_RETRIEVE,
256+
**filters)
255257

256258
columns = (
257259
"ID",

openstackclient/tests/unit/network/v2/test_security_group_network.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ def test_security_group_list_no_options(self):
285285

286286
columns, data = self.cmd.take_action(parsed_args)
287287

288-
self.network.security_groups.assert_called_once_with()
288+
self.network.security_groups.assert_called_once_with(
289+
fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
289290
self.assertEqual(self.columns, columns)
290291
self.assertListItemEqual(self.data, list(data))
291292

@@ -300,7 +301,8 @@ def test_security_group_list_all_projects(self):
300301

301302
columns, data = self.cmd.take_action(parsed_args)
302303

303-
self.network.security_groups.assert_called_once_with()
304+
self.network.security_groups.assert_called_once_with(
305+
fields=security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE)
304306
self.assertEqual(self.columns, columns)
305307
self.assertListItemEqual(self.data, list(data))
306308

@@ -316,7 +318,9 @@ def test_security_group_list_project(self):
316318
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
317319

318320
columns, data = self.cmd.take_action(parsed_args)
319-
filters = {'tenant_id': project.id, 'project_id': project.id}
321+
filters = {
322+
'tenant_id': project.id, 'project_id': project.id,
323+
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
320324

321325
self.network.security_groups.assert_called_once_with(**filters)
322326
self.assertEqual(self.columns, columns)
@@ -336,7 +340,9 @@ def test_security_group_list_project_domain(self):
336340
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
337341

338342
columns, data = self.cmd.take_action(parsed_args)
339-
filters = {'tenant_id': project.id, 'project_id': project.id}
343+
filters = {
344+
'tenant_id': project.id, 'project_id': project.id,
345+
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
340346

341347
self.network.security_groups.assert_called_once_with(**filters)
342348
self.assertEqual(self.columns, columns)
@@ -362,7 +368,8 @@ def test_list_with_tag_options(self):
362368
**{'tags': 'red,blue',
363369
'any_tags': 'red,green',
364370
'not_tags': 'orange,yellow',
365-
'not_any_tags': 'black,white'}
371+
'not_any_tags': 'black,white',
372+
'fields': security_group.ListSecurityGroup.FIELDS_TO_RETRIEVE}
366373
)
367374
self.assertEqual(self.columns, columns)
368375
self.assertEqual(self.data, list(data))

0 commit comments

Comments
 (0)