From f2aa158d4b8d49cb3ae2532b9b8ed49a1a93b564 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 27 Nov 2024 09:56:05 +0000 Subject: [PATCH] Wait for the router port activation before deletion Same as in [1], it is needed to use the same active wait for the testcases in ``RoutersNegativeTest``. This patch moves the router interface deletion method to a common place. [1]https://review.opendev.org/c/openstack/tempest/+/931765 Related-Bug: #2083287 Change-Id: I224d885b6f56f9a1bc7a317995993be242feba23 --- tempest/api/network/base.py | 14 +++++++++++ tempest/api/network/test_routers.py | 26 ++++++-------------- tempest/api/network/test_routers_negative.py | 14 ++++++----- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py index 99742ccd3d..5bbd50e5c4 100644 --- a/tempest/api/network/base.py +++ b/tempest/api/network/base.py @@ -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): diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py index aaedba20c4..fedf2f446e 100644 --- a/tempest/api/network/test_routers.py +++ b/tempest/api/network/test_routers.py @@ -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']) diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py index 50ba9774a9..299e0e9baa 100644 --- a/tempest/api/network/test_routers_negative.py +++ b/tempest/api/network/test_routers_negative.py @@ -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'])