Skip to content

Commit 4714410

Browse files
committed
Add "trusted" attribute to the "port"
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/927723 Related-bug: #2060916 Change-Id: I8e3d4ee2208ef6bb6c96ee430d7b550a0720431e
1 parent 9c5fd76 commit 4714410

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def _get_columns(item):
9393
'status': 'status',
9494
'tags': 'tags',
9595
'trunk_details': 'trunk_details',
96+
'trusted': 'trusted',
9697
'updated_at': 'updated_at',
9798
}
9899
return (
@@ -222,6 +223,10 @@ def _get_attrs(client_manager, parsed_args):
222223
and parsed_args.hardware_offload_type
223224
):
224225
attrs['hardware_offload_type'] = parsed_args.hardware_offload_type
226+
if parsed_args.not_trusted:
227+
attrs['trusted'] = False
228+
if parsed_args.trusted:
229+
attrs['trusted'] = True
225230

226231
return attrs
227232

@@ -388,6 +393,25 @@ def _add_updatable_args(parser, create=False):
388393
'(repeat option to set multiple hints)'
389394
),
390395
)
396+
port_trusted = parser.add_mutually_exclusive_group()
397+
port_trusted.add_argument(
398+
'--trusted',
399+
action='store_true',
400+
help=_(
401+
"Set port to be trusted. This will be populated into the "
402+
"'binding:profile' dictionary and passed to the services "
403+
"which expect it in this dictionary (for example, Nova)"
404+
),
405+
)
406+
port_trusted.add_argument(
407+
'--not-trusted',
408+
action='store_true',
409+
help=_(
410+
"Set port to be not trusted. This will be populated into the "
411+
"'binding:profile' dictionary and passed to the services "
412+
"which expect it in this dictionary (for example, Nova)"
413+
),
414+
)
391415

392416

393417
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -1122,6 +1146,11 @@ def take_action(self, parsed_args):
11221146
raise exceptions.CommandError(msg)
11231147
attrs['hints'] = expanded_hints
11241148

1149+
if parsed_args.not_trusted:
1150+
attrs['trusted'] = False
1151+
if parsed_args.trusted:
1152+
attrs['trusted'] = True
1153+
11251154
attrs.update(
11261155
self._parse_extra_properties(parsed_args.extra_properties)
11271156
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ def create_one_port(attrs=None):
16761676
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
16771677
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
16781678
'tags': [],
1679+
'trusted': None,
16791680
'propagate_uplink_status': False,
16801681
'location': 'MUNCHMUNCHMUNCH',
16811682
}

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _get_common_cols_data(fake_port):
7373
'security_group_ids',
7474
'status',
7575
'tags',
76+
'trusted',
7677
'trunk_details',
7778
'updated_at',
7879
)
@@ -114,6 +115,7 @@ def _get_common_cols_data(fake_port):
114115
format_columns.ListColumn(fake_port.security_group_ids),
115116
fake_port.status,
116117
format_columns.ListColumn(fake_port.tags),
118+
fake_port.trusted,
117119
fake_port.trunk_details,
118120
fake_port.updated_at,
119121
)
@@ -1111,6 +1113,50 @@ def test_create_with_hardware_offload_type_switchdev(self):
11111113
def test_create_with_hardware_offload_type_null(self):
11121114
self._test_create_with_hardware_offload_type()
11131115

1116+
def _test_create_with_trusted_field(self, trusted):
1117+
arglist = [
1118+
'--network',
1119+
self._port.network_id,
1120+
'test-port',
1121+
]
1122+
if trusted:
1123+
arglist += ['--trusted']
1124+
else:
1125+
arglist += ['--not-trusted']
1126+
1127+
verifylist = [
1128+
(
1129+
'network',
1130+
self._port.network_id,
1131+
),
1132+
('name', 'test-port'),
1133+
]
1134+
if trusted:
1135+
verifylist.append(('trusted', True))
1136+
else:
1137+
verifylist.append(('trusted', False))
1138+
1139+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1140+
1141+
columns, data = self.cmd.take_action(parsed_args)
1142+
1143+
create_args = {
1144+
'admin_state_up': True,
1145+
'network_id': self._port.network_id,
1146+
'name': 'test-port',
1147+
}
1148+
create_args['trusted'] = trusted
1149+
self.network_client.create_port.assert_called_once_with(**create_args)
1150+
1151+
self.assertEqual(set(self.columns), set(columns))
1152+
self.assertCountEqual(self.data, data)
1153+
1154+
def test_create_with_trusted_true(self):
1155+
self._test_create_with_trusted_field(True)
1156+
1157+
def test_create_with_trusted_false(self):
1158+
self._test_create_with_trusted_field(False)
1159+
11141160

11151161
class TestDeletePort(TestPort):
11161162
# Ports to delete.
@@ -2497,6 +2543,35 @@ def test_set_hints_valid_json(self):
24972543
)
24982544
self.assertIsNone(result)
24992545

2546+
def _test_set_trusted_field(self, trusted):
2547+
arglist = [self._port.id]
2548+
if trusted:
2549+
arglist += ['--trusted']
2550+
else:
2551+
arglist += ['--not-trusted']
2552+
2553+
verifylist = [
2554+
('port', self._port.id),
2555+
]
2556+
if trusted:
2557+
verifylist.append(('trusted', True))
2558+
else:
2559+
verifylist.append(('trusted', False))
2560+
2561+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2562+
2563+
result = self.cmd.take_action(parsed_args)
2564+
self.network_client.update_port.assert_called_once_with(
2565+
self._port, **{'trusted': trusted}
2566+
)
2567+
self.assertIsNone(result)
2568+
2569+
def test_set_trusted_true(self):
2570+
self._test_set_trusted_field(True)
2571+
2572+
def test_set_trusted_false(self):
2573+
self._test_set_trusted_field(False)
2574+
25002575

25012576
class TestShowPort(TestPort):
25022577
# The port to show.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``trusted`` attribute to the ``port create`` and ``port set`` commands.
5+
It can be set to ``true`` with ``--trusted`` and to ``false`` with
6+
``--not-trusted`` CLI arguments passed to the ``port create`` and ``port
7+
set`` commands``

0 commit comments

Comments
 (0)