Skip to content

Commit

Permalink
Merge "Add "trusted" attribute to the "port""
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Nov 8, 2024
2 parents d17d99f + 4714410 commit 79e01a5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
29 changes: 29 additions & 0 deletions openstackclient/network/v2/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _get_columns(item):
'status': 'status',
'tags': 'tags',
'trunk_details': 'trunk_details',
'trusted': 'trusted',
'updated_at': 'updated_at',
}
return (
Expand Down Expand Up @@ -222,6 +223,10 @@ def _get_attrs(client_manager, parsed_args):
and parsed_args.hardware_offload_type
):
attrs['hardware_offload_type'] = parsed_args.hardware_offload_type
if parsed_args.not_trusted:
attrs['trusted'] = False
if parsed_args.trusted:
attrs['trusted'] = True

return attrs

Expand Down Expand Up @@ -388,6 +393,25 @@ def _add_updatable_args(parser, create=False):
'(repeat option to set multiple hints)'
),
)
port_trusted = parser.add_mutually_exclusive_group()
port_trusted.add_argument(
'--trusted',
action='store_true',
help=_(
"Set port to be trusted. This will be populated into the "
"'binding:profile' dictionary and passed to the services "
"which expect it in this dictionary (for example, Nova)"
),
)
port_trusted.add_argument(
'--not-trusted',
action='store_true',
help=_(
"Set port to be not trusted. This will be populated into the "
"'binding:profile' dictionary and passed to the services "
"which expect it in this dictionary (for example, Nova)"
),
)


# TODO(abhiraut): Use the SDK resource mapped attribute names once the
Expand Down Expand Up @@ -1137,6 +1161,11 @@ def take_action(self, parsed_args):
raise exceptions.CommandError(msg)
attrs['hints'] = expanded_hints

if parsed_args.not_trusted:
attrs['trusted'] = False
if parsed_args.trusted:
attrs['trusted'] = True

attrs.update(
self._parse_extra_properties(parsed_args.extra_properties)
)
Expand Down
1 change: 1 addition & 0 deletions openstackclient/tests/unit/network/v2/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ def create_one_port(attrs=None):
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
'tags': [],
'trusted': None,
'propagate_uplink_status': False,
'location': 'MUNCHMUNCHMUNCH',
}
Expand Down
75 changes: 75 additions & 0 deletions openstackclient/tests/unit/network/v2/test_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _get_common_cols_data(fake_port):
'security_group_ids',
'status',
'tags',
'trusted',
'trunk_details',
'updated_at',
)
Expand Down Expand Up @@ -114,6 +115,7 @@ def _get_common_cols_data(fake_port):
format_columns.ListColumn(fake_port.security_group_ids),
fake_port.status,
format_columns.ListColumn(fake_port.tags),
fake_port.trusted,
fake_port.trunk_details,
fake_port.updated_at,
)
Expand Down Expand Up @@ -1111,6 +1113,50 @@ def test_create_with_hardware_offload_type_switchdev(self):
def test_create_with_hardware_offload_type_null(self):
self._test_create_with_hardware_offload_type()

def _test_create_with_trusted_field(self, trusted):
arglist = [
'--network',
self._port.network_id,
'test-port',
]
if trusted:
arglist += ['--trusted']
else:
arglist += ['--not-trusted']

verifylist = [
(
'network',
self._port.network_id,
),
('name', 'test-port'),
]
if trusted:
verifylist.append(('trusted', True))
else:
verifylist.append(('trusted', False))

parsed_args = self.check_parser(self.cmd, arglist, verifylist)

columns, data = self.cmd.take_action(parsed_args)

create_args = {
'admin_state_up': True,
'network_id': self._port.network_id,
'name': 'test-port',
}
create_args['trusted'] = trusted
self.network_client.create_port.assert_called_once_with(**create_args)

self.assertEqual(set(self.columns), set(columns))
self.assertCountEqual(self.data, data)

def test_create_with_trusted_true(self):
self._test_create_with_trusted_field(True)

def test_create_with_trusted_false(self):
self._test_create_with_trusted_field(False)


class TestDeletePort(TestPort):
# Ports to delete.
Expand Down Expand Up @@ -2520,6 +2566,35 @@ def test_set_hints_valid_json(self):
)
self.assertIsNone(result)

def _test_set_trusted_field(self, trusted):
arglist = [self._port.id]
if trusted:
arglist += ['--trusted']
else:
arglist += ['--not-trusted']

verifylist = [
('port', self._port.id),
]
if trusted:
verifylist.append(('trusted', True))
else:
verifylist.append(('trusted', False))

parsed_args = self.check_parser(self.cmd, arglist, verifylist)

result = self.cmd.take_action(parsed_args)
self.network_client.update_port.assert_called_once_with(
self._port, **{'trusted': trusted}
)
self.assertIsNone(result)

def test_set_trusted_true(self):
self._test_set_trusted_field(True)

def test_set_trusted_false(self):
self._test_set_trusted_field(False)


class TestShowPort(TestPort):
# The port to show.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
Add ``trusted`` attribute to the ``port create`` and ``port set`` commands.
It can be set to ``true`` with ``--trusted`` and to ``false`` with
``--not-trusted`` CLI arguments passed to the ``port create`` and ``port
set`` commands``

0 comments on commit 79e01a5

Please sign in to comment.