diff --git a/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py b/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py index 0041c086..d0cd0a63 100644 --- a/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py +++ b/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py @@ -139,7 +139,8 @@ class OVNBGPDriver(driver_api.AgentDriverBase): "FIPUnsetEvent", "OVNLBMemberCreateDeleteEvent", "ChassisCreateEvent", - "ChassisPrivateCreateEvent"]) + "ChassisPrivateCreateEvent", + "LocalnetCreateDeleteEvent"]) if self._expose_tenant_networks: events.update(["SubnetRouterAttachedEvent", "SubnetRouterDetachedEvent", diff --git a/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py b/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py index 4c2423fb..3a367574 100644 --- a/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py +++ b/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py @@ -105,7 +105,8 @@ class OVNEVPNDriver(driver_api.AgentDriverBase): "TenantPortCreatedEvent", "TenantPortDeletedEvent", "ChassisCreateEvent", - "ChassisPrivateCreateEvent"]) + "ChassisPrivateCreateEvent", + "LocalnetCreateDeleteEvent"]) return events @lockutils.synchronized('evpn') diff --git a/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py index ac431330..be87699e 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py @@ -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 diff --git a/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py index dbd24fb2..a189e183 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py @@ -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 diff --git a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_bgp_watcher.py b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_bgp_watcher.py index fd9e168b..6f1bed14 100644 --- a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_bgp_watcher.py +++ b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_bgp_watcher.py @@ -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 diff --git a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_evpn_watcher.py b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_evpn_watcher.py index e79170c1..71b8f8c4 100644 --- a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_evpn_watcher.py +++ b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_evpn_watcher.py @@ -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