Skip to content

Commit ec15df8

Browse files
slawqoSeanMooney
authored andcommitted
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 (cherry picked from commit 6bdc79a)
1 parent 68ed11b commit ec15df8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

nova/tests/unit/virt/test_netutils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818

1919
class TestNetUtilsTestCase(test.NoDBTestCase):
20+
21+
def _get_fake_instance_nw_info(self, num_networks, dhcp_server, mtu):
22+
network_info = fake_network.fake_get_instance_nw_info(self,
23+
num_networks)
24+
for vif in network_info:
25+
for subnet in vif['network']['subnets']:
26+
subnet['meta']['dhcp_server'] = dhcp_server
27+
vif['network']['meta']['mtu'] = mtu
28+
29+
return network_info
30+
2031
def test_get_cached_vifs_with_vlan_no_nw_info(self):
2132
# Make sure that an empty dictionary will be returned when
2233
# nw_info is None
@@ -39,3 +50,15 @@ def test_get_cached_vifs_with_vlan(self):
3950
expected = {'fa:16:3e:d1:28:e4': '2145'}
4051
self.assertEqual(expected,
4152
netutils.get_cached_vifs_with_vlan(network_info))
53+
54+
def test__get_link_mtu(self):
55+
network_info_dhcp = self._get_fake_instance_nw_info(
56+
1, '192.168.0.100', 9000)
57+
network_info_no_dhcp = self._get_fake_instance_nw_info(
58+
1, None, 9000)
59+
60+
for vif in network_info_dhcp:
61+
self.assertIsNone(netutils._get_link_mtu(vif))
62+
63+
for vif in network_info_no_dhcp:
64+
self.assertEqual(9000, netutils._get_link_mtu(vif))

nova/virt/netutils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,19 @@ def _get_eth_link(vif, ifc_num):
263263
'id': link_id,
264264
'vif_id': vif['id'],
265265
'type': nic_type,
266-
'mtu': vif['network']['meta'].get('mtu'),
266+
'mtu': _get_link_mtu(vif),
267267
'ethernet_mac_address': vif.get('address'),
268268
}
269269
return link
270270

271271

272+
def _get_link_mtu(vif):
273+
for subnet in vif['network']['subnets']:
274+
if subnet['meta'].get('dhcp_server'):
275+
return None
276+
return vif['network']['meta'].get('mtu')
277+
278+
272279
def _get_nets(vif, subnet, version, net_num, link_id):
273280
"""Get networks for the given VIF and subnet
274281
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
other:
3+
- |
4+
For networks which have any subnets with enabled DHCP, MTU value is not send
5+
in the metadata. In such case MTU is configured through the DHCP server.

0 commit comments

Comments
 (0)