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

This commit is contained in:
Zuul
2022-11-29 22:02:04 +00:00
committed by Gerrit Code Review
3 changed files with 36 additions and 1 deletions
+23
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))
+8 -1
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
@@ -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.