Browse Source

Merge "Fix race condition retrieving logical router rows" into stable/train

changes/55/819655/1
Zuul 6 months ago committed by Gerrit Code Review
parent
commit
6e8296cb5a
  1. 19
      networking_ovn/octavia/ovn_driver.py
  2. 28
      networking_ovn/ovsdb/impl_idl_ovn.py
  3. 1
      networking_ovn/ovsdb/ovsdb_monitor.py
  4. 7
      networking_ovn/tests/unit/octavia/test_ovn_driver.py

19
networking_ovn/octavia/ovn_driver.py

@ -460,8 +460,8 @@ class OvnProviderHelper(object):
[])}
def _find_lb_in_table(self, lb, table):
return [item for item in self.ovn_nbdb_api.tables[table].rows.values()
if lb in item.load_balancer]
return self.ovn_nbdb_api.find_lb_in_table(
lb, table).execute(check_error=True)
def request_handler(self):
while True:
@ -797,7 +797,8 @@ class OvnProviderHelper(object):
if not lrp_name:
return
for lr in self.ovn_nbdb_api.tables['Logical_Router'].rows.values():
lrs = self.ovn_nbdb_api.get_lrs().execute(check_error=True)
for lr in lrs:
for lrp in lr.ports:
if lrp.name == lrp_name:
return lr
@ -1136,12 +1137,12 @@ class OvnProviderHelper(object):
if_exists=True))
lr_ref = ovn_lb.external_ids.get(ovn_const.LB_EXT_IDS_LR_REF_KEY, {})
if lr_ref:
for lr in self.ovn_nbdb_api.tables[
'Logical_Router'].rows.values():
if lr.name == lr_ref:
commands.append(self.ovn_nbdb_api.lr_lb_del(
lr.uuid, ovn_lb.uuid))
break
try:
lr = self.ovn_nbdb_api.lookup('Logical_Router', lr_ref)
commands.append(self.ovn_nbdb_api.lr_lb_del(
lr.uuid, ovn_lb.uuid))
except idlutils.RowNotFound:
pass
# Delete LB from all Routers the LB is indirectly associated
for lr in self._find_lb_in_table(ovn_lb, 'Logical_Router'):
commands.append(

28
networking_ovn/ovsdb/impl_idl_ovn.py

@ -22,8 +22,10 @@ from oslo_utils import uuidutils
from ovs import socket_util
from ovs import stream
from ovsdbapp.backend import ovs_idl
from ovsdbapp.backend.ovs_idl import command
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.backend.ovs_idl import idlutils
from ovsdbapp.backend.ovs_idl import rowview
from ovsdbapp.backend.ovs_idl import transaction as idl_trans
from ovsdbapp.backend.ovs_idl import vlog
from ovsdbapp.schema.ovn_northbound import impl_idl as nb_impl_idl
@ -175,6 +177,26 @@ class OvsdbConnectionUnavailable(n_exc.ServiceUnavailable):
"'ovn_sb_connection' configuration options are correct.")
class FindLbInTableCommand(command.ReadOnlyCommand):
def __init__(self, api, lb, table):
super(FindLbInTableCommand, self).__init__(api)
self.lb = lb
self.table = table
def run_idl(self, txn):
self.result = [
rowview.RowView(item) for item in
self.api.tables[self.table].rows.values()
if self.lb in item.load_balancer]
class GetLrsCommand(command.ReadOnlyCommand):
def run_idl(self, txn):
self.result = [
rowview.RowView(item) for item in
self.api.tables['Logical_Router'].rows.values()]
# Retry forever to get the OVN NB and SB IDLs. Wait 2^x * 1 seconds between
# each retry, up to 'max_interval' seconds, then interval will be fixed
# to 'max_interval' seconds afterwards. The default 'max_interval' is 180.
@ -230,6 +252,12 @@ class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
except ovn_exc.RevisionConflict as e:
LOG.info('Transaction aborted. Reason: %s', e)
def find_lb_in_table(self, lb, table):
return FindLbInTableCommand(self, lb, table)
def get_lrs(self):
return GetLrsCommand(self)
def create_lswitch_port(self, lport_name, lswitch_name, may_exist=True,
**columns):
return cmd.AddLSwitchPortCommand(self, lport_name, lswitch_name,

1
networking_ovn/ovsdb/ovsdb_monitor.py

@ -424,6 +424,7 @@ class OvnIdl(BaseOvnIdl):
# but not granted by the ovsdb-server.
if self.is_lock_contended:
return
row = idlutils.frozen_row(row)
self.notify_handler.notify(event, row, updates)
@abc.abstractmethod

7
networking_ovn/tests/unit/octavia/test_ovn_driver.py

@ -1140,6 +1140,7 @@ class TestOvnProviderHelper(TestOvnOctaviaBase):
net_dr.return_value.neutron_client.delete_port.return_value = None
(self.helper.ovn_nbdb_api.ls_get.return_value.execute.
return_value) = self.network
self.helper.ovn_nbdb_api.lookup.return_value = self.router
(self.helper.ovn_nbdb_api.tables['Logical_Router'].rows.
values.return_value) = [self.router]
self.helper.lb_delete(self.ovn_lb)
@ -2369,8 +2370,8 @@ class TestOvnProviderHelper(TestOvnOctaviaBase):
ls = fakes.FakeOvsdbRow.create_one_ovsdb_row(
attrs={'ports': [lsp]})
(self.helper.ovn_nbdb_api.tables['Logical_Router'].rows.
values.return_value) = [lr]
(self.helper.ovn_nbdb_api.get_lrs.return_value.
execute.return_value) = [lr]
returned_lr = self.helper._find_lr_of_ls(ls)
self.assertEqual(lr, returned_lr)
@ -2379,7 +2380,7 @@ class TestOvnProviderHelper(TestOvnOctaviaBase):
attrs={'ports': []})
returned_lr = self.helper._find_lr_of_ls(ls)
(self.helper.ovn_nbdb_api.tables['Logical_Router'].rows.
values.assert_not_called())
values.assert_not_called())
self.assertIsNone(returned_lr)
def test__update_lb_to_ls_association_empty_network_and_subnet(self):

Loading…
Cancel
Save