From 8a3973cddb07f0095d32d8e8cc97fe712c79750b Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 2 Oct 2013 13:15:25 -0700 Subject: [PATCH] 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 --- .../servers/test_list_servers_negative.py | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py index 7f5ccf92bb..983258d483 100644 --- a/tempest/api/compute/servers/test_list_servers_negative.py +++ b/tempest/api/compute/servers/test_list_servers_negative.py @@ -27,6 +27,26 @@ from tempest.test import attr class ListServersNegativeTestJSON(base.BaseComputeTest): _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() @@ -54,26 +74,14 @@ class ListServersNegativeTestJSON(base.BaseComputeTest): # 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