Skip to content

Commit 7212aa9

Browse files
authored
Merge pull request #105 from stackhpc/upstream/2023.1-2024-01-01
Synchronise 2023.1 with upstream
2 parents cd55efd + 6401d39 commit 7212aa9

File tree

7 files changed

+89
-19
lines changed

7 files changed

+89
-19
lines changed

neutron/agent/ovn/extensions/qos_hwol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OVSInterfaceEvent(row_event.RowEvent):
4848

4949
def __init__(self, ovn_agent):
5050
self.ovn_agent = ovn_agent
51-
events = (self.ROW_CREATE, self.ROW_DELETE)
51+
events = (self.ROW_CREATE, self.ROW_UPDATE, self.ROW_DELETE)
5252
table = 'Interface'
5353
super().__init__(events, table, None)
5454

@@ -58,7 +58,7 @@ def match_fn(self, event, row, old):
5858
return True
5959

6060
def run(self, event, row, old):
61-
if event == self.ROW_CREATE:
61+
if event in (self.ROW_CREATE, self.ROW_UPDATE):
6262
self.ovn_agent.qos_hwol_ext.add_port(
6363
row.external_ids['iface-id'], row.name)
6464
elif event == self.ROW_DELETE:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,8 @@ def sync_hostname_and_physical_networks(self, ctx):
13531353
LOG.debug('OVN-SB Sync hostname and physical networks started')
13541354
host_phynets_map = self.ovn_api.get_chassis_hostname_and_physnets()
13551355
current_hosts = set(host_phynets_map)
1356-
previous_hosts = segments_db.get_hosts_mapped_with_segments(ctx)
1356+
previous_hosts = segments_db.get_hosts_mapped_with_segments(
1357+
ctx, include_agent_types={ovn_const.OVN_CONTROLLER_AGENT})
13571358

13581359
stale_hosts = previous_hosts - current_hosts
13591360
for host in stale_hosts:

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,9 @@ def _verify_lb(test, protocol, vip_ext_port, vip_int_port):
908908
pf_def.INTERNAL_IP_ADDRESS: p1_ip}
909909
pf_obj = self.pf_plugin.create_floatingip_port_forwarding(
910910
self.context, fip_id, **fip_attrs(fip_pf_args))
911-
m_publish.assert_called_once()
911+
call = mock.call('port_forwarding', 'after_create', self.pf_plugin,
912+
payload=mock.ANY)
913+
m_publish.assert_has_calls([call])
912914

913915
# Assert load balancer for port forwarding was not created
914916
self.assertFalse(self._find_pf_lb(router_id, fip_id))
@@ -926,7 +928,9 @@ def _verify_lb(test, protocol, vip_ext_port, vip_int_port):
926928
m_publish.reset_mock()
927929
self.pf_plugin.update_floatingip_port_forwarding(
928930
self.context, pf_obj['id'], fip_id, **fip_attrs(fip_pf_args))
929-
m_publish.assert_called_once()
931+
call = mock.call('port_forwarding', 'after_update', self.pf_plugin,
932+
payload=mock.ANY)
933+
m_publish.assert_has_calls([call])
930934

931935
# Assert load balancer for port forwarding is stale
932936
_verify_lb(self, 'tcp', 2222, 22)

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,22 @@ def setUp(self):
18181818
def _sync_resources(self):
18191819
self.sb_synchronizer.sync_hostname_and_physical_networks(self.ctx)
18201820

1821+
def create_agent(self, host, bridge_mappings=None, agent_type=None):
1822+
if agent_type is None:
1823+
agent_type = ovn_const.OVN_CONTROLLER_AGENT
1824+
if bridge_mappings is None:
1825+
bridge_mappings = {}
1826+
agent = {
1827+
'host': host,
1828+
'agent_type': agent_type,
1829+
'binary': '/bin/test',
1830+
'topic': 'test_topic',
1831+
'configurations': {'bridge_mappings': bridge_mappings}
1832+
}
1833+
_, status = self.plugin.create_or_update_agent(self.context, agent)
1834+
1835+
return status['id']
1836+
18211837
def create_segment(self, network_id, physical_network, segmentation_id):
18221838
segment_data = {'network_id': network_id,
18231839
'physical_network': physical_network,
@@ -1858,6 +1874,7 @@ def test_ovn_sb_sync_delete_stale_host(self):
18581874
segment = self.create_segment(network_id, 'physnet1', 50)
18591875
segments_db.update_segment_host_mapping(
18601876
self.ctx, 'host1', {segment['id']})
1877+
_ = self.create_agent('host1', bridge_mappings={'physnet1': 'eth0'})
18611878
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
18621879
self.assertEqual({'host1'}, segment_hosts)
18631880
# Since there is no chassis in the sb DB, host1 is the stale host
@@ -1866,6 +1883,36 @@ def test_ovn_sb_sync_delete_stale_host(self):
18661883
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
18671884
self.assertFalse(segment_hosts)
18681885

1886+
def test_ovn_sb_sync_host_with_no_agent_not_deleted(self):
1887+
with self.network() as network:
1888+
network_id = network['network']['id']
1889+
segment = self.create_segment(network_id, 'physnet1', 50)
1890+
segments_db.update_segment_host_mapping(
1891+
self.ctx, 'host1', {segment['id']})
1892+
_ = self.create_agent('host1', bridge_mappings={'physnet1': 'eth0'},
1893+
agent_type="Not OVN Agent")
1894+
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
1895+
self.assertEqual({'host1'}, segment_hosts)
1896+
# There is no chassis in the sb DB, host1 does not have an agent
1897+
# so it is not deleted.
1898+
self._sync_resources()
1899+
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
1900+
self.assertEqual({'host1'}, segment_hosts)
1901+
1902+
def test_ovn_sb_sync_host_with_other_agent_type_not_deleted(self):
1903+
with self.network() as network:
1904+
network_id = network['network']['id']
1905+
segment = self.create_segment(network_id, 'physnet1', 50)
1906+
segments_db.update_segment_host_mapping(
1907+
self.ctx, 'host1', {segment['id']})
1908+
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
1909+
self.assertEqual({'host1'}, segment_hosts)
1910+
# There is no chassis in the sb DB, host1 does not have an agent
1911+
# so it is not deleted.
1912+
self._sync_resources()
1913+
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
1914+
self.assertEqual({'host1'}, segment_hosts)
1915+
18691916
def test_ovn_sb_sync(self):
18701917
with self.network() as network:
18711918
network_id = network['network']['id']
@@ -1878,6 +1925,9 @@ def test_ovn_sb_sync(self):
18781925
segments_db.update_segment_host_mapping(
18791926
self.ctx, 'host3', {seg1['id']})
18801927
segment_hosts = segments_db.get_hosts_mapped_with_segments(self.ctx)
1928+
_ = self.create_agent('host1')
1929+
_ = self.create_agent('host2', bridge_mappings={'physnet2': 'eth0'})
1930+
_ = self.create_agent('host3', bridge_mappings={'physnet3': 'eth0'})
18811931
self.assertEqual({'host1', 'host2', 'host3'}, segment_hosts)
18821932
self.add_fake_chassis('host2', ['physnet2'])
18831933
self.add_fake_chassis('host3', ['physnet3'])

neutron/tests/tools.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import fixtures
2121
import netaddr
22+
from neutron_lib.callbacks import priority_group
2223
from neutron_lib import constants
2324
from neutron_lib.services.logapi import constants as log_const
2425
from neutron_lib.utils import helpers
@@ -27,15 +28,15 @@
2728
from oslo_utils import timeutils
2829

2930

30-
# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added and
31-
# priority_group module was added for constants of priority.
32-
# test the existence of the module of priority_group to check if
33-
# callback priority is supported or not.
34-
_CALLBACK_PRIORITY_SUPPORTED = True
31+
# NOTE(ykarel): from neutron-lib 3.9.0, cancellable flag was added
32+
# test the existence of the is_cancellable_event function to check if
33+
# cancellable flag is supported or not. This compatibility check can
34+
# be removed once neutron-lib >= 3.9.0 in requirements.txt.
35+
_CANCELLABLE_FLAG_SUPPORTED = True
3536
try:
36-
from neutron_lib.callbacks import priority_group # noqa
37+
from neutron_lib.callbacks.events import is_cancellable_event # noqa
3738
except ImportError:
38-
_CALLBACK_PRIORITY_SUPPORTED = False
39+
_CANCELLABLE_FLAG_SUPPORTED = False
3940

4041
LAST_RANDOM_PORT_RANGE_GENERATED = 1
4142

@@ -146,12 +147,14 @@ def make_mock_plugin_json_encodable(plugin_instance_mock):
146147

147148

148149
def get_subscribe_args(*args):
149-
# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added.
150-
# old signature: (callback, resource, event)
151-
# new signature: (callback, resource, event, priority=PRIORITY_DEFAULT)
152-
if len(args) == 3 and _CALLBACK_PRIORITY_SUPPORTED:
153-
args = list(args) # don't modify original list
154-
args.append(priority_group.PRIORITY_DEFAULT)
150+
args = list(args) # don't modify original list
151+
args.append(priority_group.PRIORITY_DEFAULT)
152+
# NOTE(ykarel): from neutron-lib 3.9.0, cancellable flag was added.
153+
# old signature: (callback, resource, event, priority=PRIORITY_DEFAULT)
154+
# new signature: (callback, resource, event, priority=PRIORITY_DEFAULT,
155+
# cancellable=False)
156+
if len(args) == 4 and _CANCELLABLE_FLAG_SUPPORTED:
157+
args.append(False)
155158
return args
156159

157160

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,10 @@ def test_ovn_sb_sync(self):
11691169

11701170
with mock.patch.object(ovn_db_sync.segments_db,
11711171
'get_hosts_mapped_with_segments',
1172-
return_value=hosts_in_neutron):
1172+
return_value=hosts_in_neutron) as mock_ghmws:
11731173
ovn_sb_synchronizer.sync_hostname_and_physical_networks(mock.ANY)
1174+
mock_ghmws.assert_called_once_with(
1175+
mock.ANY, include_agent_types={ovn_const.OVN_CONTROLLER_AGENT})
11741176
all_hosts = set(hostname_with_physnets.keys()) | hosts_in_neutron
11751177
self.assertEqual(
11761178
len(all_hosts),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
fixes:
3+
- |
4+
When synchronizing the OVN databases, either when running the migration
5+
command or during startup, the code responsible for synchronization will
6+
only clean up segment-to-host mappings for hosts with agent_type
7+
``OVN Controller agent``. Before, the synchronization would clean up
8+
(delete) segment-to-host mappings for non-OVN hosts. Fixes bug:
9+
`2040172 <https://bugs.launchpad.net/neutron/+bug/2040172>`_.
10+

0 commit comments

Comments
 (0)