From 1cb371327f63b9889ad8858b0820515040895870 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Thu, 18 May 2023 17:15:15 -0700 Subject: [PATCH] CI: Try to isolate test failures in neutron vif logic One of our tests is super-friendly to race because it relies on changing an object, but that object not being saved yet to verify the difference. However, that object and even similar changes can occur in the database and trigger the test to fail. So instead using the shared resource created on test startup, create an isolated, dedicated resource for it to use inside of the test, which should eliminate the entire issue. I hope. Change-Id: Ia0df1c211d5510777c6055f1341335f9bc5c5006 --- .../drivers/modules/network/test_common.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ironic/tests/unit/drivers/modules/network/test_common.py b/ironic/tests/unit/drivers/modules/network/test_common.py index e58fcaa205..b81fcd6dcc 100644 --- a/ironic/tests/unit/drivers/modules/network/test_common.py +++ b/ironic/tests/unit/drivers/modules/network/test_common.py @@ -1089,17 +1089,26 @@ class TestNeutronVifPortIDMixin(db_base.DbTestCase): @mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.update_port_dhcp_opts', autospec=True) def test_port_changed_client_id_fail(self, dhcp_update_mock): - self.port.internal_info = {'tenant_vif_port_id': 'fake-id'} - self.port.extra = {'client-id': 'fake3'} + port = obj_utils.create_test_port( + self.context, + id=1119, + uuid=uuidutils.generate_uuid(), + node_id=self.node.id, + address='51:51:00:cf:2d:33', + internal_info={'tenant_vif_port_id': uuidutils.generate_uuid()}, + extra={'client-id': 'fake1'}) + + port.internal_info = {'tenant_vif_port_id': 'fake-id'} + port.extra = {'client-id': 'fake3'} what_changed_mock = mock.Mock() what_changed_mock.return_value = ['extra'] - self.port.obj_what_changed = what_changed_mock + port.obj_what_changed = what_changed_mock dhcp_update_mock.side_effect = ( - exception.FailedToUpdateDHCPOptOnPort(port_id=self.port.uuid)) + exception.FailedToUpdateDHCPOptOnPort(port_id=port.uuid)) with task_manager.acquire(self.context, self.node.id) as task: self.assertRaises(exception.FailedToUpdateDHCPOptOnPort, self.interface.port_changed, - task, self.port) + task, port) self.assertEqual(2, what_changed_mock.call_count) @mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.update_port_dhcp_opts',