Clean up existing instances when not using tenant isolation
The test_list_servers_negative tests require that there are no existing
instances in the database when they run and will fail if any are found
under the primary/alternate user/tenant.
When running tempest with allow_tenant_isolation=false on a slower
system, there is a race where instances from previous tests are still
cleaning up in the background and cause test_list_servers_negative to
fail in setup.
This patch makes test_list_servers_negative block while the deleted
instances are being cleaned up in the background if running without
tenant isolation.
Closes-Bug: #1234370
Change-Id: I8519cba1fcf6ff39d69839783d07359544509db5
diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py
index 7f5ccf9..983258d 100644
--- a/tempest/api/compute/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/servers/test_list_servers_negative.py
@@ -28,6 +28,26 @@
_interface = 'json'
@classmethod
+ def _ensure_no_servers(cls, servers, username, tenant_name):
+ """
+ If there are servers and there is tenant isolation then a
+ skipException is raised to skip the test since it requires no servers
+ to already exist for the given user/tenant.
+ If there are servers and there is not tenant isolation then the test
+ blocks while the servers are being deleted.
+ """
+ if len(servers):
+ if not compute.MULTI_USER:
+ for srv in servers:
+ cls.client.wait_for_server_termination(srv['id'],
+ ignore_error=True)
+ else:
+ msg = ("User/tenant %(u)s/%(t)s already have "
+ "existing server instances. Skipping test." %
+ {'u': username, 't': tenant_name})
+ raise cls.skipException(msg)
+
+ @classmethod
def setUpClass(cls):
super(ListServersNegativeTestJSON, cls).setUpClass()
cls.client = cls.servers_client
@@ -54,26 +74,14 @@
# start of the test instead of destroying any existing
# servers.
resp, body = cls.client.list_servers()
- servers = body['servers']
- num_servers = len(servers)
- if num_servers > 0:
- username = cls.os.username
- tenant_name = cls.os.tenant_name
- msg = ("User/tenant %(u)s/%(t)s already have "
- "existing server instances. Skipping test." %
- {'u': username, 't': tenant_name})
- raise cls.skipException(msg)
+ cls._ensure_no_servers(body['servers'],
+ cls.os.username,
+ cls.os.tenant_name)
resp, body = cls.alt_client.list_servers()
- servers = body['servers']
- num_servers = len(servers)
- if num_servers > 0:
- username = cls.alt_manager.username
- tenant_name = cls.alt_manager.tenant_name
- msg = ("Alt User/tenant %(u)s/%(t)s already have "
- "existing server instances. Skipping test." %
- {'u': username, 't': tenant_name})
- raise cls.skipException(msg)
+ cls._ensure_no_servers(body['servers'],
+ cls.alt_manager.username,
+ cls.alt_manager.tenant_name)
# The following servers are created for use
# by the test methods in this class. These