Skip to content

Commit 1a5c94d

Browse files
authored
Merge pull request #94 from stackhpc/upstream/2023.1-2023-12-11
Synchronise 2023.1 with upstream
2 parents 965943c + a28ec9e commit 1a5c94d

File tree

16 files changed

+296
-23
lines changed

16 files changed

+296
-23
lines changed

doc/source/admin/config-ovs-offload.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Validate Open vSwitch hardware offloading
355355

356356
.. code-block:: bash
357357
358-
# openstack port create --network private --vnic-type=direct --binding-profile '{"capabilities": ["switchdev"]}' direct_port1
358+
# openstack port create --network private --vnic-type=direct direct_port1
359359
360360
361361
#. Create an instance using the direct port on 'First Compute Node'
@@ -369,7 +369,7 @@ Validate Open vSwitch hardware offloading
369369

370370
.. code-block:: bash
371371
372-
# openstack port create --network private --vnic-type=direct --binding-profile '{"capabilities": ["switchdev"]}' direct_port2
372+
# openstack port create --network private --vnic-type=direct direct_port2
373373
# openstack server create --flavor m1.small --image mellanox_fedora --nic port-id=direct_port2 vm2
374374
375375
.. note::

neutron/agent/linux/dhcp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,8 @@ def _get_ovn_metadata_port_ip(self, subnet):
12131213
m_ports = [port for port in self.network.ports if
12141214
self._is_ovn_metadata_port(port, self.network.id)]
12151215
if m_ports:
1216-
for fixed_ip in m_ports[0].fixed_ips:
1216+
port = self.device_manager.plugin.get_dhcp_port(m_ports[0].id)
1217+
for fixed_ip in port.fixed_ips:
12171218
if fixed_ip.subnet_id == subnet.id:
12181219
return fixed_ip.ip_address
12191220

@@ -1289,7 +1290,7 @@ def _generate_opts_per_subnet(self):
12891290
if subnet_dhcp_ip:
12901291
metadata_route_ip = subnet_dhcp_ip
12911292

1292-
if not isolated_subnets[subnet.id] and gateway:
1293+
elif not isolated_subnets[subnet.id] and gateway:
12931294
metadata_route_ip = gateway
12941295

12951296
if metadata_route_ip:

neutron/common/ovn/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
OVN_PROVNET_PORT_NAME_PREFIX = 'provnet-'
7171
OVN_NAME_PREFIX = 'neutron-'
7272

73+
# TODO(froyo): Move this to neutron-lib as soon as possible, and when a new
74+
# release is created and pointed to in the requirements remove this code
75+
OVN_LB_HM_PORT_DISTRIBUTED = 'ovn-lb-hm:distributed'
76+
7377
# Agent extension constants
7478
OVN_AGENT_DESC_KEY = 'neutron:description'
7579
OVN_AGENT_METADATA_SB_CFG_KEY = 'neutron:ovn-metadata-sb-cfg'

neutron/common/ovn/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ def ovn_metadata_name(id_):
601601
return 'metadata-%s' % id_
602602

603603

604+
def is_ovn_lb_hm_port(port):
605+
return (port['device_owner'] == constants.OVN_LB_HM_PORT_DISTRIBUTED and
606+
port['device_id'].startswith('ovn-lb-hm'))
607+
608+
604609
def is_gateway_chassis_invalid(chassis_name, gw_chassis,
605610
physnet, chassis_physnets,
606611
az_hints, chassis_with_azs):

neutron/conf/agent/metadata/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
cfg.IntOpt('metadata_workers',
9595
sample_default='<num_of_cpus> / 2',
9696
help=_('Number of separate worker processes for metadata '
97-
'server (defaults to 2 when used with ML2/OVN and half '
97+
'server (defaults to 0 when used with ML2/OVN and half '
9898
'of the number of CPUs with other backend drivers)')),
9999
cfg.IntOpt('metadata_backlog',
100100
default=4096,

neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/impl_idl_ovn.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import socket
1616
import uuid
1717

18+
from neutron_lib import constants
1819
from neutron_lib import exceptions as n_exc
1920
from neutron_lib.utils import helpers
2021
from oslo_log import log
@@ -917,7 +918,10 @@ def get_metadata_port_network(self, network):
917918
except idlutils.RowNotFound:
918919
return None
919920
cmd = self.db_find_rows('Port_Binding', ('datapath', '=', dp),
920-
('type', '=', ovn_const.LSP_TYPE_LOCALPORT))
921+
('type', '=', ovn_const.LSP_TYPE_LOCALPORT),
922+
('external_ids', '=', {
923+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY:
924+
constants.DEVICE_OWNER_DISTRIBUTED}))
921925
return next(iter(cmd.execute(check_error=True)), None)
922926

923927
def set_chassis_neutron_description(self, chassis, description,

neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ def _get_port_options(self, port):
380380
cidrs += ' {}/{}'.format(ip['ip_address'],
381381
subnet['cidr'].split('/')[1])
382382

383-
# Metadata port.
384-
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
383+
# Metadata or OVN LB HM port.
384+
if (port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED or
385+
utils.is_ovn_lb_hm_port(port)):
385386
port_type = ovn_const.LSP_TYPE_LOCALPORT
386387

387388
if utils.is_port_external(port):

neutron/services/segments/db.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from oslo_log import log as logging
3232
from oslo_utils import uuidutils
3333

34+
from neutron.db.models import agent as agent_model
35+
from neutron.db.models import segment as segment_model
3436
from neutron.db import segments_db as db
3537
from neutron import manager
3638
from neutron.objects import base as base_obj
@@ -243,14 +245,43 @@ def update_segment_host_mapping(context, host, current_segment_ids):
243245
entry.segment_id, entry.host)
244246

245247

246-
def get_hosts_mapped_with_segments(context):
248+
def get_hosts_mapped_with_segments(context, include_agent_types=None,
249+
exclude_agent_types=None):
247250
"""Get hosts that are mapped with segments.
248251
249252
L2 providers can use this method to get an overview of SegmentHostMapping,
250253
and then delete the stale SegmentHostMapping.
254+
255+
When using both include_agent_types and exclude_agent_types,
256+
exclude_agent_types is most significant.
257+
All hosts without agent are excluded when using any agent_type filter.
258+
259+
:param context: current running context information
260+
:param include_agent_types: (set) List of agent types, include hosts
261+
with matching agents.
262+
:param exclude_agent_types: (set) List of agent types, exclude hosts
263+
with matching agents.
251264
"""
252-
segment_host_mapping = network.SegmentHostMapping.get_objects(context)
253-
return {row.host for row in segment_host_mapping}
265+
def add_filter_by_agent_types(qry, include, exclude):
266+
qry = qry.join(
267+
agent_model.Agent,
268+
segment_model.SegmentHostMapping.host == agent_model.Agent.host)
269+
if include:
270+
qry = qry.filter(agent_model.Agent.agent_type.in_(include))
271+
if exclude:
272+
qry = qry.filter(agent_model.Agent.agent_type.not_in(exclude))
273+
274+
return qry
275+
276+
with db_api.CONTEXT_READER.using(context):
277+
query = context.session.query(segment_model.SegmentHostMapping)
278+
if include_agent_types or exclude_agent_types:
279+
query = add_filter_by_agent_types(query, include_agent_types,
280+
exclude_agent_types)
281+
282+
res = query.all()
283+
284+
return {row.host for row in res}
254285

255286

256287
def _get_phys_nets(agent):

neutron/tests/fullstack/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import itertools
1717
import os
1818
import random
19+
import time
1920

2021
import netaddr
2122
from neutron_lib.tests import tools
@@ -96,6 +97,17 @@ def _agent_up():
9697
def _wait_until_agent_down(self, agent_id):
9798
def _agent_down():
9899
agent = self.client.show_agent(agent_id)['agent']
100+
if not agent.get('alive'):
101+
# NOTE(slaweq): to avoid race between heartbeat written in the
102+
# database and response to this API call, lets make sure that
103+
# agent is really dead. See bug
104+
# https://bugs.launchpad.net/neutron/+bug/2045757
105+
# for details.
106+
# 2 seconds delay should be more than enough to make sure that
107+
# all pending heartbeats are already written in the Neutron
108+
# database
109+
time.sleep(2)
110+
agent = self.client.show_agent(agent_id)['agent']
99111
return not agent.get('alive')
100112

101113
common_utils.wait_until_true(_agent_down)

neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
from unittest import mock
1818

19+
from neutron_lib import constants
1920
from oslo_config import fixture as fixture_config
2021
from oslo_utils import uuidutils
2122
from ovsdbapp.backend.ovs_idl import event
@@ -154,7 +155,9 @@ def _create_metadata_port(self, txn, lswitch_name, port_name=None):
154155
addresses='AA:AA:AA:AA:AA:AA 192.168.122.123',
155156
external_ids={
156157
ovn_const.OVN_CIDRS_EXT_ID_KEY: '192.168.122.123/24',
157-
ovn_const.OVN_DEVID_EXT_ID_KEY: 'ovnmeta-' + lswitch_name
158+
ovn_const.OVN_DEVID_EXT_ID_KEY: 'ovnmeta-' + lswitch_name,
159+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY:
160+
constants.DEVICE_OWNER_DISTRIBUTED
158161
}))
159162

160163
def _update_metadata_port_ip(self, metadata_port_name):

0 commit comments

Comments
 (0)