Skip to content

Commit c29e057

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add "hardware_offload_type" attribute to "port""
2 parents f0f811c + 0725bb4 commit c29e057

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def _get_columns(item):
7474
'dns_name': 'dns_name',
7575
'extra_dhcp_opts': 'extra_dhcp_opts',
7676
'fixed_ips': 'fixed_ips',
77+
'hardware_offload_type': 'hardware_offload_type',
7778
'hints': 'hints',
7879
'id': 'id',
7980
'ip_allocation': 'ip_allocation',
@@ -212,6 +213,12 @@ def _get_attrs(client_manager, parsed_args):
212213
if 'device_profile' in parsed_args and parsed_args.device_profile:
213214
attrs['device_profile'] = parsed_args.device_profile
214215

216+
if (
217+
'hardware_offload_type' in parsed_args
218+
and parsed_args.hardware_offload_type
219+
):
220+
attrs['hardware_offload_type'] = parsed_args.hardware_offload_type
221+
215222
return attrs
216223

217224

@@ -560,6 +567,15 @@ def get_parser(self, prog_name):
560567
metavar='<device-profile>',
561568
help=_('Cyborg port device profile'),
562569
)
570+
parser.add_argument(
571+
'--hardware-offload-type',
572+
metavar='<hardware-offload-type>',
573+
dest='hardware_offload_type',
574+
help=_(
575+
'Hardware offload type this port will request when '
576+
'attached to the network backend'
577+
),
578+
)
563579
_tag.add_tag_option_to_parser_for_create(parser, _('port'))
564580
return parser
565581

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,7 @@ def create_one_port(attrs=None):
17611761
'subnet_id': 'subnet-id-' + uuid.uuid4().hex,
17621762
}
17631763
],
1764+
'hardware_offload_type': None,
17641765
'hints': {},
17651766
'id': 'port-id-' + uuid.uuid4().hex,
17661767
'mac_address': 'fa:16:3e:a9:4e:72',

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _get_common_cols_data(fake_port):
5656
'dns_name',
5757
'extra_dhcp_opts',
5858
'fixed_ips',
59+
'hardware_offload_type',
5960
'hints',
6061
'id',
6162
'ip_allocation',
@@ -96,6 +97,7 @@ def _get_common_cols_data(fake_port):
9697
fake_port.dns_name,
9798
format_columns.ListDictColumn(fake_port.extra_dhcp_opts),
9899
format_columns.ListDictColumn(fake_port.fixed_ips),
100+
fake_port.hardware_offload_type,
99101
fake_port.hints,
100102
fake_port.id,
101103
fake_port.ip_allocation,
@@ -1068,6 +1070,48 @@ def test_create_hints_valid_json(self):
10681070
self.assertCountEqual(self.columns, columns)
10691071
self.assertCountEqual(self.data, data)
10701072

1073+
def _test_create_with_hardware_offload_type(self, hwol_type=None):
1074+
arglist = [
1075+
'--network',
1076+
self._port.network_id,
1077+
'test-port',
1078+
]
1079+
if hwol_type:
1080+
arglist += ['--hardware-offload-type', hwol_type]
1081+
1082+
hardware_offload_type = None if not hwol_type else hwol_type
1083+
verifylist = [
1084+
(
1085+
'network',
1086+
self._port.network_id,
1087+
),
1088+
('name', 'test-port'),
1089+
]
1090+
if hwol_type:
1091+
verifylist.append(('hardware_offload_type', hwol_type))
1092+
1093+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1094+
1095+
columns, data = self.cmd.take_action(parsed_args)
1096+
1097+
create_args = {
1098+
'admin_state_up': True,
1099+
'network_id': self._port.network_id,
1100+
'name': 'test-port',
1101+
}
1102+
if hwol_type:
1103+
create_args['hardware_offload_type'] = hardware_offload_type
1104+
self.network_client.create_port.assert_called_once_with(**create_args)
1105+
1106+
self.assertEqual(set(self.columns), set(columns))
1107+
self.assertCountEqual(self.data, data)
1108+
1109+
def test_create_with_hardware_offload_type_switchdev(self):
1110+
self._test_create_with_hardware_offload_type(hwol_type='switchdev')
1111+
1112+
def test_create_with_hardware_offload_type_null(self):
1113+
self._test_create_with_hardware_offload_type()
1114+
10711115

10721116
class TestDeletePort(TestPort):
10731117
# Ports to delete.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add the port hardware offload attribute to the ``port create`` command.
5+
Once defined, the value cannot be modified.

0 commit comments

Comments
 (0)