Merge "NB: Consolidate common code of events to the superclass" into stable/2024.1

This commit is contained in:
Zuul 2024-11-20 11:08:13 +00:00 committed by Gerrit Code Review
commit 4331a19c24
3 changed files with 15 additions and 21 deletions

View File

@ -23,6 +23,10 @@ LOG = logging.getLogger(__name__)
class Event(row_event.RowEvent): class Event(row_event.RowEvent):
def __init__(self, agent, events, table, condition=None):
self.agent = agent
super().__init__(events, table, condition)
def run(self, *args, **kwargs): def run(self, *args, **kwargs):
try: try:
self._run(*args, **kwargs) self._run(*args, **kwargs)
@ -33,10 +37,8 @@ class Event(row_event.RowEvent):
class PortBindingChassisEvent(Event): class PortBindingChassisEvent(Event):
def __init__(self, bgp_agent, events): def __init__(self, bgp_agent, events):
self.agent = bgp_agent
table = 'Port_Binding' table = 'Port_Binding'
super(PortBindingChassisEvent, self).__init__( super().__init__(bgp_agent, events, table)
events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _check_ip_associated(self, mac): def _check_ip_associated(self, mac):
@ -45,10 +47,8 @@ class PortBindingChassisEvent(Event):
class OVNLBEvent(Event): class OVNLBEvent(Event):
def __init__(self, bgp_agent, events): def __init__(self, bgp_agent, events):
self.agent = bgp_agent
table = 'Load_Balancer' table = 'Load_Balancer'
super(OVNLBEvent, self).__init__( super().__init__(bgp_agent, events, table)
events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _get_router(self, row, key=constants.OVN_LB_LR_REF_EXT_ID_KEY): def _get_router(self, row, key=constants.OVN_LB_LR_REF_EXT_ID_KEY):
@ -87,19 +87,15 @@ class OVNLBEvent(Event):
class LogicalSwitchChassisEvent(Event): class LogicalSwitchChassisEvent(Event):
def __init__(self, bgp_agent, events): def __init__(self, bgp_agent, events):
self.agent = bgp_agent
table = 'Logical_Switch' table = 'Logical_Switch'
super(LogicalSwitchChassisEvent, self).__init__( super().__init__(bgp_agent, events, table)
events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
class LSPChassisEvent(Event): class LSPChassisEvent(Event):
def __init__(self, bgp_agent, events): def __init__(self, bgp_agent, events):
self.agent = bgp_agent
table = 'Logical_Switch_Port' table = 'Logical_Switch_Port'
super(LSPChassisEvent, self).__init__( super().__init__(bgp_agent, events, table)
events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _check_ip_associated(self, mac): def _check_ip_associated(self, mac):
@ -141,10 +137,8 @@ class LSPChassisEvent(Event):
class LRPChassisEvent(Event): class LRPChassisEvent(Event):
def __init__(self, bgp_agent, events): def __init__(self, bgp_agent, events):
self.agent = bgp_agent
table = 'Logical_Router_Port' table = 'Logical_Router_Port'
super(LRPChassisEvent, self).__init__( super().__init__(bgp_agent, events, table)
events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _get_network(self, row): def _get_network(self, row):

View File

@ -486,11 +486,11 @@ class ChassisCreateEventBase(base_watcher.Event):
table = None table = None
def __init__(self, bgp_agent): def __init__(self, bgp_agent):
self.agent = bgp_agent
self.first_time = True self.first_time = True
events = (self.ROW_CREATE,) events = (self.ROW_CREATE,)
super(ChassisCreateEventBase, self).__init__( super().__init__(
events, self.table, (('name', '=', self.agent.chassis),)) bgp_agent, events, self.table,
(('name', '=', bgp_agent.chassis),))
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _run(self, event, row, old): def _run(self, event, row, old):

View File

@ -218,11 +218,11 @@ class ChassisCreateEventBase(base_watcher.Event):
table = None table = None
def __init__(self, bgp_agent): def __init__(self, bgp_agent):
self.agent = bgp_agent
self.first_time = True self.first_time = True
events = (self.ROW_CREATE,) events = (self.ROW_CREATE,)
super(ChassisCreateEventBase, self).__init__( super().__init__(
events, self.table, (('name', '=', self.agent.chassis),)) bgp_agent, events, self.table,
(('name', '=', bgp_agent.chassis),))
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
def _run(self, event, row, old): def _run(self, event, row, old):