Fix AttachInterfacesTest error
This commit fixes some issues in AttachInterfacesTest.
* There is a problem to get the return value, TypeError is
occurring.
* Assign the JSON or XML to _interface, but it is not specified
in the method.
* Add a process to wait until the "ACTIVE" status.
Because the status is "DOWN" when a interface is created.
Fixes bug 1164894
Change-Id: I71ec9e46eb15e70f870b7a833d5433fa351c42eb
diff --git a/tempest/services/compute/json/interfaces_client.py b/tempest/services/compute/json/interfaces_client.py
index 468a5c2..06e6476 100644
--- a/tempest/services/compute/json/interfaces_client.py
+++ b/tempest/services/compute/json/interfaces_client.py
@@ -14,8 +14,10 @@
# under the License.
import json
+import time
from tempest.common.rest_client import RestClient
+from tempest import exceptions
class InterfacesClientJSON(RestClient):
@@ -55,3 +57,24 @@
resp, body = self.delete('servers/%s/os-interface/%s' % (server,
port_id))
return resp, body
+
+ def wait_for_interface_status(self, server, port_id, status):
+ """Waits for a interface to reach a given status."""
+ resp, body = self.show_interface(server, port_id)
+ interface_status = body['port_state']
+ start = int(time.time())
+
+ while(interface_status != status):
+ time.sleep(self.build_interval)
+ resp, body = self.show_interface(server, port_id)
+ interface_status = body['port_state']
+
+ timed_out = int(time.time()) - start >= self.build_timeout
+
+ if interface_status != status and timed_out:
+ message = ('Interface %s failed to reach %s status within '
+ 'the required time (%s s).' %
+ (port_id, status, self.build_timeout))
+ raise exceptions.TimeoutException(message)
+
+ return resp, body
diff --git a/tempest/services/compute/xml/interfaces_client.py b/tempest/services/compute/xml/interfaces_client.py
index 4a692a1..a84e0bd 100644
--- a/tempest/services/compute/xml/interfaces_client.py
+++ b/tempest/services/compute/xml/interfaces_client.py
@@ -13,9 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+import time
+
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
@@ -80,3 +83,23 @@
resp, body = self.delete('servers/%s/os-interface/%s' % (server,
port_id))
return resp, body
+
+ def wait_for_interface_status(self, server, port_id, status):
+ """Waits for a interface to reach a given status."""
+ resp, body = self.show_interface(server, port_id)
+ interface_status = body['port_state']
+ start = int(time.time())
+
+ while(interface_status != status):
+ time.sleep(self.build_interval)
+ resp, body = self.show_interface(server, port_id)
+ interface_status = body['port_state']
+
+ timed_out = int(time.time()) - start >= self.build_timeout
+
+ if interface_status != status and timed_out:
+ message = ('Interface %s failed to reach %s status within '
+ 'the required time (%s s).' %
+ (port_id, status, self.build_timeout))
+ raise exceptions.TimeoutException(message)
+ return resp, body
diff --git a/tempest/tests/compute/servers/test_attach_interfaces.py b/tempest/tests/compute/servers/test_attach_interfaces.py
index 47c0575..5e447c4 100644
--- a/tempest/tests/compute/servers/test_attach_interfaces.py
+++ b/tempest/tests/compute/servers/test_attach_interfaces.py
@@ -25,7 +25,7 @@
@classmethod
def setUpClass(cls):
super(AttachInterfacesTestJSON, cls).setUpClass()
- os = clients.Manager()
+ os = clients.Manager(interface=cls._interface)
if not os.config.network.quantum_available:
raise cls.skipException("Quantum is required")
cls.client = os.interfaces_client
@@ -41,13 +41,18 @@
self.assertEqual(iface['fixed_ips'][0]['ip_address'], fixed_ip)
def _create_server_get_interfaces(self):
- server = self.create_server()
+ resp, server = self.create_server()
self.os.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
resp, ifs = self.client.list_interfaces(server['id'])
+ resp, body = self.client.wait_for_interface_status(
+ server['id'], ifs[0]['port_id'], 'ACTIVE')
+ ifs[0]['port_state'] = body['port_state']
return server, ifs
def _test_create_interface(self, server):
resp, iface = self.client.create_interface(server['id'])
+ resp, iface = self.client.wait_for_interface_status(
+ server['id'], iface['port_id'], 'ACTIVE')
self._check_interface(iface)
return iface
@@ -55,6 +60,8 @@
network_id = ifs[0]['net_id']
resp, iface = self.client.create_interface(server['id'],
network_id=network_id)
+ resp, iface = self.client.wait_for_interface_status(
+ server['id'], iface['port_id'], 'ACTIVE')
self._check_interface(iface, network_id=network_id)
return iface