Wait for the router port activation before deletion

The cleanup method ``_remove_router_interface_with_subnet_id`` should
wait for the router interface (port) activation before trying to delete
it. That will prevent a race condition between the deletion and the
port update.

Closes-Bug: #2083287
Change-Id: Id9029eb5a0558e74c62248fa08689aa1adee961a
This commit is contained in:
Rodolfo Alonso Hernandez 2024-10-08 10:53:38 +00:00 committed by Rodolfo Alonso
parent 868ee068ee
commit 6ad37f2b29

View File

@ -18,6 +18,7 @@ import testtools
from tempest.api.network import base from tempest.api.network import base
from tempest.common import utils from tempest.common import utils
from tempest.common import waiters
from tempest import config from tempest import config
from tempest.lib.common.utils import data_utils from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils from tempest.lib.common.utils import test_utils
@ -33,11 +34,17 @@ class RoutersTest(base.BaseNetworkTest):
interface = self.routers_client.add_router_interface( interface = self.routers_client.add_router_interface(
router_id, subnet_id=subnet_id) router_id, subnet_id=subnet_id)
self.addCleanup(self._remove_router_interface_with_subnet_id, self.addCleanup(self._remove_router_interface_with_subnet_id,
router_id, subnet_id) router_id, subnet_id, interface['port_id'])
self.assertEqual(subnet_id, interface['subnet_id']) self.assertEqual(subnet_id, interface['subnet_id'])
return interface return interface
def _remove_router_interface_with_subnet_id(self, router_id, subnet_id): def _remove_router_interface_with_subnet_id(self, router_id, subnet_id,
port_id):
# NOTE: with DVR and without a VM port, it is not possible to know
# what agent will host the router interface thus won't be bound.
if not utils.is_extension_enabled('dvr', 'network'):
waiters.wait_for_port_status(client=self.ports_client,
port_id=port_id, status='ACTIVE')
body = self.routers_client.remove_router_interface(router_id, body = self.routers_client.remove_router_interface(router_id,
subnet_id=subnet_id) subnet_id=subnet_id)
self.assertEqual(subnet_id, body['subnet_id']) self.assertEqual(subnet_id, body['subnet_id'])
@ -107,7 +114,7 @@ class RoutersTest(base.BaseNetworkTest):
interface = self.routers_client.add_router_interface( interface = self.routers_client.add_router_interface(
router['id'], subnet_id=subnet['id']) router['id'], subnet_id=subnet['id'])
self.addCleanup(self._remove_router_interface_with_subnet_id, self.addCleanup(self._remove_router_interface_with_subnet_id,
router['id'], subnet['id']) router['id'], subnet['id'], interface['port_id'])
self.assertIn('subnet_id', interface.keys()) self.assertIn('subnet_id', interface.keys())
self.assertIn('port_id', interface.keys()) self.assertIn('port_id', interface.keys())
# Verify router id is equal to device id in port details # Verify router id is equal to device id in port details
@ -183,9 +190,10 @@ class RoutersTest(base.BaseNetworkTest):
next_cidr = next_cidr.next() next_cidr = next_cidr.next()
# Add router interface with subnet id # Add router interface with subnet id
self.create_router_interface(router['id'], subnet['id']) interface = self.create_router_interface(router['id'],
subnet['id'])
self.addCleanup(self._remove_router_interface_with_subnet_id, self.addCleanup(self._remove_router_interface_with_subnet_id,
router['id'], subnet['id']) router['id'], subnet['id'], interface['port_id'])
cidr = netaddr.IPNetwork(subnet['cidr']) cidr = netaddr.IPNetwork(subnet['cidr'])
next_hop = str(cidr[2]) next_hop = str(cidr[2])
destination = str(subnet['cidr']) destination = str(subnet['cidr'])