Merge "[OVN] Metadata ports device_owner is "network:distributed" only"
This commit is contained in:
commit
5116a88f27
@ -460,17 +460,6 @@ def is_provider_network(network):
|
|||||||
return network.get(external_net.EXTERNAL, False)
|
return network.get(external_net.EXTERNAL, 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')))
|
|
||||||
|
|
||||||
|
|
||||||
def compute_address_pairs_diff(ovn_port, neutron_port):
|
def compute_address_pairs_diff(ovn_port, neutron_port):
|
||||||
"""Compute the differences in the allowed_address_pairs field."""
|
"""Compute the differences in the allowed_address_pairs field."""
|
||||||
ovn_ap = get_allowed_address_pairs_ip_addresses_from_ovn_port(
|
ovn_ap = get_allowed_address_pairs_ip_addresses_from_ovn_port(
|
||||||
|
@ -270,14 +270,8 @@ class OVNClient(object):
|
|||||||
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
|
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
|
||||||
','.join(parents))
|
','.join(parents))
|
||||||
|
|
||||||
# Only adjust the OVN type if the port is not owned by Neutron
|
# Metadata port.
|
||||||
# DHCP agents.
|
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
|
||||||
# TODO(mjozefcz): Remove const.DEVICE_OWNER_DHCP
|
|
||||||
# from get_ports in W-release.
|
|
||||||
if (port['device_owner'] in [
|
|
||||||
const.DEVICE_OWNER_DISTRIBUTED,
|
|
||||||
const.DEVICE_OWNER_DHCP] and
|
|
||||||
not utils.is_neutron_dhcp_agent_port(port)):
|
|
||||||
port_type = ovn_const.LSP_TYPE_LOCALPORT
|
port_type = ovn_const.LSP_TYPE_LOCALPORT
|
||||||
|
|
||||||
if utils.is_port_external(port):
|
if utils.is_port_external(port):
|
||||||
@ -2176,35 +2170,20 @@ class OVNClient(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_metadata_port(port):
|
def is_metadata_port(port):
|
||||||
# TODO(ralonsoh): This method is implemented in order to be backported
|
return port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED
|
||||||
# to stable releases; this is why a "const.DEVICE_OWNER_DHCP" port
|
|
||||||
# could be a metadata port.
|
|
||||||
return (port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED or
|
|
||||||
(port['device_owner'] == const.DEVICE_OWNER_DHCP and
|
|
||||||
not utils.is_neutron_dhcp_agent_port(port)))
|
|
||||||
|
|
||||||
def _find_metadata_port(self, context, network_id):
|
def _find_metadata_port(self, context, network_id):
|
||||||
if not ovn_conf.is_ovn_metadata_enabled():
|
if not ovn_conf.is_ovn_metadata_enabled():
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO(mjozefcz): Remove const.DEVICE_OWNER_DHCP
|
ports = self._plugin.get_ports(
|
||||||
# from get_ports in W-release.
|
context, filters=dict(
|
||||||
ports = self._plugin.get_ports(context, filters=dict(
|
|
||||||
network_id=[network_id],
|
network_id=[network_id],
|
||||||
device_owner=[
|
device_owner=[const.DEVICE_OWNER_DISTRIBUTED]),
|
||||||
const.DEVICE_OWNER_DHCP,
|
limit=1)
|
||||||
const.DEVICE_OWNER_DISTRIBUTED]))
|
|
||||||
# TODO(mjozefcz): Remove this compatibility code in W release.
|
if ports:
|
||||||
# First look for const.DEVICE_OWNER_DISTRIBUTED and then for
|
return ports[0]
|
||||||
# const.DEVICE_OWNER_DHCP.
|
|
||||||
for port in ports:
|
|
||||||
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
|
|
||||||
return port
|
|
||||||
# Metadata ports are DHCP ports not belonging to the Neutron
|
|
||||||
# DHCP agents
|
|
||||||
for port in ports:
|
|
||||||
if not utils.is_neutron_dhcp_agent_port(port):
|
|
||||||
return port
|
|
||||||
|
|
||||||
def _find_metadata_port_ip(self, context, subnet):
|
def _find_metadata_port_ip(self, context, subnet):
|
||||||
metadata_port = self._find_metadata_port(context, subnet['network_id'])
|
metadata_port = self._find_metadata_port(context, subnet['network_id'])
|
||||||
|
@ -900,21 +900,13 @@ class OvnNbSynchronizer(OvnDbSynchronizer):
|
|||||||
if not ovn_conf.is_ovn_metadata_enabled():
|
if not ovn_conf.is_ovn_metadata_enabled():
|
||||||
return
|
return
|
||||||
LOG.debug('OVN sync metadata ports started')
|
LOG.debug('OVN sync metadata ports started')
|
||||||
# TODO(mjozefcz): Remove constants.DEVICE_OWNER_DHCP
|
|
||||||
# from get_ports in W-release.
|
|
||||||
for net in self.core_plugin.get_networks(ctx):
|
for net in self.core_plugin.get_networks(ctx):
|
||||||
# Get only DHCP ports that don't belong to agent, it should return
|
metadata_ports = self.core_plugin.get_ports(
|
||||||
# only OVN metadata ports
|
|
||||||
dhcp_ports = [
|
|
||||||
p for p in self.core_plugin.get_ports(
|
|
||||||
ctx, filters=dict(
|
ctx, filters=dict(
|
||||||
network_id=[net['id']],
|
network_id=[net['id']],
|
||||||
device_owner=[
|
device_owner=[constants.DEVICE_OWNER_DISTRIBUTED]))
|
||||||
constants.DEVICE_OWNER_DISTRIBUTED,
|
|
||||||
constants.DEVICE_OWNER_DHCP]))
|
|
||||||
if not utils.is_neutron_dhcp_agent_port(p)]
|
|
||||||
|
|
||||||
if not dhcp_ports:
|
if not metadata_ports:
|
||||||
LOG.warning('Missing metadata port found in Neutron for '
|
LOG.warning('Missing metadata port found in Neutron for '
|
||||||
'network %s', net['id'])
|
'network %s', net['id'])
|
||||||
if self.mode == SYNC_MODE_REPAIR:
|
if self.mode == SYNC_MODE_REPAIR:
|
||||||
@ -931,7 +923,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer):
|
|||||||
else:
|
else:
|
||||||
# Delete all but one DHCP ports. Only one is needed for
|
# Delete all but one DHCP ports. Only one is needed for
|
||||||
# metadata.
|
# metadata.
|
||||||
for port in dhcp_ports[1:]:
|
for port in metadata_ports[1:]:
|
||||||
LOG.warning('Unnecessary DHCP port %s for network %s '
|
LOG.warning('Unnecessary DHCP port %s for network %s '
|
||||||
'found in Neutron', port['id'], net['id'])
|
'found in Neutron', port['id'], net['id'])
|
||||||
if self.mode == SYNC_MODE_REPAIR:
|
if self.mode == SYNC_MODE_REPAIR:
|
||||||
@ -939,7 +931,7 @@ class OvnNbSynchronizer(OvnDbSynchronizer):
|
|||||||
'network %s', port['id'], net['id'])
|
'network %s', port['id'], net['id'])
|
||||||
self.core_plugin.delete_port(ctx, port['id'])
|
self.core_plugin.delete_port(ctx, port['id'])
|
||||||
db_ports.pop(port['id'], None)
|
db_ports.pop(port['id'], None)
|
||||||
port = dhcp_ports[0]
|
port = metadata_ports[0]
|
||||||
if port['id'] in db_ports.keys():
|
if port['id'] in db_ports.keys():
|
||||||
LOG.warning('Metadata port %s for network %s found in '
|
LOG.warning('Metadata port %s for network %s found in '
|
||||||
'Neutron but not in OVN',
|
'Neutron but not in OVN',
|
||||||
|
@ -3485,34 +3485,6 @@ class TestOVNMechanismDriverMetadataPort(MechDriverSetupBase,
|
|||||||
port['device_owner'] = const.DEVICE_OWNER_DHCP
|
port['device_owner'] = const.DEVICE_OWNER_DHCP
|
||||||
return port
|
return port
|
||||||
|
|
||||||
@mock.patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_ports')
|
|
||||||
def test__find_metadata_port(self, mock_get_ports):
|
|
||||||
ports = [
|
|
||||||
self._create_fake_dhcp_port('dhcp-0', neutron_port=True),
|
|
||||||
self._create_fake_dhcp_port('dhcp-1', neutron_port=True),
|
|
||||||
self._create_fake_dhcp_port(const.DEVICE_ID_RESERVED_DHCP_PORT,
|
|
||||||
neutron_port=True),
|
|
||||||
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'])
|
|
||||||
|
|
||||||
@mock.patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_ports')
|
|
||||||
def test__find_metadata_port_compat(self, mock_get_ports):
|
|
||||||
ports = [
|
|
||||||
self._create_fake_dhcp_port('dhcp-0', neutron_port=True),
|
|
||||||
self._create_fake_dhcp_port('dhcp-1', neutron_port=True),
|
|
||||||
self._create_fake_dhcp_port(const.DEVICE_ID_RESERVED_DHCP_PORT,
|
|
||||||
neutron_port=True),
|
|
||||||
self._create_fake_dhcp_port('ovnmeta-0', neutron_port=True)]
|
|
||||||
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):
|
def test_metadata_port_on_network_create(self):
|
||||||
"""Check metadata port create.
|
"""Check metadata port create.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user