From 1098929a5446d5f4e535e7972fb972a371d22292 Mon Sep 17 00:00:00 2001 From: Michel Nederlof Date: Mon, 10 Jun 2024 12:18:46 +0200 Subject: [PATCH] [OVN] Fix virtual parent match for PortBindingUpdateVirtualPortsEvent As mentioned in change [1], the condition should be a `is None` as per inline comment. [1] https://review.opendev.org/c/openstack/neutron/+/896883 Related-Bug: #2038413 Change-Id: I3666cf0509747863ca2a416c8bfc065582573734 (cherry picked from commit 170d99f2d53f77d4c66e505f310fd9d8f3481149) --- .../ovn/mech_driver/ovsdb/ovsdb_monitor.py | 2 +- .../mech_driver/ovsdb/test_ovsdb_monitor.py | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py index 56b1b1923ff..81a1ca3b0d1 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py @@ -568,7 +568,7 @@ class PortBindingUpdateVirtualPortsEvent(row_event.RowEvent): # which means we need to update the host_id information return True - if getattr(old, 'options', None) is not None: + if getattr(old, 'options', None) is None: # The "old.options" dictionary is not being modified, # thus the virtual parents didn't change. return False diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py index 0bf92fc6ef9..f0c0e82e418 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py @@ -329,6 +329,65 @@ class TestPortBindingChassisUpdateEvent(base.BaseTestCase): 'type': '_fake_'})) +class TestPortBindingUpdateVirtualPortsEvent(base.BaseTestCase): + def setUp(self): + super().setUp() + self.event = ovsdb_monitor.PortBindingUpdateVirtualPortsEvent(None) + + self.pbtable = fakes.FakeOvsdbTable.create_one_ovsdb_table( + attrs={'name': 'Port_Binding'}) + self.ovsdb_row = fakes.FakeOvsdbRow.create_one_ovsdb_row + + self.row = self.ovsdb_row( + attrs={'_table': self.pbtable, + 'chassis': 'newchassis', + 'options': { + 'virtual-parents': 'uuid1,uuid2'}}) + + def test_delete_event_matches(self): + # Delete event (only type virtual). + self.assertFalse(self.event.match_fn( + self.event.ROW_DELETE, + self.ovsdb_row(attrs={'_table': self.pbtable, 'type': '_fake_'}), + None)) + self.assertTrue(self.event.match_fn( + self.event.ROW_DELETE, + self.ovsdb_row(attrs={'_table': self.pbtable, 'type': 'virtual'}), + None)) + + def test_event_no_match_no_options(self): + # Unrelated portbind change (no options in old, so no virtual parents) + self.assertFalse(self.event.match_fn( + self.event.ROW_UPDATE, self.row, + self.ovsdb_row(attrs={'_table': self.pbtable, + 'name': 'somename'}))) + + def test_event_no_match_other_options_change(self): + # Non-virtual parent change, no chassis has changed + old = self.ovsdb_row(attrs={'_table': self.pbtable, + 'options': { + 'virtual-parents': 'uuid1,uuid2', + 'other-opt': '_fake_'}}) + + self.assertFalse(self.event.match_fn(self.event.ROW_UPDATE, + self.row, old)) + + def test_event_match_chassis_change(self): + # Port binding change (chassis changed, and marked in old) + self.assertTrue(self.event.match_fn( + self.event.ROW_UPDATE, self.row, + self.ovsdb_row(attrs={'_table': self.pbtable, + 'chassis': 'fakechassis'}))) + + def test_event_match_virtual_parent_change(self): + # Virtual parent change + old = self.ovsdb_row(attrs={'_table': self.pbtable, + 'options': { + 'virtual-parents': 'uuid1,uuid3'}}) + self.assertTrue(self.event.match_fn(self.event.ROW_UPDATE, + self.row, old)) + + class TestOvnNbIdlNotifyHandler(test_mech_driver.OVNMechanismDriverTestCase): def setUp(self):