Honor the interface-mtu in the extra_dhcp_opts of a port

Also need to honor its corresponding code which is 26.

Basically user can set this option value like this,
neutron port-create net1 --extra-dhcp-opt opt_name=interface-mtu,opt_value=1400
neutron port-update --extra-dhcp-opt opt_name=26,opt_value=1100 <port_id>

Change-Id: I20e3b34daa1613e8cf2eaebf7b46b04650ea4dd1
This commit is contained in:
Kent Wu 2018-06-18 17:10:04 -07:00
parent 6f48e93268
commit 50001a4ac0
2 changed files with 29 additions and 1 deletions

View File

@ -2393,6 +2393,14 @@ class AIMMappingDriver(nrd.CommonNeutronBase, aim_rpc.AIMMappingRPCMixin):
def _get_port_mtu(self, context, port):
if self.advertise_mtu:
for dhcp_opt in port.get('extra_dhcp_opts'):
if (dhcp_opt.get('opt_name') == 'interface-mtu' or
dhcp_opt.get('opt_name') == '26'):
if dhcp_opt.get('opt_value'):
try:
return int(dhcp_opt['opt_value'])
except ValueError:
continue
network = self._get_network(context, port['network_id'])
return network.get('mtu')
return None

View File

@ -3125,7 +3125,11 @@ class TestPolicyTarget(AIMBaseTestCase,
port['security_groups'].append(sg['id'])
port = self._plugin.update_port(
self._context, port['id'], {'port': port})
# Set the bad MTU through extra_dhcp_opts, it should fall back
# to the network MTU
data = {'port': {'extra_dhcp_opts': [{'opt_name': '26',
'opt_value': 'garbage'}]}}
port = self._update('ports', port['id'], data)['port']
mapping = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % pt2['port_id'],
host='h2')
@ -3154,6 +3158,14 @@ class TestPolicyTarget(AIMBaseTestCase,
'name': self.driver.aim_mech_driver.apic_system_id +
'_DefaultSecurityGroup'})
self.assertEqual(sg_list, mapping['security_group'])
# Set the right MTU through extra_dhcp_opts
data = {'port': {'extra_dhcp_opts': [{'opt_name': 'interface-mtu',
'opt_value': '2000'}]}}
port = self._update('ports', port['id'], data)['port']
mapping = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % pt2['port_id'],
host='h2')
self.assertEqual(2000, mapping['interface_mtu'])
def _do_test_gbp_details_no_pt(self, use_as=True, routed=True,
pre_vrf=None):
@ -3262,6 +3274,14 @@ class TestPolicyTarget(AIMBaseTestCase,
self.assertFalse(mapping['ip_mapping'])
self.assertFalse(mapping['host_snat_ips'])
self.assertEqual(1000, mapping['interface_mtu'])
# Set the right MTU through extra_dhcp_opts
data = {'port': {'extra_dhcp_opts': [{'opt_name': '26',
'opt_value': '2100'}]}}
port = self._update('ports', port_id, data)['port']
mapping = self.driver.get_gbp_details(
self._neutron_admin_context, device='tap%s' % port_id,
host='h1')
self.assertEqual(2100, mapping['interface_mtu'])
def test_get_gbp_details(self):
self._do_test_get_gbp_details()