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):