From 4dbfc4755217c4d8690cd2c55e04b87476efb0db Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Tue, 25 Mar 2025 12:08:52 +0000 Subject: [PATCH] Return the ``port`` column headers expected in the list command In [1], it was added the ability to print in the "port list" command any field not defined in the hardcoded column set for this command. But in [2], it was added a filter list in the API call in order to reduce the CLI execution time. The unintentional drawback of this optimization was that is no longer possible to print any field outside the "port list" column set. Because the optimization if preferred and it is always possible to use "port show" to see all the port fields, the code added in [1] is removed. [1]https://review.opendev.org/c/openstack/python-openstackclient/+/522901 [2]https://review.opendev.org/c/openstack/python-openstackclient/+/754117 Closes-Bug: #2098980 Related-Bug: #1707848 Related-Bug: #1897100 Change-Id: Ia944b8e108c454219d642cfa595ffafdf060a57f --- openstackclient/network/v2/port.py | 7 ++----- .../tests/functional/network/v2/test_port.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 3579194bf7..4ff2a65925 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -944,15 +944,12 @@ class ListPort(command.Lister): for item in columns ] - headers, attrs = utils.calculate_header_and_attrs( - column_headers, columns, parsed_args - ) return ( - headers, + column_headers, ( utils.get_item_properties( s, - attrs, + columns, formatters=_list_formatters, ) for s in data diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py index 4530395507..e1f251abfa 100644 --- a/openstackclient/tests/functional/network/v2/test_port.py +++ b/openstackclient/tests/functional/network/v2/test_port.py @@ -12,6 +12,8 @@ import uuid +from tempest.lib import exceptions as tempest_exc + from openstackclient.tests.functional.network.v2 import common @@ -162,8 +164,16 @@ class PortTests(common.NetworkTagTests): id_list = [p['ID'] for p in json_output] self.assertIn(id1, id_list) self.assertIn(id2, id_list) - # Check an unknown field exists - self.assertIn('device_id', json_output[0]) + # Check an unknown field does not exist + self.assertNotIn('device_id', json_output[0]) + + # Test list with only unknown fields + exc = self.assertRaises( + tempest_exc.CommandFailed, + self.openstack, + 'port list -c device_id', + ) + self.assertIn("No recognized column names in ['device_id']", str(exc)) def test_port_set(self): """Test create, set, show, delete"""