Browse Source

Merge "Exclude all device_ids that belong to Neutron DHCP Agent" into stable/rocky

changes/44/703944/1
Zuul 4 weeks ago
parent
commit
6a196c1476
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
@@ -1803,10 +1803,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

@@ -403,3 +403,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

@@ -904,10 +904,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

@@ -2530,6 +2530,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')
@@ -2537,6 +2538,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