Browse Source

Exclude all device_ids that belong to Neutron DHCP Agent

It looks like sometimes, the device_id for ports created
by Neutron DHCP Agent can be in the form of:

- dhcp-$hostuuid-$networkid
- 'reserved_dhcp_port' (DEVICE_ID_RESERVED_DHCP_PORT)

Current code is only taking the first form into account when
skipping Neutron DHCP Agent ports. This patch is changing it
to include both forms.

Closes-Bug: #1848521
Co-Authored-By: Lucas Alvares Gomes <lucasagomes@gmail.com>
Change-Id: Ifbfc551ac68dcc5d3d39a155f7642f2f2d9272c4
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
(cherry picked from commit 15bf8f265b)
tags/6.0.1
Daniel Alvarez 4 months ago
parent
commit
509e2833ee
4 changed files with 35 additions and 8 deletions
  1. +4
    -4
      networking_ovn/common/ovn_client.py
  2. +11
    -0
      networking_ovn/common/utils.py
  3. +2
    -4
      networking_ovn/ovn_db_sync.py
  4. +18
    -0
      networking_ovn/tests/unit/ml2/test_mech_driver.py

+ 4
- 4
networking_ovn/common/ovn_client.py View File

@@ -230,7 +230,7 @@ class OVNClient(object):
# Only adjust the OVN type if the port is not owned by Neutron
# DHCP agents.
if (port['device_owner'] == const.DEVICE_OWNER_DHCP and
not port['device_id'].startswith('dhcp')):
not utils.is_neutron_dhcp_agent_port(port)):
port_type = 'localport'

# The "unknown" address should only be set for the normal LSP
@@ -1849,10 +1849,10 @@ class OVNClient(object):
ports = self._plugin.get_ports(context, filters=dict(
network_id=[network_id], device_owner=[const.DEVICE_OWNER_DHCP]))

# Metadata ports are DHCP ports without a device_id starting by 'dhcp'
# since those belong to Neutron DHCP agents.
# Metadata ports are DHCP ports not belonging to the Neutron
# DHCP agents
for port in ports:
if not port['device_id'].startswith('dhcp'):
if not utils.is_neutron_dhcp_agent_port(port):
return port

def _find_metadata_port_ip(self, context, subnet):

+ 11
- 0
networking_ovn/common/utils.py View File

@@ -415,3 +415,14 @@ def is_gateway_chassis_invalid(chassis_name, gw_chassis,
elif gw_chassis and chassis_name not in gw_chassis:
return True
return False


def is_neutron_dhcp_agent_port(port):
"""Check if the given DHCP port belongs to Neutron DHCP agents

The DHCP ports with the device_id equals to 'reserved_dhcp_port'
or starting with the word 'dhcp' belongs to the Neutron DHCP agents.
"""
return (port['device_owner'] == const.DEVICE_OWNER_DHCP and
(port['device_id'] == const.DEVICE_ID_RESERVED_DHCP_PORT or
port['device_id'].startswith('dhcp')))

+ 2
- 4
networking_ovn/ovn_db_sync.py View File

@@ -902,10 +902,8 @@ class OvnNbSynchronizer(OvnDbSynchronizer):
device_owner=[constants.DEVICE_OWNER_DHCP]))

for port in dhcp_ports:
# Ports with a device_id like 'dhcp<host_id>-<network_id>'
# belong to Neutron DHCP agent so we'll skip those for OVN
# metadata.
if port['device_id'].startswith('dhcp'):
# Do not touch the Neutron DHCP agents ports
if utils.is_neutron_dhcp_agent_port(port):
dhcp_ports.remove(port)

if not dhcp_ports:

+ 18
- 0
networking_ovn/tests/unit/ml2/test_mech_driver.py View File

@@ -2602,6 +2602,7 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
self.mech_driver._sb_ovn = fakes.FakeOvsdbSbOvnIdl()
self.nb_ovn = self.mech_driver._nb_ovn
self.sb_ovn = self.mech_driver._sb_ovn
self.ctx = context.get_admin_context()
ovn_config.cfg.CONF.set_override('ovn_metadata_enabled',
True,
group='ovn')
@@ -2609,6 +2610,23 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
p.start()
self.addCleanup(p.stop)

def _create_fake_dhcp_port(self, device_id):
return {'network_id': 'fake', 'device_owner': const.DEVICE_OWNER_DHCP,
'device_id': device_id}

@mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.get_ports')
def test__find_metadata_port(self, mock_get_ports):
ports = [
self._create_fake_dhcp_port('dhcp-0'),
self._create_fake_dhcp_port('dhcp-1'),
self._create_fake_dhcp_port(const.DEVICE_ID_RESERVED_DHCP_PORT),
self._create_fake_dhcp_port('ovnmeta-0')]
mock_get_ports.return_value = ports

md_port = self.mech_driver._ovn_client._find_metadata_port(
self.ctx, 'fake-net-id')
self.assertEqual('ovnmeta-0', md_port['device_id'])

def test_metadata_port_on_network_create(self):
"""Check metadata port create.


Loading…
Cancel
Save