From 5296d0c01c4ca390f1690f6206b5fd9acc7bd0b4 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 30 Sep 2026 11:35:57 +0200 Subject: [PATCH] ut: Use random physnets in VLAN allocation deletion ``test_delete_physical_networks_keeps_allocated`` asserted on the full ``VlanAllocation`` table using fixed ``physnet1``/``physnet2`` names, which could collide with rows left by other tests on the shared unit test database. Closes-Bug: #2168942 Assisted-By: Composer 2.5 Signed-off-by: Rodolfo Alonso Hernandez Change-Id: I112bc4923d4a0d35cbdcdaf0aa4c9051257c4e3e --- .../objects/plugins/ml2/test_vlanallocation.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/neutron/tests/unit/objects/plugins/ml2/test_vlanallocation.py b/neutron/tests/unit/objects/plugins/ml2/test_vlanallocation.py index ff3d1320cd5..b83be003009 100644 --- a/neutron/tests/unit/objects/plugins/ml2/test_vlanallocation.py +++ b/neutron/tests/unit/objects/plugins/ml2/test_vlanallocation.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.utils import helpers + from neutron.objects.plugins.ml2 import vlanallocation from neutron.tests.unit.objects.plugins.ml2 import test_base as ml2_test_base from neutron.tests.unit.objects import test_base @@ -30,20 +32,23 @@ class VlanAllocationDbObjTestCase( _test_class = vlanallocation.VlanAllocation def test_delete_physical_networks_keeps_allocated(self): + physnet_purged = helpers.get_random_string(16) + physnet_other = helpers.get_random_string(16) for vlan_id, allocated in ((100, False), (101, True)): vlanallocation.VlanAllocation( - self.context, physical_network='physnet1', vlan_id=vlan_id, + self.context, physical_network=physnet_purged, vlan_id=vlan_id, allocated=allocated).create() vlanallocation.VlanAllocation( - self.context, physical_network='physnet2', vlan_id=100, + self.context, physical_network=physnet_other, vlan_id=100, allocated=False).create() vlanallocation.VlanAllocation.delete_physical_networks( - self.context, ['physnet1']) + self.context, [physnet_purged]) remaining = {(alloc.physical_network, alloc.vlan_id) for alloc in vlanallocation.VlanAllocation.get_objects( self.context)} - # the unallocated physnet1 register is gone, the allocated one is - # kept, and other physical networks are untouched - self.assertEqual({('physnet1', 101), ('physnet2', 100)}, remaining) + # the unallocated register on the purged physnet is gone, the + # allocated one is kept, and other physical networks are untouched + self.assertEqual( + {(physnet_purged, 101), (physnet_other, 100)}, remaining)