Improve OVNLBMemberCreateDeleteEvent watching event
Minimize the number of SB calls to be made for certain events Change-Id: I08b4b22565bc90750736849c3a7a6d3049009dd2
This commit is contained in:
parent
d9c7de6465
commit
ddb740e2e4
@ -13,13 +13,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from ovsdbapp.backend.ovs_idl import event as row_event
|
||||
|
||||
from ovn_bgp_agent import constants
|
||||
from ovn_bgp_agent.drivers.openstack.watchers import base_watcher
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
_SYNC_STATE_LOCK = lockutils.ReaderWriterLock()
|
||||
|
||||
@ -369,6 +371,8 @@ class OVNLBMemberCreateDeleteEvent(base_watcher.OVNLBMemberEvent):
|
||||
# loadbalancer has the VIP on a provider network
|
||||
# Also, the cr-lrp port needs to have subnet datapaths (LS) associated
|
||||
# to it that include the load balancer
|
||||
if not self.agent.ovn_local_cr_lrps:
|
||||
return
|
||||
try:
|
||||
row_dp = row.datapaths
|
||||
except AttributeError:
|
||||
@ -389,6 +393,19 @@ class OVNLBMemberCreateDeleteEvent(base_watcher.OVNLBMemberEvent):
|
||||
if not vip_port:
|
||||
return
|
||||
associated_cr_lrp_port = None
|
||||
|
||||
router_dps = []
|
||||
if not (CONF.expose_tenant_networks or
|
||||
CONF.expose_ipv6_gua_tenant_networks):
|
||||
# assume all the members are connected through the same router
|
||||
# so only one member needs to be checked
|
||||
member_dp = row_dp[0]
|
||||
# get lrps on that dp (patch ports)
|
||||
router_lrps = (
|
||||
self.agent.sb_idl.get_lrps_for_datapath(member_dp))
|
||||
for lrp in router_lrps:
|
||||
router_dps.append(self.agent.sb_idl.get_port_datapath(lrp))
|
||||
|
||||
for cr_lrp_port, cr_lrp_info in self.agent.ovn_local_cr_lrps.items():
|
||||
if vip_port.datapath != cr_lrp_info.get('provider_datapath'):
|
||||
continue
|
||||
@ -398,20 +415,9 @@ class OVNLBMemberCreateDeleteEvent(base_watcher.OVNLBMemberEvent):
|
||||
associated_cr_lrp_port = cr_lrp_port
|
||||
break
|
||||
else:
|
||||
# assume all the members are connected through the same router
|
||||
# so only one member needs to be checked
|
||||
member_dp = row_dp[0]
|
||||
# get lrps on that dp (patch ports)
|
||||
router_lrps = (
|
||||
self.agent.sb_idl.get_lrps_for_datapath(member_dp))
|
||||
for lrp in router_lrps:
|
||||
router_dp = self.agent.sb_idl.get_port_datapath(lrp)
|
||||
if router_dp == cr_lrp_info.get('router_datapath'):
|
||||
associated_cr_lrp_port = cr_lrp_port
|
||||
break
|
||||
if associated_cr_lrp_port:
|
||||
if cr_lrp_info.get('router_datapath') in router_dps:
|
||||
associated_cr_lrp_port = cr_lrp_port
|
||||
break
|
||||
|
||||
else:
|
||||
return
|
||||
|
||||
|
@ -15,11 +15,15 @@
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from ovn_bgp_agent import constants
|
||||
from ovn_bgp_agent.drivers.openstack.watchers import bgp_watcher
|
||||
from ovn_bgp_agent.tests import base as test_base
|
||||
from ovn_bgp_agent.tests import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestPortBindingChassisCreatedEvent(test_base.TestCase):
|
||||
|
||||
@ -863,12 +867,16 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
|
||||
logical_port='ovn-lb-port-1',
|
||||
external_ids={constants.OVN_CIDRS_EXT_ID_KEY: '172.24.100.66/26'})
|
||||
self.agent.sb_idl.get_ovn_vip_port.return_value = vip_port
|
||||
self.agent.sb_idl.get_lrps_for_datapath.return_value = ['fake-lrp']
|
||||
self.agent.sb_idl.get_port_datapath.return_value = 'r_dp'
|
||||
self.event.run(self.event.ROW_CREATE, row, mock.Mock())
|
||||
self.agent.expose_ovn_lb_on_provider.assert_called_once_with(
|
||||
'172.24.100.66', 'ovn-lb-port-1', 'cr-lrp1')
|
||||
self.agent.withdraw_ovn_lb_on_provider.assert_not_called()
|
||||
|
||||
def test_run_no_subnets_datapath(self):
|
||||
CONF.set_override('expose_tenant_networks', False)
|
||||
self.addCleanup(CONF.clear_override, 'expose_tenant_networks')
|
||||
dpg1 = utils.create_row(_uuid='fake_dp_group',
|
||||
datapaths=['s_dp1'])
|
||||
row = utils.create_row(name='ovn-lb1',
|
||||
@ -912,6 +920,8 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
|
||||
datapath='dp2',
|
||||
logical_port='ovn-lb-port-1',
|
||||
external_ids={constants.OVN_CIDRS_EXT_ID_KEY: '172.24.100.66/26'})
|
||||
self.agent.sb_idl.get_lrps_for_datapath.return_value = ['fake-lrp']
|
||||
self.agent.sb_idl.get_port_datapath.return_value = 'dp2'
|
||||
self.agent.sb_idl.get_ovn_vip_port.return_value = vip_port
|
||||
self.event.run(self.event.ROW_CREATE, row, mock.Mock())
|
||||
self.agent.expose_ovn_lb_on_provider.assert_not_called()
|
||||
@ -927,6 +937,8 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
|
||||
datapath='dp1',
|
||||
logical_port='ovn-lb-port-1',
|
||||
external_ids={constants.OVN_CIDRS_EXT_ID_KEY: '172.24.100.66/26'})
|
||||
self.agent.sb_idl.get_lrps_for_datapath.return_value = ['fake-lrp']
|
||||
self.agent.sb_idl.get_port_datapath.return_value = 'r_dp'
|
||||
self.agent.sb_idl.get_ovn_vip_port.return_value = vip_port
|
||||
self.event.run(self.event.ROW_CREATE, row, mock.Mock())
|
||||
self.agent.expose_ovn_lb_on_provider.assert_not_called()
|
||||
@ -942,6 +954,8 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
|
||||
datapath='dp1',
|
||||
logical_port='port-1',
|
||||
external_ids={})
|
||||
self.agent.sb_idl.get_lrps_for_datapath.return_value = ['fake-lrp']
|
||||
self.agent.sb_idl.get_port_datapath.return_value = 'r_dp'
|
||||
self.agent.sb_idl.get_ovn_vip_port.return_value = vip_port
|
||||
self.event.run(self.event.ROW_CREATE, row, mock.Mock())
|
||||
self.agent.expose_ovn_lb_on_provider.assert_not_called()
|
||||
@ -957,6 +971,8 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
|
||||
datapath='dp1',
|
||||
logical_port='ovn-lb-port-1',
|
||||
external_ids={constants.OVN_CIDRS_EXT_ID_KEY: '172.24.100.66/26'})
|
||||
self.agent.sb_idl.get_lrps_for_datapath.return_value = ['fake-lrp']
|
||||
self.agent.sb_idl.get_port_datapath.return_value = 'r_dp'
|
||||
self.agent.sb_idl.get_ovn_vip_port.return_value = vip_port
|
||||
self.event.run(self.event.ROW_DELETE, row, mock.Mock())
|
||||
self.agent.withdraw_ovn_lb_on_provider.assert_called_once_with(
|
||||
|
Loading…
Reference in New Issue
Block a user