From dcbd6a9e990f6990083eed7c6ef579b074006dc7 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Wed, 31 Jul 2024 20:48:32 +0000 Subject: [PATCH] evpn: Remove Chassis events The code was a copy and paste from the bgp_watcher Change-Id: I054a13303b39567b5136497c8c1f1f8d9b848490 (cherry picked from commit 41ea5a37a59fb9ece9050e86e1f143826aa68b52) --- .../drivers/openstack/ovn_bgp_driver.py | 5 ++-- .../drivers/openstack/ovn_evpn_driver.py | 5 ++-- .../openstack/watchers/base_watcher.py | 27 +++++++++++++++++++ .../drivers/openstack/watchers/bgp_watcher.py | 27 ------------------- .../openstack/watchers/evpn_watcher.py | 27 ------------------- .../openstack/watchers/test_base_watcher.py | 26 ++++++++++++++++++ .../openstack/watchers/test_bgp_watcher.py | 26 ------------------ .../openstack/watchers/test_evpn_watcher.py | 26 ------------------ 8 files changed, 59 insertions(+), 110 deletions(-) diff --git a/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py b/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py index 2c705966..3647e699 100644 --- a/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py +++ b/ovn_bgp_agent/drivers/openstack/ovn_bgp_driver.py @@ -27,6 +27,7 @@ from ovn_bgp_agent.drivers.openstack.utils import driver_utils from ovn_bgp_agent.drivers.openstack.utils import ovn from ovn_bgp_agent.drivers.openstack.utils import ovs from ovn_bgp_agent.drivers.openstack.utils import wire as wire_utils +from ovn_bgp_agent.drivers.openstack.watchers import base_watcher from ovn_bgp_agent.drivers.openstack.watchers import bgp_watcher as watcher from ovn_bgp_agent import exceptions as agent_exc from ovn_bgp_agent.utils import helpers @@ -112,8 +113,8 @@ class OVNBGPDriver(driver_api.AgentDriverBase): watcher.FIPUnsetEvent(self), watcher.OVNLBMemberCreateEvent(self), watcher.OVNLBMemberDeleteEvent(self), - watcher.ChassisCreateEvent(self), - watcher.ChassisPrivateCreateEvent(self), + base_watcher.ChassisCreateEvent(self), + base_watcher.ChassisPrivateCreateEvent(self), watcher.LocalnetCreateDeleteEvent(self)} if self._expose_tenant_networks: events.update({watcher.SubnetRouterAttachedEvent(self), diff --git a/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py b/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py index 437840b3..49cb2aa4 100644 --- a/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py +++ b/ovn_bgp_agent/drivers/openstack/ovn_evpn_driver.py @@ -25,6 +25,7 @@ from ovn_bgp_agent.drivers import driver_api from ovn_bgp_agent.drivers.openstack.utils import frr from ovn_bgp_agent.drivers.openstack.utils import ovn from ovn_bgp_agent.drivers.openstack.utils import ovs +from ovn_bgp_agent.drivers.openstack.watchers import base_watcher from ovn_bgp_agent.drivers.openstack.watchers import evpn_watcher as \ watcher from ovn_bgp_agent.utils import helpers @@ -91,8 +92,8 @@ class OVNEVPNDriver(driver_api.AgentDriverBase): watcher.SubnetRouterDetachedEvent(self), watcher.TenantPortCreatedEvent(self), watcher.TenantPortDeletedEvent(self), - watcher.ChassisCreateEvent(self), - watcher.ChassisPrivateCreateEvent(self), + base_watcher.ChassisCreateEvent(self), + base_watcher.ChassisPrivateCreateEvent(self), watcher.LocalnetCreateDeleteEvent(self)} @lockutils.synchronized('evpn') diff --git a/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py index 8cfc4a73..6b09b8ae 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py @@ -149,3 +149,30 @@ class LRPChassisEvent(Event): 'logical_switch': self._get_network(row), 'router': row.external_ids.get(constants.OVN_LR_NAME_EXT_ID_KEY), } + + +class ChassisCreateEventBase(Event): + table = None + + def __init__(self, bgp_agent): + self.first_time = True + events = (self.ROW_CREATE,) + super().__init__( + bgp_agent, events, self.table, + (('name', '=', bgp_agent.chassis),)) + self.event_name = self.__class__.__name__ + + def _run(self, event, row, old): + if self.first_time: + self.first_time = False + else: + LOG.info("Connection to OVSDB established, doing a full sync") + self.agent.sync() + + +class ChassisCreateEvent(ChassisCreateEventBase): + table = 'Chassis' + + +class ChassisPrivateCreateEvent(ChassisCreateEventBase): + table = 'Chassis_Private' diff --git a/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py index e23c855f..aed4ed4d 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/bgp_watcher.py @@ -481,30 +481,3 @@ class LocalnetCreateDeleteEvent(base_watcher.PortBindingChassisEvent): def _run(self, event, row, old): with _SYNC_STATE_LOCK.read_lock(): self.agent.sync() - - -class ChassisCreateEventBase(base_watcher.Event): - table = None - - def __init__(self, bgp_agent): - self.first_time = True - events = (self.ROW_CREATE,) - super().__init__( - bgp_agent, events, self.table, - (('name', '=', bgp_agent.chassis),)) - self.event_name = self.__class__.__name__ - - def _run(self, event, row, old): - if self.first_time: - self.first_time = False - else: - LOG.info("Connection to OVSDB established, doing a full sync") - self.agent.sync() - - -class ChassisCreateEvent(ChassisCreateEventBase): - table = 'Chassis' - - -class ChassisPrivateCreateEvent(ChassisCreateEventBase): - table = 'Chassis_Private' diff --git a/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py index 6a089882..f1dfd1c0 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/evpn_watcher.py @@ -213,30 +213,3 @@ class LocalnetCreateDeleteEvent(base_watcher.PortBindingChassisEvent): def _run(self, event, row, old): with _SYNC_STATE_LOCK.read_lock(): self.agent.sync() - - -class ChassisCreateEventBase(base_watcher.Event): - table = None - - def __init__(self, bgp_agent): - self.first_time = True - events = (self.ROW_CREATE,) - super().__init__( - bgp_agent, events, self.table, - (('name', '=', bgp_agent.chassis),)) - self.event_name = self.__class__.__name__ - - def _run(self, event, row, old): - if self.first_time: - self.first_time = False - else: - LOG.info("Connection to OVSDB established, doing a full sync") - self.agent.sync() - - -class ChassisCreateEvent(ChassisCreateEventBase): - table = 'Chassis' - - -class ChassisPrivateCreateEvent(ChassisCreateEventBase): - table = 'Chassis_Private' diff --git a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_base_watcher.py b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_base_watcher.py index b54eea91..f8d3ba53 100644 --- a/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_base_watcher.py +++ b/ovn_bgp_agent/tests/unit/drivers/openstack/watchers/test_base_watcher.py @@ -132,3 +132,29 @@ class TestLRPChassisEvent(test_base.TestCase): self.assertEqual('test-net', self.lrp_event._get_network(row)) row = utils.create_row(external_ids={}) self.assertEqual(None, self.lrp_event._get_network(row)) + + +class TestChassisCreateEvent(test_base.TestCase): + _event = base_watcher.ChassisCreateEvent + + def setUp(self): + super(TestChassisCreateEvent, self).setUp() + self.chassis = '935f91fa-b8f8-47b9-8b1b-3a7a90ef7c26' + self.agent = mock.Mock(chassis=self.chassis) + self.event = self._event(self.agent) + + def test_run(self): + self.assertTrue(self.event.first_time) + self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) + + self.assertFalse(self.event.first_time) + self.agent.sync.assert_not_called() + + def test_run_not_first_time(self): + self.event.first_time = False + self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) + self.agent.sync.assert_called_once_with() + + +class TestChassisPrivateCreateEvent(TestChassisCreateEvent): + _event = base_watcher.ChassisPrivateCreateEvent 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 82ffaca2..b204e570 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 @@ -1060,29 +1060,3 @@ class TestLocalnetCreateDeleteEvent(test_base.TestCase): 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 - - def setUp(self): - super(TestChassisCreateEvent, self).setUp() - self.chassis = '935f91fa-b8f8-47b9-8b1b-3a7a90ef7c26' - self.agent = mock.Mock(chassis=self.chassis) - self.event = self._event(self.agent) - - def test_run(self): - self.assertTrue(self.event.first_time) - self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) - - self.assertFalse(self.event.first_time) - self.agent.sync.assert_not_called() - - def test_run_not_first_time(self): - self.event.first_time = False - self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) - self.agent.sync.assert_called_once_with() - - -class TestChassisPrivateCreateEvent(TestChassisCreateEvent): - _event = bgp_watcher.ChassisPrivateCreateEvent 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 71b8f8c4..afdc02b9 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 @@ -501,29 +501,3 @@ class TestLocalnetCreateDeleteEvent(test_base.TestCase): 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 - - def setUp(self): - super(TestChassisCreateEvent, self).setUp() - self.chassis = '935f91fa-b8f8-47b9-8b1b-3a7a90ef7c26' - self.agent = mock.Mock(chassis=self.chassis) - self.event = self._event(self.agent) - - def test_run(self): - self.assertTrue(self.event.first_time) - self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) - - self.assertFalse(self.event.first_time) - self.agent.sync.assert_not_called() - - def test_run_not_first_time(self): - self.event.first_time = False - self.event.run(mock.Mock(), mock.Mock(), mock.Mock()) - self.agent.sync.assert_called_once_with() - - -class TestChassisPrivateCreateEvent(TestChassisCreateEvent): - _event = evpn_watcher.ChassisPrivateCreateEvent