Don't provide MTU value in metadata service if DHCP is enabled

For networks with subnets with enabled DHCP service don't provide
mtu value in the metadata. That way cloud-init will not configure it
"statically" in e.g. netplan's config file and guest OS will use MTU
value provided by the DHCP service.


Closes-Bug: #1899487
Change-Id: Ib775c2210349b72b3dc033554ac6d8b35b8d2d79
This commit is contained in:
Slawek Kaplonski 2022-09-02 15:58:50 +02:00 committed by Sylvain Bauza
parent 0bab2e5a88
commit 6bdc79af30
3 changed files with 36 additions and 1 deletions

View File

@ -17,6 +17,17 @@ from nova.virt import netutils
class TestNetUtilsTestCase(test.NoDBTestCase):
def _get_fake_instance_nw_info(self, num_networks, dhcp_server, mtu):
network_info = fake_network.fake_get_instance_nw_info(self,
num_networks)
for vif in network_info:
for subnet in vif['network']['subnets']:
subnet['meta']['dhcp_server'] = dhcp_server
vif['network']['meta']['mtu'] = mtu
return network_info
def test_get_cached_vifs_with_vlan_no_nw_info(self):
# Make sure that an empty dictionary will be returned when
# nw_info is None
@ -39,3 +50,15 @@ class TestNetUtilsTestCase(test.NoDBTestCase):
expected = {'fa:16:3e:d1:28:e4': '2145'}
self.assertEqual(expected,
netutils.get_cached_vifs_with_vlan(network_info))
def test__get_link_mtu(self):
network_info_dhcp = self._get_fake_instance_nw_info(
1, '192.168.0.100', 9000)
network_info_no_dhcp = self._get_fake_instance_nw_info(
1, None, 9000)
for vif in network_info_dhcp:
self.assertIsNone(netutils._get_link_mtu(vif))
for vif in network_info_no_dhcp:
self.assertEqual(9000, netutils._get_link_mtu(vif))

View File

@ -263,12 +263,19 @@ def _get_eth_link(vif, ifc_num):
'id': link_id,
'vif_id': vif['id'],
'type': nic_type,
'mtu': vif['network']['meta'].get('mtu'),
'mtu': _get_link_mtu(vif),
'ethernet_mac_address': vif.get('address'),
}
return link
def _get_link_mtu(vif):
for subnet in vif['network']['subnets']:
if subnet['meta'].get('dhcp_server'):
return None
return vif['network']['meta'].get('mtu')
def _get_nets(vif, subnet, version, net_num, link_id):
"""Get networks for the given VIF and subnet

View File

@ -0,0 +1,5 @@
---
other:
- |
For networks which have any subnets with enabled DHCP, MTU value is not send
in the metadata. In such case MTU is configured through the DHCP server.