diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index af8c936df..49118b1d9 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -74,6 +74,7 @@ def _get_columns(item): 'dns_name': 'dns_name', 'extra_dhcp_opts': 'extra_dhcp_opts', 'fixed_ips': 'fixed_ips', + 'hardware_offload_type': 'hardware_offload_type', 'hints': 'hints', 'id': 'id', 'ip_allocation': 'ip_allocation', @@ -212,6 +213,12 @@ def _get_attrs(client_manager, parsed_args): if 'device_profile' in parsed_args and parsed_args.device_profile: attrs['device_profile'] = parsed_args.device_profile + if ( + 'hardware_offload_type' in parsed_args + and parsed_args.hardware_offload_type + ): + attrs['hardware_offload_type'] = parsed_args.hardware_offload_type + return attrs @@ -560,6 +567,15 @@ class CreatePort(command.ShowOne, common.NeutronCommandWithExtraArgs): metavar='', help=_('Cyborg port device profile'), ) + parser.add_argument( + '--hardware-offload-type', + metavar='', + dest='hardware_offload_type', + help=_( + 'Hardware offload type this port will request when ' + 'attached to the network backend' + ), + ) _tag.add_tag_option_to_parser_for_create(parser, _('port')) return parser diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index fcfa376f1..ac02d96ad 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -1761,6 +1761,7 @@ def create_one_port(attrs=None): 'subnet_id': 'subnet-id-' + uuid.uuid4().hex, } ], + 'hardware_offload_type': None, 'hints': {}, 'id': 'port-id-' + uuid.uuid4().hex, 'mac_address': 'fa:16:3e:a9:4e:72', diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index e93cc8c48..f09fe1e51 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -56,6 +56,7 @@ class TestPort(network_fakes.TestNetworkV2): 'dns_name', 'extra_dhcp_opts', 'fixed_ips', + 'hardware_offload_type', 'hints', 'id', 'ip_allocation', @@ -96,6 +97,7 @@ class TestPort(network_fakes.TestNetworkV2): fake_port.dns_name, format_columns.ListDictColumn(fake_port.extra_dhcp_opts), format_columns.ListDictColumn(fake_port.fixed_ips), + fake_port.hardware_offload_type, fake_port.hints, fake_port.id, fake_port.ip_allocation, @@ -1068,6 +1070,48 @@ class TestCreatePort(TestPort): self.assertCountEqual(self.columns, columns) self.assertCountEqual(self.data, data) + def _test_create_with_hardware_offload_type(self, hwol_type=None): + arglist = [ + '--network', + self._port.network_id, + 'test-port', + ] + if hwol_type: + arglist += ['--hardware-offload-type', hwol_type] + + hardware_offload_type = None if not hwol_type else hwol_type + verifylist = [ + ( + 'network', + self._port.network_id, + ), + ('name', 'test-port'), + ] + if hwol_type: + verifylist.append(('hardware_offload_type', hwol_type)) + + 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', + } + if hwol_type: + create_args['hardware_offload_type'] = hardware_offload_type + 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_hardware_offload_type_switchdev(self): + self._test_create_with_hardware_offload_type(hwol_type='switchdev') + + def test_create_with_hardware_offload_type_null(self): + self._test_create_with_hardware_offload_type() + class TestDeletePort(TestPort): # Ports to delete. diff --git a/releasenotes/notes/add-port-hardware-offload-type-011c98ab748357d7.yaml b/releasenotes/notes/add-port-hardware-offload-type-011c98ab748357d7.yaml new file mode 100644 index 000000000..87a72cdbd --- /dev/null +++ b/releasenotes/notes/add-port-hardware-offload-type-011c98ab748357d7.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add the port hardware offload attribute to the ``port create`` command. + Once defined, the value cannot be modified.