Skip to content

Commit c150349

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix "security group list" command to display project ID properly"
2 parents 3d4750c + 888022f commit c150349

4 files changed

Lines changed: 41 additions & 21 deletions

File tree

openstackclient/network/v2/security_group.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,6 @@ def update_parser_compute(self, parser):
210210
)
211211
return parser
212212

213-
def _get_return_data(self, data, include_project=True):
214-
columns = (
215-
"ID",
216-
"Name",
217-
"Description",
218-
)
219-
column_headers = columns
220-
if include_project:
221-
columns = columns + ('Tenant ID',)
222-
column_headers = column_headers + ('Project',)
223-
return (column_headers,
224-
(utils.get_item_properties(
225-
s, columns,
226-
) for s in data))
227-
228213
def take_action_network(self, client, parsed_args):
229214
filters = {}
230215
if parsed_args.project:
@@ -236,13 +221,42 @@ def take_action_network(self, client, parsed_args):
236221
).id
237222
filters['tenant_id'] = project_id
238223
filters['project_id'] = project_id
239-
return self._get_return_data(client.security_groups(**filters))
224+
data = client.security_groups(**filters)
225+
226+
columns = (
227+
"ID",
228+
"Name",
229+
"Description",
230+
"Project ID"
231+
)
232+
column_headers = (
233+
"ID",
234+
"Name",
235+
"Description",
236+
"Project"
237+
)
238+
return (column_headers,
239+
(utils.get_item_properties(
240+
s, columns,
241+
) for s in data))
240242

241243
def take_action_compute(self, client, parsed_args):
242244
search = {'all_tenants': parsed_args.all_projects}
243245
data = client.security_groups.list(search_opts=search)
244-
return self._get_return_data(data,
245-
include_project=parsed_args.all_projects)
246+
247+
columns = (
248+
"ID",
249+
"Name",
250+
"Description",
251+
)
252+
column_headers = columns
253+
if parsed_args.all_projects:
254+
columns = columns + ('Tenant ID',)
255+
column_headers = column_headers + ('Project',)
256+
return (column_headers,
257+
(utils.get_item_properties(
258+
s, columns,
259+
) for s in data))
246260

247261

248262
class SetSecurityGroup(common.NetworkAndComputeCommand):

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ def create_one_security_group(attrs=None):
10711071
'id': 'security-group-id-' + uuid.uuid4().hex,
10721072
'name': 'security-group-name-' + uuid.uuid4().hex,
10731073
'description': 'security-group-description-' + uuid.uuid4().hex,
1074-
'tenant_id': 'project-id-' + uuid.uuid4().hex,
1074+
'project_id': 'project-id-' + uuid.uuid4().hex,
10751075
'security_group_rules': [],
10761076
}
10771077

@@ -1083,7 +1083,7 @@ def create_one_security_group(attrs=None):
10831083
loaded=True)
10841084

10851085
# Set attributes with special mapping in OpenStack SDK.
1086-
security_group.project_id = security_group_attrs['tenant_id']
1086+
security_group.project_id = security_group_attrs['project_id']
10871087

10881088
return security_group
10891089

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
404404
grp.id,
405405
grp.name,
406406
grp.description,
407-
grp.tenant_id,
407+
grp.project_id,
408408
))
409409

410410
def setUp(self):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
``security group list`` command now can display project IDs in the ``Project`` column
5+
of the command output.
6+
[Bug `1659967 <https://bugs.launchpad.net/bugs/1659967>`_]

0 commit comments

Comments
 (0)