Ensure VM ports on tenant networks are withdraw when VM is removed

It is possible that when the VM gets removed the port remains (e.g.,
when the VM is created using an existing port). Therefore the
ROW_UPDATE event also needs to be handle for withdraw events when
exposing VMs on tenant networks

Change-Id: I0885e7b9f6d45e46e75f36b2a16a97480e62bd56
This commit is contained in:
Luis Tomas Bolivar 2022-08-29 17:33:25 +02:00
parent 275a7c9a37
commit ee0fa1f32b
2 changed files with 36 additions and 11 deletions

View File

@ -217,7 +217,7 @@ class TenantPortCreatedEvent(base_watcher.PortBindingChassisEvent):
# single and dual-stack format
if not self._check_single_dual_stack_format(row.mac[0]):
return False
return (not old.chassis and
return (not old.chassis and row.chassis and
self.agent.ovn_local_lrps != [])
except (IndexError, AttributeError):
return False
@ -236,7 +236,7 @@ class TenantPortCreatedEvent(base_watcher.PortBindingChassisEvent):
class TenantPortDeletedEvent(base_watcher.PortBindingChassisEvent):
def __init__(self, bgp_agent):
events = (self.ROW_DELETE,)
events = (self.ROW_UPDATE, self.ROW_DELETE,)
super(TenantPortDeletedEvent, self).__init__(
bgp_agent, events)
@ -245,7 +245,11 @@ class TenantPortDeletedEvent(base_watcher.PortBindingChassisEvent):
# single and dual-stack format
if not self._check_single_dual_stack_format(row.mac[0]):
return False
return (self.agent.ovn_local_lrps != [])
if event == self.ROW_UPDATE:
return (old.chassis and not row.chassis and
self.agent.ovn_local_lrps != [])
if event == self.ROW_DELETE:
return (self.agent.ovn_local_lrps != [])
except (IndexError, AttributeError):
return False

View File

@ -457,27 +457,35 @@ class TestTenantPortCreatedEvent(test_base.TestCase):
self.event = bgp_watcher.TenantPortCreatedEvent(self.agent)
def test_match_fn(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
row = utils.create_row(chassis=[mock.Mock()],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[])
self.assertTrue(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_no_chassis(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[])
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_not_single_or_dual_stack(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff'])
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_match_fn_old_chassis_set(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
row = utils.create_row(chassis=[mock.Mock()],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[mock.Mock()])
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_empty_ovn_local_lrps(self):
self.agent.ovn_local_lrps = []
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
row = utils.create_row(chassis=[mock.Mock()],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[])
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_index_error(self):
row = utils.create_row(mac=[])
row = utils.create_row(chassis=[mock.Mock()], mac=[])
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_run(self):
@ -511,17 +519,30 @@ class TestTenantPortDeletedEvent(test_base.TestCase):
self.event = bgp_watcher.TenantPortDeletedEvent(self.agent)
def test_match_fn(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
self.assertTrue(self.event.match_fn(mock.Mock(), row, mock.Mock()))
event = self.event.ROW_UPDATE
row = utils.create_row(chassis=[],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[mock.Mock()],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
self.assertTrue(self.event.match_fn(event, row, old))
def test_match_fn_delete(self):
event = self.event.ROW_DELETE
row = utils.create_row(chassis=[],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
self.assertTrue(self.event.match_fn(event, row, mock.Mock()))
def test_match_fn_not_single_or_dual_stack(self):
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff'])
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
def test_match_fn_empty_ovn_local_lrps(self):
row = utils.create_row(chassis=[],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
old = utils.create_row(chassis=[mock.Mock()],
mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
self.agent.ovn_local_lrps = []
row = utils.create_row(mac=['aa:bb:cc:dd:ee:ff 10.10.1.16'])
self.assertFalse(self.event.match_fn(mock.Mock(), row, mock.Mock()))
self.assertFalse(self.event.match_fn(mock.Mock(), row, old))
def test_match_fn_index_error(self):
row = utils.create_row(mac=[])