Skip to content

Commit f2adeeb

Browse files
author
Steven Blatzheim
committed
Fix nova-metadata-api for ovn dhcp native networks
With the change from ml2/ovs DHCP agents towards OVN implementation in neutron there is no port with device_owner network:dhcp anymore. Instead DHCP is provided by network:distributed port. Closes-Bug: 2055245 Change-Id: Ibb569b9db1475b8bbd8f8722d49228182cd47f85 (cherry picked from commit 135af52) (cherry picked from commit 45a9261)
1 parent fab81c3 commit f2adeeb

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

nova/network/neutron.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,6 +3610,7 @@ def _get_subnets_from_port(self, context, port, client=None):
36103610
'gateway': network_model.IP(
36113611
address=subnet['gateway_ip'],
36123612
type='gateway'),
3613+
'enable_dhcp': False,
36133614
}
36143615
if subnet.get('ipv6_address_mode'):
36153616
subnet_dict['ipv6_address_mode'] = subnet['ipv6_address_mode']
@@ -3626,22 +3627,14 @@ def _get_subnets_from_port(self, context, port, client=None):
36263627
subnet_dict['dhcp_server'] = ip_pair['ip_address']
36273628
break
36283629

3629-
# NOTE(arnaudmorin): If enable_dhcp is set on subnet, but, for
3630-
# some reason neutron did not have any DHCP port yet, we still
3631-
# want the network_info to be populated with a valid dhcp_server
3632-
# value. This is mostly useful for the metadata API (which is
3633-
# relying on this value to give network_data to the instance).
3634-
#
3635-
# This will also help some providers which are using external
3636-
# DHCP servers not handled by neutron.
3637-
# In this case, neutron will never create any DHCP port in the
3638-
# subnet.
3639-
#
3640-
# Also note that we cannot set the value to None because then the
3641-
# value would be discarded by the metadata API.
3642-
# So the subnet gateway will be used as fallback.
3643-
if subnet.get('enable_dhcp') and 'dhcp_server' not in subnet_dict:
3644-
subnet_dict['dhcp_server'] = subnet['gateway_ip']
3630+
# NOTE(stblatzheim): If enable_dhcp is set on subnet, but subnet
3631+
# has ovn native dhcp and no dhcp-agents. Network owner will be
3632+
# network:distributed
3633+
# Just rely on enable_dhcp flag given by neutron
3634+
# Fix for https://bugs.launchpad.net/nova/+bug/2055245
3635+
3636+
if subnet.get('enable_dhcp'):
3637+
subnet_dict['enable_dhcp'] = True
36453638

36463639
subnet_object = network_model.Subnet(**subnet_dict)
36473640
for dns in subnet.get('dns_nameservers', []):

nova/tests/unit/network/test_neutron.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,8 +3615,8 @@ def test_get_subnets_from_port_enabled_dhcp_no_dhcp_ports(self,
36153615

36163616
subnets = self.api._get_subnets_from_port(self.context, port_data)
36173617

3618-
self.assertEqual(subnet_data1[0]['gateway_ip'],
3619-
subnets[0]['meta']['dhcp_server'])
3618+
self.assertEqual(subnet_data1[0]['enable_dhcp'],
3619+
subnets[0]['meta']['enable_dhcp'])
36203620

36213621
@mock.patch.object(neutronapi, 'get_client', return_value=mock.Mock())
36223622
def test_get_physnet_tunneled_info_multi_segment(self, mock_get_client):

nova/virt/netutils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ def _get_nets(vif, subnet, version, net_num, link_id):
289289
net_type = ''
290290
if subnet.get_meta('ipv6_address_mode') is not None:
291291
net_type = '_%s' % subnet.get_meta('ipv6_address_mode')
292-
elif subnet.get_meta('dhcp_server') is not None:
292+
elif (subnet.get_meta('dhcp_server') is not None or
293+
subnet.get_meta('enable_dhcp')):
293294
net_info = {
294295
'id': 'network%d' % net_num,
295296
'type': 'ipv%d_dhcp' % version,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
fixes:
3+
- |
4+
With the change from ml2/ovs DHCP agents towards OVN implementation
5+
in neutron there is no port with device_owner ``network:dhcp`` anymore.
6+
Instead DHCP is provided by ``network:distributed`` port.
7+
Fix relies on enable_dhcp provided by neutron-api if no port with
8+
``network:dhcp`` owner is found. See `bug 2055245
9+
<https://bugs.launchpad.net/nova/+bug/2055245>`__ for details.

0 commit comments

Comments
 (0)