From 2a6e4aef0a725ddc31bd993d5a1f78185b39a4d3 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Mon, 5 Aug 2024 19:16:46 +0000 Subject: [PATCH] Move _get_ips_info out of LRP event The method was made function to be able to use it in more generic manner. Change-Id: I33a24f6942a4e2b1c12c9bdaf80d88757795f24b Signed-off-by: Jakub Libosvar (cherry picked from commit bf7c7460753f3f87d5c3714d559516faa6c91e44) --- ovn_bgp_agent/drivers/openstack/utils/port.py | 11 +++++++++++ .../drivers/openstack/watchers/base_watcher.py | 11 ----------- .../drivers/openstack/watchers/nb_bgp_watcher.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ovn_bgp_agent/drivers/openstack/utils/port.py b/ovn_bgp_agent/drivers/openstack/utils/port.py index b65a8748..6b4f7bc1 100644 --- a/ovn_bgp_agent/drivers/openstack/utils/port.py +++ b/ovn_bgp_agent/drivers/openstack/utils/port.py @@ -41,3 +41,14 @@ def make_lsp_dict(row): 'logical_switch': common.get_from_external_ids( row, constants.OVN_LS_NAME_EXT_ID_KEY), } + + +def make_lrp_dict(row): + return { + 'mac': row.mac, + 'cidrs': row.networks, + 'type': constants.OVN_CR_LRP_PORT_TYPE, + 'logical_switch': common.get_from_external_ids( + row, constants.OVN_LS_NAME_EXT_ID_KEY), + 'router': row.external_ids.get(constants.OVN_LR_NAME_EXT_ID_KEY), + } diff --git a/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py index a9038e2c..9badc7df 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/base_watcher.py @@ -16,7 +16,6 @@ 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.utils import common as common_utils from ovn_bgp_agent.drivers.openstack.utils import driver_utils @@ -74,16 +73,6 @@ class LRPChassisEvent(Event): super().__init__(bgp_agent, events, table) self.event_name = self.__class__.__name__ - def _get_ips_info(self, row): - return { - 'mac': row.mac, - 'cidrs': row.networks, - 'type': constants.OVN_CR_LRP_PORT_TYPE, - 'logical_switch': common_utils.get_from_external_ids( - row, constants.OVN_LS_NAME_EXT_ID_KEY), - 'router': row.external_ids.get(constants.OVN_LR_NAME_EXT_ID_KEY), - } - class ChassisCreateEventBase(Event): table = None diff --git a/ovn_bgp_agent/drivers/openstack/watchers/nb_bgp_watcher.py b/ovn_bgp_agent/drivers/openstack/watchers/nb_bgp_watcher.py index c307609f..ae32a11f 100644 --- a/ovn_bgp_agent/drivers/openstack/watchers/nb_bgp_watcher.py +++ b/ovn_bgp_agent/drivers/openstack/watchers/nb_bgp_watcher.py @@ -402,7 +402,7 @@ class ChassisRedirectCreateEvent(base_watcher.LRPChassisEvent): def _run(self, event, row, old): with _SYNC_STATE_LOCK.read_lock(): - ips_info = self._get_ips_info(row) + ips_info = port_utils.make_lrp_dict(row) ips = [net.split("/")[0] for net in row.networks] self.agent.expose_ip(ips, ips_info) @@ -436,7 +436,7 @@ class ChassisRedirectDeleteEvent(base_watcher.LRPChassisEvent): def _run(self, event, row, old): with _SYNC_STATE_LOCK.read_lock(): - ips_info = self._get_ips_info(row) + ips_info = port_utils.make_lrp_dict(row) ips = [net.split("/")[0] for net in row.networks] self.agent.withdraw_ip(ips, ips_info)