Skip to content

Commit 877e85e

Browse files
committed
[OVN] DB sync host/physnet - filter on agent_type
When syncing hostname and physical networks, filter neutron hosts on agent_type. Only segmenthostmappings for hosts with agent 'OVN Controller agent' should be cleaned up. Since change: I935186b6ee95f0cae8dc05869d9742c8fb3353c3 there is de-duplication of segmenthostmapping updates from agents. If the OVN DB sync clears/deletes mappings for hosts owned by other agents/plugins the mappings are never re-created. Closes-Bug: #2040172 Change-Id: Iaf15e560e1b1ec31618b2ebc6206a938463c1094 Signed-off-by: Harald Jensås <[email protected]> (cherry picked from commit 3aafeef)
1 parent 98a3eae commit 877e85e

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

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_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/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)