[NB watcher] Prevent lsp events for remote tenant events

Added check in LSP events to see if the event would belong to a network
that is exposed remotely (e.g. tenant networks behind router)

Change-Id: Idcc7880fc877f0a876c65bb1877ec4f89c2af5aa
This commit is contained in:
Michel Nederlof 2024-03-08 14:48:27 +00:00
parent dcfffb0d98
commit 8f3351072c
2 changed files with 34 additions and 0 deletions

View File

@ -55,6 +55,11 @@ class LogicalSwitchPortProviderCreateEvent(base_watcher.LSPChassisEvent):
current_chassis, _ = self._get_chassis(row)
logical_switch = self._get_network(row)
if logical_switch in self.agent.ovn_local_lrps:
# This is a tenant network, routed through lrp, handled by
# event LogicalSwitchPortTenantCreateEvent
return False
# Check for rejection criteria
if (current_chassis != self.agent.chassis or
not bool(row.up[0]) or
@ -101,6 +106,11 @@ class LogicalSwitchPortProviderDeleteEvent(base_watcher.LSPChassisEvent):
ips = row.addresses[0].split(' ')[1:]
logical_switch = self._get_network(row)
if logical_switch in self.agent.ovn_local_lrps:
# This is a tenant network, routed through lrp, handled by
# event LogicalSwitchPortTenantDeleteEvent
return False
# Do nothing if we do not expose the current port
if not self.agent.is_ip_exposed(logical_switch, ips):
return False

View File

@ -27,6 +27,8 @@ class TestLogicalSwitchPortProviderCreateEvent(test_base.TestCase):
super(TestLogicalSwitchPortProviderCreateEvent, self).setUp()
self.chassis = 'fake-chassis'
self.agent = mock.Mock(chassis=self.chassis)
self.agent.ovn_local_lrps = {
'net1': ['10.0.0.5']}
# Assume the logical switch has been setup properly.
self.agent.is_ls_provider.return_value = True
@ -91,6 +93,16 @@ class TestLogicalSwitchPortProviderCreateEvent(test_base.TestCase):
old = utils.create_row(options={}, up=[True])
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_tenant_create(self):
row = utils.create_row(
type=constants.OVN_VM_VIF_PORT_TYPE,
addresses=['mac 192.168.0.1'],
options={'requested-chassis': self.chassis},
external_ids={constants.OVN_LS_NAME_EXT_ID_KEY: 'net1'},
up=[True])
old = utils.create_row(options={}, up=[True])
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_additional_bindings(self):
event = self.event.ROW_UPDATE
bindings = ','.join([self.chassis, 'other-chassis'])
@ -133,6 +145,8 @@ class TestLogicalSwitchPortProviderDeleteEvent(test_base.TestCase):
super(TestLogicalSwitchPortProviderDeleteEvent, self).setUp()
self.chassis = 'fake-chassis'
self.agent = mock.Mock(chassis=self.chassis)
self.agent.ovn_local_lrps = {
'net1': ['10.0.0.5']}
# Assume the logical switch has been setup properly.
self.agent.is_ls_provider.return_value = True
@ -224,6 +238,16 @@ class TestLogicalSwitchPortProviderDeleteEvent(test_base.TestCase):
old = utils.create_row(options={'requested-chassis': 'other_chassis'})
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_tenant_delete(self):
event = self.event.ROW_DELETE
row = utils.create_row(
type=constants.OVN_VM_VIF_PORT_TYPE,
addresses=['mac 192.168.0.1'],
options={'requested-chassis': self.chassis},
external_ids={constants.OVN_LS_NAME_EXT_ID_KEY: 'net1'},
up=[True])
self.assertFalse(self.event.match_fn(event, row, mock.Mock()))
def test_match_fn_wrong_type(self):
row = utils.create_row(
type=constants.OVN_CHASSISREDIRECT_VIF_PORT_TYPE,