Skip to content

Commit 608914c

Browse files
committed
Fix KeyError failure in _sync_subnet_dhcp_options()
If the netron-ovn-db-sync-util is run while neutron-server is active (which is not recommended), it can randomly fail if there are active API calls in flight to create networks and/or subnets. Skip the subnet and log a warning if detected. Conflicts: neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovn_db_sync.py Closes-bug: #2045811 Change-Id: Ic5d9608277dd5c4881b3e4b494e1864be0bed1b4 (cherry picked from commit e4323e1) (cherry picked from commit 2ec0ef0) (cherry picked from commit 4fc3c71)
1 parent c19c0a1 commit 608914c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,20 @@ def _sync_subnet_dhcp_options(self, ctx, db_networks,
856856
LOG.warning('DHCP options for subnet %s is present in '
857857
'Neutron but out of sync for OVN', subnet_id)
858858
if self.mode == SYNC_MODE_REPAIR:
859+
# If neutron-server is running we could race and find a
860+
# subnet without a cached network, just skip it to avoid
861+
# a KeyError below.
862+
network_id = utils.ovn_name(subnet['network_id'])
863+
if network_id not in db_networks:
864+
LOG.warning('Network %s for subnet %s not found in OVN NB '
865+
'DB network cache, possible race condition, '
866+
'please check that neutron-server is stopped! '
867+
'Skipping subnet.', network_id, subnet_id)
868+
continue
859869
try:
860-
LOG.debug('Adding/Updating DHCP options for subnet %s in '
861-
' OVN NB DB', subnet_id)
862-
network = db_networks[utils.ovn_name(subnet['network_id'])]
870+
LOG.warning('Adding/Updating DHCP options for subnet %s '
871+
'in OVN NB DB', subnet_id)
872+
network = db_networks[network_id]
863873
# _ovn_client._add_subnet_dhcp_options doesn't create
864874
# a new row in DHCP_Options if the row already exists.
865875
# See commands.AddDHCPOptionsCommand.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ def setUp(self):
104104
'gateway_ip': '20.0.0.1',
105105
'dns_nameservers': [],
106106
'host_routes': [],
107+
'ip_version': 4},
108+
# A subnet without a known network should be skipped,
109+
# see bug #2045811
110+
{'id': 'notfound',
111+
'network_id': 'notfound',
112+
'enable_dhcp': True,
113+
'cidr': '30.0.0.0/24',
114+
'tenant_id': 'tenant1',
115+
'gateway_ip': '30.0.0.1',
116+
'dns_nameservers': [],
117+
'host_routes': [],
107118
'ip_version': 4}]
108119

109120
self.security_groups = [

0 commit comments

Comments
 (0)