Skip to content

Commit 51961e1

Browse files
brianphaleyralonsoh
authored andcommitted
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. Closes-bug: #2045811 Change-Id: Ic5d9608277dd5c4881b3e4b494e1864be0bed1b4 (cherry picked from commit e4323e1)
1 parent d683804 commit 51961e1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,10 +870,20 @@ def _sync_subnet_dhcp_options(self, ctx, db_networks,
870870
LOG.warning('DHCP options for subnet %s present in '
871871
'Neutron but out of sync with OVN NB DB', subnet_id)
872872
if self.mode == SYNC_MODE_REPAIR:
873+
# If neutron-server is running we could race and find a
874+
# subnet without a cached network, just skip it to avoid
875+
# a KeyError below.
876+
network_id = utils.ovn_name(subnet['network_id'])
877+
if network_id not in db_networks:
878+
LOG.warning('Network %s for subnet %s not found in OVN NB '
879+
'DB network cache, possible race condition, '
880+
'please check that neutron-server is stopped! '
881+
'Skipping subnet.', network_id, subnet_id)
882+
continue
873883
try:
874884
LOG.warning('Adding/Updating DHCP options for subnet %s '
875885
'in OVN NB DB', subnet_id)
876-
network = db_networks[utils.ovn_name(subnet['network_id'])]
886+
network = db_networks[network_id]
877887
# _ovn_client._add_subnet_dhcp_options doesn't create
878888
# a new row in DHCP_Options if the row already exists.
879889
# 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)