Ensure localnet port events are processed

If a new provider network is created, we need to re-sync so that
we have the needed information to expose IPs on it or through
CR-LRPs that will be associated to it

Change-Id: I822ae25f93b0a9e017f86c3f0ac4ac0010d49211
This commit is contained in:
Luis Tomas Bolivar 2023-03-15 10:44:31 +01:00
parent e0b6db65ba
commit a298010044
6 changed files with 72 additions and 2 deletions

View File

@ -139,7 +139,8 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
"FIPUnsetEvent",
"OVNLBMemberCreateDeleteEvent",
"ChassisCreateEvent",
"ChassisPrivateCreateEvent"])
"ChassisPrivateCreateEvent",
"LocalnetCreateDeleteEvent"])
if self._expose_tenant_networks:
events.update(["SubnetRouterAttachedEvent",
"SubnetRouterDetachedEvent",

View File

@ -105,7 +105,8 @@ class OVNEVPNDriver(driver_api.AgentDriverBase):
"TenantPortCreatedEvent",
"TenantPortDeletedEvent",
"ChassisCreateEvent",
"ChassisPrivateCreateEvent"])
"ChassisPrivateCreateEvent",
"LocalnetCreateDeleteEvent"])
return events
@lockutils.synchronized('evpn')

View File

@ -430,6 +430,20 @@ class OVNLBMemberCreateDeleteEvent(base_watcher.OVNLBMemberEvent):
vip_ip, vip_port.logical_port, associated_cr_lrp_port)
class LocalnetCreateDeleteEvent(base_watcher.PortBindingChassisEvent):
def __init__(self, bgp_agent):
events = (self.ROW_CREATE, self.ROW_DELETE,)
super(LocalnetCreateDeleteEvent, self).__init__(
bgp_agent, events)
def match_fn(self, event, row, old):
return row.type == constants.OVN_LOCALNET_VIF_PORT_TYPE
def run(self, event, row, old):
with _SYNC_STATE_LOCK.read_lock():
self.agent.sync()
class ChassisCreateEventBase(row_event.RowEvent):
table = None

View File

@ -201,6 +201,20 @@ class TenantPortDeletedEvent(base_watcher.PortBindingChassisEvent):
self.agent.withdraw_remote_ip(ips, row)
class LocalnetCreateDeleteEvent(base_watcher.PortBindingChassisEvent):
def __init__(self, bgp_agent):
events = (self.ROW_CREATE, self.ROW_DELETE,)
super(LocalnetCreateDeleteEvent, self).__init__(
bgp_agent, events)
def match_fn(self, event, row, old):
return row.type == constants.OVN_LOCALNET_VIF_PORT_TYPE
def run(self, event, row, old):
with _SYNC_STATE_LOCK.read_lock():
self.agent.sync()
class ChassisCreateEventBase(row_event.RowEvent):
table = None

View File

@ -964,6 +964,26 @@ class TestOVNLBMemberCreateDeleteEvent(test_base.TestCase):
self.agent.expose_ovn_lb_on_provider.assert_not_called()
class TestLocalnetCreateDeleteEvent(test_base.TestCase):
def setUp(self):
super(TestLocalnetCreateDeleteEvent, self).setUp()
self.agent = mock.Mock()
self.event = bgp_watcher.LocalnetCreateDeleteEvent(self.agent)
def test_match_fn(self):
row = utils.create_row(type=constants.OVN_LOCALNET_VIF_PORT_TYPE)
self.assertTrue(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_match_fn_not_match(self):
row = utils.create_row(type=constants.OVN_VM_VIF_PORT_TYPE)
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_run(self):
self.event.run(mock.Mock(), mock.Mock(), mock.Mock())
self.agent.sync.assert_called_once()
class TestChassisCreateEvent(test_base.TestCase):
_event = bgp_watcher.ChassisCreateEvent

View File

@ -483,6 +483,26 @@ class TestTenantPortDeletedEvent(test_base.TestCase):
self.agent.withdraw_remote_ip.assert_not_called()
class TestLocalnetCreateDeleteEvent(test_base.TestCase):
def setUp(self):
super(TestLocalnetCreateDeleteEvent, self).setUp()
self.agent = mock.Mock()
self.event = evpn_watcher.LocalnetCreateDeleteEvent(self.agent)
def test_match_fn(self):
row = utils.create_row(type=constants.OVN_LOCALNET_VIF_PORT_TYPE)
self.assertTrue(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_match_fn_not_match(self):
row = utils.create_row(type=constants.OVN_VM_VIF_PORT_TYPE)
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_run(self):
self.event.run(mock.Mock(), mock.Mock(), mock.Mock())
self.agent.sync.assert_called_once()
class TestChassisCreateEvent(test_base.TestCase):
_event = evpn_watcher.ChassisCreateEvent