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 e4323e1f20
)
This commit is contained in:
parent
377e1f6838
commit
e34c95c4b9
|
@ -865,10 +865,20 @@ class OvnNbSynchronizer(OvnDbSynchronizer):
|
|||
LOG.warning('DHCP options for subnet %s is present in '
|
||||
'Neutron but out of sync for OVN', subnet_id)
|
||||
if self.mode == SYNC_MODE_REPAIR:
|
||||
# If neutron-server is running we could race and find a
|
||||
# subnet without a cached network, just skip it to avoid
|
||||
# a KeyError below.
|
||||
network_id = utils.ovn_name(subnet['network_id'])
|
||||
if network_id not in db_networks:
|
||||
LOG.warning('Network %s for subnet %s not found in OVN NB '
|
||||
'DB network cache, possible race condition, '
|
||||
'please check that neutron-server is stopped! '
|
||||
'Skipping subnet.', network_id, subnet_id)
|
||||
continue
|
||||
try:
|
||||
LOG.debug('Adding/Updating DHCP options for subnet %s in '
|
||||
' OVN NB DB', subnet_id)
|
||||
network = db_networks[utils.ovn_name(subnet['network_id'])]
|
||||
LOG.warning('Adding/Updating DHCP options for subnet %s '
|
||||
'in OVN NB DB', subnet_id)
|
||||
network = db_networks[network_id]
|
||||
# _ovn_client._add_subnet_dhcp_options doesn't create
|
||||
# a new row in DHCP_Options if the row already exists.
|
||||
# See commands.AddDHCPOptionsCommand.
|
||||
|
|
|
@ -104,6 +104,17 @@ class TestOvnNbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
|
|||
'gateway_ip': '20.0.0.1',
|
||||
'dns_nameservers': [],
|
||||
'host_routes': [],
|
||||
'ip_version': 4},
|
||||
# A subnet without a known network should be skipped,
|
||||
# see bug #2045811
|
||||
{'id': 'notfound',
|
||||
'network_id': 'notfound',
|
||||
'enable_dhcp': True,
|
||||
'cidr': '30.0.0.0/24',
|
||||
'tenant_id': 'tenant1',
|
||||
'gateway_ip': '30.0.0.1',
|
||||
'dns_nameservers': [],
|
||||
'host_routes': [],
|
||||
'ip_version': 4}]
|
||||
|
||||
self.security_groups = [
|
||||
|
|
Loading…
Reference in New Issue