summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2017-11-24 22:01:06 +0000
committerAkihiro Motoki <amotoki@gmail.com>2017-11-24 22:45:06 +0000
commit0626f95579357918e51d46e4e29720854540bfd9 (patch)
tree6d44c93cf5f736068f944fb7cb4d97bfe2b703ee /openstackclient
parentc47b1ff06341cd56b1b94e8954a4c4b90a039cb4 (diff)
downloadpython-openstackclient-0626f95579357918e51d46e4e29720854540bfd9.tar.gz
Allow port list to shown undefined attributes
At now, OSC command implementation extracts resource attributes based on a predefined column list, so if a user specifies an unknown attribute not defined in the column lists, such attribute will be ignored. In case of 'port list', the neutron port defines many attributes and it is not a good idea to show all attributes even in the long mode from the perspective of user experience. This commit consumes osc_lib.utils.calculate_headers_and_attrs() function to show undefined port attributes if requested in -c option. Closes-Bug: #1707848 Depends-On: I6c6bc3c6e3c769c96869fd76b9d9c1661280850e Change-Id: I130a6aed41d80603698b6cab0c9a1d1dc59df743
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/port.py6
-rw-r--r--openstackclient/tests/functional/network/v2/test_port.py10
2 files changed, 14 insertions, 2 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 4b23b339..21f30c41 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -584,9 +584,11 @@ class ListPort(command.Lister):
data = network_client.ports(**filters)
- return (column_headers,
+ headers, attrs = utils.calculate_header_and_attrs(
+ column_headers, columns, parsed_args)
+ return (headers,
(utils.get_item_properties(
- s, columns,
+ s, attrs,
formatters=_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 a7059790..7357c0ed 100644
--- a/openstackclient/tests/functional/network/v2/test_port.py
+++ b/openstackclient/tests/functional/network/v2/test_port.py
@@ -131,6 +131,16 @@ class PortTests(common.NetworkTagTests):
self.assertNotIn(mac1, item_map.values())
self.assertIn(mac2, item_map.values())
+ # Test list with unknown fields
+ json_output = json.loads(self.openstack(
+ 'port list -f json -c ID -c Name -c device_id'
+ ))
+ 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])
+
def test_port_set(self):
"""Test create, set, show, delete"""
name = uuid.uuid4().hex