From 888022f8c0a2911a03fc682fdbe4c68c35a27db7 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Thu, 16 Feb 2017 18:43:31 +0800 Subject: [PATCH] Fix "security group list" command to display project ID properly The "Project" column of the output of "security group list" command is blank since the new attribute name is "project_id" not "tenant_id" in network resource, so change it to display project IDs properly Change-Id: Ie2a071afac3b5a8aaa2c6f1c50d44ae06905d916 Closes-bug: #1659967 --- openstackclient/network/v2/security_group.py | 50 ++++++++++++------- .../tests/unit/network/v2/fakes.py | 4 +- .../unit/network/v2/test_security_group.py | 2 +- .../notes/bug-1659967-644a8ee3621c9e81.yaml | 6 +++ 4 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 releasenotes/notes/bug-1659967-644a8ee3621c9e81.yaml diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index c6d9ede7f8..182d481779 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -210,21 +210,6 @@ class ListSecurityGroup(common.NetworkAndComputeLister): ) return parser - def _get_return_data(self, data, include_project=True): - columns = ( - "ID", - "Name", - "Description", - ) - column_headers = columns - if include_project: - columns = columns + ('Tenant ID',) - column_headers = column_headers + ('Project',) - return (column_headers, - (utils.get_item_properties( - s, columns, - ) for s in data)) - def take_action_network(self, client, parsed_args): filters = {} if parsed_args.project: @@ -236,13 +221,42 @@ class ListSecurityGroup(common.NetworkAndComputeLister): ).id filters['tenant_id'] = project_id filters['project_id'] = project_id - return self._get_return_data(client.security_groups(**filters)) + data = client.security_groups(**filters) + + columns = ( + "ID", + "Name", + "Description", + "Project ID" + ) + column_headers = ( + "ID", + "Name", + "Description", + "Project" + ) + return (column_headers, + (utils.get_item_properties( + s, columns, + ) for s in data)) def take_action_compute(self, client, parsed_args): search = {'all_tenants': parsed_args.all_projects} data = client.security_groups.list(search_opts=search) - return self._get_return_data(data, - include_project=parsed_args.all_projects) + + columns = ( + "ID", + "Name", + "Description", + ) + column_headers = columns + if parsed_args.all_projects: + columns = columns + ('Tenant ID',) + column_headers = column_headers + ('Project',) + return (column_headers, + (utils.get_item_properties( + s, columns, + ) for s in data)) class SetSecurityGroup(common.NetworkAndComputeCommand): diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 7afe332885..e0ee05b412 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -1071,7 +1071,7 @@ class FakeSecurityGroup(object): 'id': 'security-group-id-' + uuid.uuid4().hex, 'name': 'security-group-name-' + uuid.uuid4().hex, 'description': 'security-group-description-' + uuid.uuid4().hex, - 'tenant_id': 'project-id-' + uuid.uuid4().hex, + 'project_id': 'project-id-' + uuid.uuid4().hex, 'security_group_rules': [], } @@ -1083,7 +1083,7 @@ class FakeSecurityGroup(object): loaded=True) # Set attributes with special mapping in OpenStack SDK. - security_group.project_id = security_group_attrs['tenant_id'] + security_group.project_id = security_group_attrs['project_id'] return security_group diff --git a/openstackclient/tests/unit/network/v2/test_security_group.py b/openstackclient/tests/unit/network/v2/test_security_group.py index 9a30267ebd..66d357f98a 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group.py +++ b/openstackclient/tests/unit/network/v2/test_security_group.py @@ -404,7 +404,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork): grp.id, grp.name, grp.description, - grp.tenant_id, + grp.project_id, )) def setUp(self): diff --git a/releasenotes/notes/bug-1659967-644a8ee3621c9e81.yaml b/releasenotes/notes/bug-1659967-644a8ee3621c9e81.yaml new file mode 100644 index 0000000000..a42f9460fc --- /dev/null +++ b/releasenotes/notes/bug-1659967-644a8ee3621c9e81.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + ``security group list`` command now can display project IDs in the ``Project`` column + of the command output. + [Bug `1659967 `_]