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 135af5230e)
(cherry picked from commit 45a926156c)
This commit is contained in:
Steven Blatzheim 2024-02-28 07:25:59 +01:00
parent fab81c33ba
commit f2adeebdf2
4 changed files with 22 additions and 19 deletions

View File

@ -3610,6 +3610,7 @@ class API:
'gateway': network_model.IP(
address=subnet['gateway_ip'],
type='gateway'),
'enable_dhcp': False,
}
if subnet.get('ipv6_address_mode'):
subnet_dict['ipv6_address_mode'] = subnet['ipv6_address_mode']
@ -3626,22 +3627,14 @@ class API:
subnet_dict['dhcp_server'] = ip_pair['ip_address']
break
# NOTE(arnaudmorin): If enable_dhcp is set on subnet, but, for
# some reason neutron did not have any DHCP port yet, we still
# want the network_info to be populated with a valid dhcp_server
# value. This is mostly useful for the metadata API (which is
# relying on this value to give network_data to the instance).
#
# This will also help some providers which are using external
# DHCP servers not handled by neutron.
# In this case, neutron will never create any DHCP port in the
# subnet.
#
# Also note that we cannot set the value to None because then the
# value would be discarded by the metadata API.
# So the subnet gateway will be used as fallback.
if subnet.get('enable_dhcp') and 'dhcp_server' not in subnet_dict:
subnet_dict['dhcp_server'] = subnet['gateway_ip']
# NOTE(stblatzheim): If enable_dhcp is set on subnet, but subnet
# has ovn native dhcp and no dhcp-agents. Network owner will be
# network:distributed
# Just rely on enable_dhcp flag given by neutron
# Fix for https://bugs.launchpad.net/nova/+bug/2055245
if subnet.get('enable_dhcp'):
subnet_dict['enable_dhcp'] = True
subnet_object = network_model.Subnet(**subnet_dict)
for dns in subnet.get('dns_nameservers', []):

View File

@ -3615,8 +3615,8 @@ class TestAPI(TestAPIBase):
subnets = self.api._get_subnets_from_port(self.context, port_data)
self.assertEqual(subnet_data1[0]['gateway_ip'],
subnets[0]['meta']['dhcp_server'])
self.assertEqual(subnet_data1[0]['enable_dhcp'],
subnets[0]['meta']['enable_dhcp'])
@mock.patch.object(neutronapi, 'get_client', return_value=mock.Mock())
def test_get_physnet_tunneled_info_multi_segment(self, mock_get_client):

View File

@ -289,7 +289,8 @@ def _get_nets(vif, subnet, version, net_num, link_id):
net_type = ''
if subnet.get_meta('ipv6_address_mode') is not None:
net_type = '_%s' % subnet.get_meta('ipv6_address_mode')
elif subnet.get_meta('dhcp_server') is not None:
elif (subnet.get_meta('dhcp_server') is not None or
subnet.get_meta('enable_dhcp')):
net_info = {
'id': 'network%d' % net_num,
'type': 'ipv%d_dhcp' % version,

View File

@ -0,0 +1,9 @@
---
fixes:
- |
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.
Fix relies on enable_dhcp provided by neutron-api if no port with
``network:dhcp`` owner is found. See `bug 2055245
<https://bugs.launchpad.net/nova/+bug/2055245>`__ for details.