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
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index 0dd7c70..aaedba2 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -18,6 +18,7 @@
 
 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,11 +34,17 @@
         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)
+                        router_id, subnet_id, interface['port_id'])
         self.assertEqual(subnet_id, interface['subnet_id'])
         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,
                                                            subnet_id=subnet_id)
         self.assertEqual(subnet_id, body['subnet_id'])
@@ -107,7 +114,7 @@
         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'])
+                        router['id'], subnet['id'], interface['port_id'])
         self.assertIn('subnet_id', interface.keys())
         self.assertIn('port_id', interface.keys())
         # Verify router id is equal to device id in port details
@@ -183,9 +190,10 @@
             next_cidr = next_cidr.next()
 
             # 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,
-                            router['id'], subnet['id'])
+                            router['id'], subnet['id'], interface['port_id'])
             cidr = netaddr.IPNetwork(subnet['cidr'])
             next_hop = str(cidr[2])
             destination = str(subnet['cidr'])