Skip to content

Commit 4fc3c71

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)
1 parent de9e3e8 commit 4fc3c71

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
@@ -863,10 +863,20 @@ def _sync_subnet_dhcp_options(self, ctx, db_networks,
863863
LOG.warning('DHCP options for subnet %s is present in '
864864
'Neutron but out of sync for OVN', subnet_id)
865865
if self.mode == SYNC_MODE_REPAIR:
866+
# If neutron-server is running we could race and find a
867+
# subnet without a cached network, just skip it to avoid
868+
# a KeyError below.
869+
network_id = utils.ovn_name(subnet['network_id'])
870+
if network_id not in db_networks:
871+
LOG.warning('Network %s for subnet %s not found in OVN NB '
872+
'DB network cache, possible race condition, '
873+
'please check that neutron-server is stopped! '
874+
'Skipping subnet.', network_id, subnet_id)
875+
continue
866876
try:
867-
LOG.debug('Adding/Updating DHCP options for subnet %s in '
868-
' OVN NB DB', subnet_id)
869-
network = db_networks[utils.ovn_name(subnet['network_id'])]
877+
LOG.warning('Adding/Updating DHCP options for subnet %s '
878+
'in OVN NB DB', subnet_id)
879+
network = db_networks[network_id]
870880
# _ovn_client._add_subnet_dhcp_options doesn't create
871881
# a new row in DHCP_Options if the row already exists.
872882
# 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)