Merge "Wait for the router port activation before deletion"

This commit is contained in:
Zuul 2024-12-30 21:28:34 +00:00 committed by Gerrit Code Review
commit b23e9fcc28
3 changed files with 30 additions and 24 deletions

View File

@ -15,6 +15,8 @@
import netaddr
from tempest.common import utils as common_utils
from tempest.common import waiters
from tempest import config
from tempest import exceptions
from tempest.lib.common.utils import data_utils
@ -226,6 +228,18 @@ class BaseNetworkTest(tempest.test.BaseTestCase):
subnet_id=i['fixed_ips'][0]['subnet_id'])
cls.routers_client.delete_router(router['id'])
def remove_router_interface(self, router_id, port_id, subnet_id=None):
# 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 common_utils.is_extension_enabled('dvr', 'network'):
waiters.wait_for_port_status(client=self.ports_client,
port_id=port_id, status='ACTIVE')
if subnet_id:
kwargs = {'subnet_id': subnet_id}
else:
kwargs = {'port_id': port_id}
self.routers_client.remove_router_interface(router_id, **kwargs)
class BaseAdminNetworkTest(BaseNetworkTest):

View File

@ -18,7 +18,6 @@ import testtools
from tempest.api.network import base
from tempest.common import utils
from tempest.common import waiters
from tempest import config
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
@ -33,22 +32,11 @@ class RoutersTest(base.BaseNetworkTest):
def _add_router_interface_with_subnet_id(self, router_id, subnet_id):
interface = self.routers_client.add_router_interface(
router_id, subnet_id=subnet_id)
self.addCleanup(self._remove_router_interface_with_subnet_id,
router_id, subnet_id, interface['port_id'])
self.addCleanup(self.remove_router_interface,
router_id, interface['port_id'], subnet_id=subnet_id)
self.assertEqual(subnet_id, interface['subnet_id'])
return interface
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,
subnet_id=subnet_id)
self.assertEqual(subnet_id, body['subnet_id'])
@classmethod
def skip_checks(cls):
super(RoutersTest, cls).skip_checks()
@ -113,8 +101,9 @@ class RoutersTest(base.BaseNetworkTest):
# Add router interface with subnet id
interface = self.routers_client.add_router_interface(
router['id'], subnet_id=subnet['id'])
self.addCleanup(self._remove_router_interface_with_subnet_id,
router['id'], subnet['id'], interface['port_id'])
self.addCleanup(self.remove_router_interface,
router['id'], interface['port_id'],
subnet_id=subnet['id'])
self.assertIn('subnet_id', interface.keys())
self.assertIn('port_id', interface.keys())
# Verify router id is equal to device id in port details
@ -192,8 +181,9 @@ class RoutersTest(base.BaseNetworkTest):
# Add router interface with subnet id
interface = self.create_router_interface(router['id'],
subnet['id'])
self.addCleanup(self._remove_router_interface_with_subnet_id,
router['id'], subnet['id'], interface['port_id'])
self.addCleanup(self.remove_router_interface,
router['id'], interface['port_id'],
subnet_id=subnet['id'])
cidr = netaddr.IPNetwork(subnet['cidr'])
next_hop = str(cidr[2])
destination = str(subnet['cidr'])

View File

@ -77,8 +77,9 @@ class RoutersNegativeTest(base.BaseNetworkTest):
subnet02 = self.create_subnet(network02)
interface = self.routers_client.add_router_interface(
self.router['id'], subnet_id=subnet01['id'])
self.addCleanup(self.routers_client.remove_router_interface,
self.router['id'], subnet_id=subnet01['id'])
self.addCleanup(self.remove_router_interface,
self.router['id'], interface['port_id'],
subnet_id=subnet01['id'])
self.assertEqual(subnet01['id'], interface['subnet_id'])
self.assertRaises(lib_exc.BadRequest,
self.routers_client.add_router_interface,
@ -89,10 +90,11 @@ class RoutersNegativeTest(base.BaseNetworkTest):
@decorators.idempotent_id('04df80f9-224d-47f5-837a-bf23e33d1c20')
def test_router_remove_interface_in_use_returns_409(self):
"""Test removing in-use interface from router"""
self.routers_client.add_router_interface(self.router['id'],
subnet_id=self.subnet['id'])
self.addCleanup(self.routers_client.remove_router_interface,
self.router['id'], subnet_id=self.subnet['id'])
interface = self.routers_client.add_router_interface(
self.router['id'], subnet_id=self.subnet['id'])
self.addCleanup(self.remove_router_interface,
self.router['id'], interface['port_id'],
subnet_id=self.subnet['id'])
self.assertRaises(lib_exc.Conflict,
self.routers_client.delete_router,
self.router['id'])