Merge "AttachInterfacesTest: use build_timeout on iterface deletion"
diff --git a/tempest/api/compute/servers/test_attach_interfaces.py b/tempest/api/compute/servers/test_attach_interfaces.py
index 738e4a8..4dacb48 100644
--- a/tempest/api/compute/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/servers/test_attach_interfaces.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 from tempest.api.compute import base
+from tempest import exceptions
 from tempest.test import attr
 
 import time
@@ -75,15 +76,19 @@
         # NOTE(danms): delete not the first or last, but one in the middle
         iface = ifs[1]
         self.client.delete_interface(server['id'], iface['port_id'])
-        for i in range(0, 5):
-            _r, _ifs = self.client.list_interfaces(server['id'])
-            if len(ifs) != len(_ifs):
-                break
-            time.sleep(1)
+        _ifs = self.client.list_interfaces(server['id'])[1]
+        start = int(time.time())
 
-        self.assertEqual(len(_ifs), len(ifs) - 1)
-        for _iface in _ifs:
-            self.assertNotEqual(iface['port_id'], _iface['port_id'])
+        while len(ifs) == len(_ifs):
+            time.sleep(self.build_interval)
+            _ifs = self.client.list_interfaces(server['id'])[1]
+            timed_out = int(time.time()) - start >= self.build_timeout
+            if len(ifs) == len(_ifs) and timed_out:
+                message = ('Failed to delete interface within '
+                           'the required time: %s sec.' % self.build_timeout)
+                raise exceptions.TimeoutException(message)
+
+        self.assertNotIn(iface['port_id'], [i['port_id'] for i in _ifs])
         return _ifs
 
     def _compare_iface_list(self, list1, list2):
diff --git a/tempest/api/compute/v3/servers/test_attach_interfaces.py b/tempest/api/compute/v3/servers/test_attach_interfaces.py
index d05296b..8f69c54 100644
--- a/tempest/api/compute/v3/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/v3/servers/test_attach_interfaces.py
@@ -14,6 +14,7 @@
 #    under the License.
 
 from tempest.api.compute import base
+from tempest import exceptions
 from tempest.test import attr
 
 import time
@@ -75,15 +76,19 @@
         # NOTE(danms): delete not the first or last, but one in the middle
         iface = ifs[1]
         self.client.delete_interface(server['id'], iface['port_id'])
-        for i in range(0, 5):
-            _r, _ifs = self.client.list_interfaces(server['id'])
-            if len(ifs) != len(_ifs):
-                break
-            time.sleep(1)
+        _ifs = self.client.list_interfaces(server['id'])[1]
+        start = int(time.time())
 
-        self.assertEqual(len(_ifs), len(ifs) - 1)
-        for _iface in _ifs:
-            self.assertNotEqual(iface['port_id'], _iface['port_id'])
+        while len(ifs) == len(_ifs):
+            time.sleep(self.build_interval)
+            _ifs = self.client.list_interfaces(server['id'])[1]
+            timed_out = int(time.time()) - start >= self.build_timeout
+            if len(ifs) == len(_ifs) and timed_out:
+                message = ('Failed to delete interface within '
+                           'the required time: %s sec.' % self.build_timeout)
+                raise exceptions.TimeoutException(message)
+
+        self.assertNotIn(iface['port_id'], [i['port_id'] for i in _ifs])
         return _ifs
 
     def _compare_iface_list(self, list1, list2):