Skip to content

Commit 2a0431e

Browse files
committed
Add the trunk subports information to the port list command
Added the subports information to the port list command, when the "--long" qualifier is specified. Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/926609 Closes-Bug: #2074187 Change-Id: I8ef66c3415279caf0ebea4ba6232ca3696188de9
1 parent a631014 commit 2a0431e

3 files changed

Lines changed: 69 additions & 5 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ def human_readable(self):
3838
return 'UP' if self._value else 'DOWN'
3939

4040

41+
class SubPortColumn(format_columns.ListDictColumn):
42+
def _retrieve_subports(self):
43+
if isinstance(self._value, dict):
44+
self._value = self._value['sub_ports']
45+
46+
def human_readable(self):
47+
self._retrieve_subports()
48+
return super().human_readable()
49+
50+
def machine_readable(self):
51+
self._retrieve_subports()
52+
return super().machine_readable()
53+
54+
4155
_formatters = {
4256
'admin_state_up': AdminStateColumn,
4357
'is_admin_state_up': AdminStateColumn,
@@ -51,6 +65,7 @@ def human_readable(self):
5165
'fixed_ips': format_columns.ListDictColumn,
5266
'security_group_ids': format_columns.ListColumn,
5367
'tags': format_columns.ListColumn,
68+
'trunk_details': SubPortColumn,
5469
}
5570

5671

@@ -868,8 +883,18 @@ def take_action(self, parsed_args):
868883

869884
filters = {}
870885
if parsed_args.long:
871-
columns += ('security_group_ids', 'device_owner', 'tags')
872-
column_headers += ('Security Groups', 'Device Owner', 'Tags')
886+
columns += (
887+
'security_group_ids',
888+
'device_owner',
889+
'tags',
890+
'trunk_details',
891+
)
892+
column_headers += (
893+
'Security Groups',
894+
'Device Owner',
895+
'Tags',
896+
'Trunk subports',
897+
)
873898
if parsed_args.device_owner is not None:
874899
filters['device_owner'] = parsed_args.device_owner
875900
if parsed_args.device_id is not None:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ def create_one_port(attrs=None):
16791679
'trusted': None,
16801680
'propagate_uplink_status': False,
16811681
'location': 'MUNCHMUNCHMUNCH',
1682+
'trunk_details': {},
16821683
}
16831684

16841685
# Overwrite default attributes.

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from unittest import mock
1414
from unittest.mock import call
15+
import uuid
1516

1617
from osc_lib.cli import format_columns
1718
from osc_lib import exceptions
@@ -24,7 +25,12 @@
2425

2526

2627
LIST_FIELDS_TO_RETRIEVE = ('id', 'name', 'mac_address', 'fixed_ips', 'status')
27-
LIST_FIELDS_TO_RETRIEVE_LONG = ('security_group_ids', 'device_owner', 'tags')
28+
LIST_FIELDS_TO_RETRIEVE_LONG = (
29+
'security_group_ids',
30+
'device_owner',
31+
'tags',
32+
'trunk_details',
33+
)
2834

2935

3036
class TestPort(network_fakes.TestNetworkV2):
@@ -116,7 +122,7 @@ def _get_common_cols_data(fake_port):
116122
fake_port.status,
117123
format_columns.ListColumn(fake_port.tags),
118124
fake_port.trusted,
119-
fake_port.trunk_details,
125+
port.SubPortColumn(fake_port.trunk_details),
120126
fake_port.updated_at,
121127
)
122128

@@ -1236,7 +1242,37 @@ def test_multi_ports_delete_with_exception(self):
12361242

12371243

12381244
class TestListPort(compute_fakes.FakeClientMixin, TestPort):
1239-
_ports = network_fakes.create_ports(count=3)
1245+
_project = identity_fakes.FakeProject.create_one_project()
1246+
_networks = network_fakes.create_networks(count=3)
1247+
_sport1 = network_fakes.create_one_port(
1248+
attrs={'project_id': _project.id, 'network_id': _networks[1]['id']}
1249+
)
1250+
_sport2 = network_fakes.create_one_port(
1251+
attrs={'project_id': _project.id, 'network_id': _networks[2]['id']}
1252+
)
1253+
_trunk_details = {
1254+
'trunk_id': str(uuid.uuid4()),
1255+
'sub_ports': [
1256+
{
1257+
'segmentation_id': 100,
1258+
'segmentation_type': 'vlan',
1259+
'port_id': _sport1.id,
1260+
},
1261+
{
1262+
'segmentation_id': 102,
1263+
'segmentation_type': 'vlan',
1264+
'port_id': _sport2.id,
1265+
},
1266+
],
1267+
}
1268+
_pport = network_fakes.create_one_port(
1269+
attrs={
1270+
'project_id': _project.id,
1271+
'network_id': _networks[0]['id'],
1272+
'trunk_details': _trunk_details,
1273+
}
1274+
)
1275+
_ports = (_pport, _sport1, _sport2)
12401276

12411277
columns = (
12421278
'ID',
@@ -1255,6 +1291,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort):
12551291
'Security Groups',
12561292
'Device Owner',
12571293
'Tags',
1294+
'Trunk subports',
12581295
)
12591296

12601297
data = []
@@ -1281,6 +1318,7 @@ class TestListPort(compute_fakes.FakeClientMixin, TestPort):
12811318
format_columns.ListColumn(prt.security_group_ids),
12821319
prt.device_owner,
12831320
format_columns.ListColumn(prt.tags),
1321+
port.SubPortColumn(prt.trunk_details),
12841322
)
12851323
)
12861324

0 commit comments

Comments
 (0)