Move wait_for_server_termination from servers_client
wait_for_server_termination of compute client is just a wrapper.
So the method seems redundant and it doesn't fit as service clients.
This patch moves wait_for_server_termination to waiters module which
contains similar methods.
Partially implements blueprint consistent-service-method-names
Change-Id: Ib738ad91bb5e7344b6a342f23f867df42b833608
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index b2effc2..1ec2b56 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -129,7 +129,8 @@
for server in cls.servers:
try:
- cls.servers_client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(cls.servers_client,
+ server['id'])
except Exception:
LOG.exception('Waiting for deletion of server %s failed'
% server['id'])
@@ -150,7 +151,8 @@
except Exception as exc:
LOG.exception(exc)
cls.servers_client.delete_server(cls.server_id)
- cls.servers_client.wait_for_server_termination(cls.server_id)
+ waiters.wait_for_server_termination(cls.servers_client,
+ cls.server_id)
cls.server_id = None
raise
@@ -300,7 +302,8 @@
if server_id:
try:
cls.servers_client.delete_server(server_id)
- cls.servers_client.wait_for_server_termination(server_id)
+ waiters.wait_for_server_termination(cls.servers_client,
+ server_id)
except Exception:
LOG.exception('Failed to delete server %s' % server_id)
@@ -316,7 +319,8 @@
"""Deletes an existing server and waits for it to be gone."""
try:
cls.servers_client.delete_server(server_id)
- cls.servers_client.wait_for_server_termination(server_id)
+ waiters.wait_for_server_termination(cls.servers_client,
+ server_id)
except Exception:
LOG.exception('Failed to delete server %s' % server_id)
diff --git a/tempest/api/compute/images/test_images_negative.py b/tempest/api/compute/images/test_images_negative.py
index 84a8258..7f23730 100644
--- a/tempest/api/compute/images/test_images_negative.py
+++ b/tempest/api/compute/images/test_images_negative.py
@@ -50,7 +50,7 @@
# Delete server before trying to create server
self.servers_client.delete_server(server['id'])
- self.servers_client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.servers_client, server['id'])
# Create a new image after server is deleted
name = data_utils.rand_name('image')
meta = {'image_type': 'test'}
diff --git a/tempest/api/compute/security_groups/test_security_groups.py b/tempest/api/compute/security_groups/test_security_groups.py
index bd252b0..7fff8bf 100644
--- a/tempest/api/compute/security_groups/test_security_groups.py
+++ b/tempest/api/compute/security_groups/test_security_groups.py
@@ -123,7 +123,7 @@
# Shutdown the server and then verify we can destroy the
# security groups, since no active server instance is using them
self.servers_client.delete_server(server_id)
- self.servers_client.wait_for_server_termination(server_id)
+ waiters.wait_for_server_termination(self.servers_client, server_id)
self.client.delete_security_group(sg['id'])
self.client.delete_security_group(sg2['id'])
diff --git a/tempest/api/compute/servers/test_create_server.py b/tempest/api/compute/servers/test_create_server.py
index e62a52b..c6fb2fb 100644
--- a/tempest/api/compute/servers/test_create_server.py
+++ b/tempest/api/compute/servers/test_create_server.py
@@ -21,6 +21,7 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
from tempest.common.utils.linux import remote_client
+from tempest.common import waiters
from tempest import config
from tempest import test
@@ -178,7 +179,8 @@
# we're OK.
def cleanup_server():
self.client.delete_server(server_multi_nics['id'])
- self.client.wait_for_server_termination(server_multi_nics['id'])
+ waiters.wait_for_server_termination(self.client,
+ server_multi_nics['id'])
self.addCleanup(cleanup_server)
@@ -218,7 +220,8 @@
def cleanup_server():
self.client.delete_server(server_multi_nics['id'])
- self.client.wait_for_server_termination(server_multi_nics['id'])
+ waiters.wait_for_server_termination(self.client,
+ server_multi_nics['id'])
self.addCleanup(cleanup_server)
diff --git a/tempest/api/compute/servers/test_delete_server.py b/tempest/api/compute/servers/test_delete_server.py
index b2acd34..04b0cf2 100644
--- a/tempest/api/compute/servers/test_delete_server.py
+++ b/tempest/api/compute/servers/test_delete_server.py
@@ -38,14 +38,14 @@
# Delete a server while it's VM state is Building
server = self.create_test_server(wait_until='BUILD')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('925fdfb4-5b13-47ea-ac8a-c36ae6fddb05')
def test_delete_active_server(self):
# Delete a server while it's VM state is Active
server = self.create_test_server(wait_until='ACTIVE')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('546d368c-bb6c-4645-979a-83ed16f3a6be')
def test_delete_server_while_in_shutoff_state(self):
@@ -54,7 +54,7 @@
self.client.stop(server['id'])
waiters.wait_for_server_status(self.client, server['id'], 'SHUTOFF')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('943bd6e8-4d7a-4904-be83-7a6cc2d4213b')
@testtools.skipUnless(CONF.compute_feature_enabled.pause,
@@ -65,7 +65,7 @@
self.client.pause_server(server['id'])
waiters.wait_for_server_status(self.client, server['id'], 'PAUSED')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('1f82ebd3-8253-4f4e-b93f-de9b7df56d8b')
@testtools.skipUnless(CONF.compute_feature_enabled.suspend,
@@ -76,7 +76,7 @@
self.client.suspend_server(server['id'])
waiters.wait_for_server_status(self.client, server['id'], 'SUSPENDED')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('bb0cb402-09dd-4947-b6e5-5e7e1cfa61ad')
@testtools.skipUnless(CONF.compute_feature_enabled.shelve,
@@ -95,7 +95,7 @@
waiters.wait_for_server_status(self.client, server['id'],
'SHELVED')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('ab0c38b4-cdd8-49d3-9b92-0cb898723c01')
@testtools.skipIf(not CONF.compute_feature_enabled.resize,
@@ -107,7 +107,7 @@
waiters.wait_for_server_status(self.client, server['id'],
'VERIFY_RESIZE')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
@test.idempotent_id('d0f3f0d6-d9b6-4a32-8da4-23015dcab23c')
@test.services('volume')
@@ -128,7 +128,7 @@
volume['id'], 'in-use')
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
waiters.wait_for_volume_status(volumes_client,
volume['id'], 'available')
@@ -152,12 +152,13 @@
server = self.non_admin_client.show_server(server['id'])
self.assertEqual(server['status'], 'ERROR')
self.non_admin_client.delete_server(server['id'])
- self.servers_client.wait_for_server_termination(server['id'],
- ignore_error=True)
+ waiters.wait_for_server_termination(self.servers_client,
+ server['id'],
+ ignore_error=True)
@test.idempotent_id('73177903-6737-4f27-a60c-379e8ae8cf48')
def test_admin_delete_servers_of_others(self):
# Administrator can delete servers of others
server = self.create_test_server(wait_until='ACTIVE')
self.admin_client.delete_server(server['id'])
- self.servers_client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.servers_client, server['id'])
diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py
index def6cf5..f205ddf 100644
--- a/tempest/api/compute/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/servers/test_list_servers_negative.py
@@ -17,6 +17,7 @@
from tempest_lib import exceptions as lib_exc
from tempest.api.compute import base
+from tempest.common import waiters
from tempest import test
@@ -47,8 +48,8 @@
# be put into ERROR status on a quick spawn, then delete,
# as the compute node expects the instance local status
# to be spawning, not deleted. See LP Bug#1061167
- cls.client.wait_for_server_termination(srv['id'],
- ignore_error=True)
+ waiters.wait_for_server_termination(cls.client, srv['id'],
+ ignore_error=True)
cls.deleted_fixtures.append(srv)
@test.attr(type=['negative'])
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index fe05456..f5d99fc 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -171,7 +171,7 @@
# Rebuild and Reboot a deleted server
server = self.create_test_server()
self.client.delete_server(server['id'])
- self.client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.client, server['id'])
self.assertRaises(lib_exc.NotFound,
self.client.rebuild,
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 067c0c1..58c5ba9 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -53,7 +53,8 @@
def resource_cleanup(cls):
# Delete the test instance
cls.servers_client.delete_server(cls.server['id'])
- cls.servers_client.wait_for_server_termination(cls.server['id'])
+ waiters.wait_for_server_termination(cls.servers_client,
+ cls.server['id'])
super(VolumesV2ActionsTest, cls).resource_cleanup()
diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py
index 5203444..48f40f0 100644
--- a/tempest/api/volume/test_volumes_negative.py
+++ b/tempest/api/volume/test_volumes_negative.py
@@ -181,8 +181,8 @@
def test_attach_volumes_with_nonexistent_volume_id(self):
srv_name = data_utils.rand_name('Instance')
server = self.create_server(srv_name)
- self.addCleanup(self.servers_client.wait_for_server_termination,
- server['id'])
+ self.addCleanup(waiters.wait_for_server_termination,
+ self.servers_client, server['id'])
self.addCleanup(self.servers_client.delete_server, server['id'])
waiters.wait_for_server_status(self.servers_client, server['id'],
'ACTIVE')
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index aef42be..740363b 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -119,6 +119,7 @@
from tempest_lib import exceptions as lib_exc
import yaml
+from tempest.common import waiters
from tempest import config
from tempest.services.compute.json import flavors_client
from tempest.services.compute.json import floating_ips_client
@@ -896,8 +897,8 @@
# TODO(EmilienM): disassociate floating IP from server and release it.
client.servers.delete_server(response['id'])
- client.servers.wait_for_server_termination(response['id'],
- ignore_error=True)
+ waiters.wait_for_server_termination(client.servers, response['id'],
+ ignore_error=True)
def create_secgroups(secgroups):
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py
index 85a03cf..f24c45f 100644
--- a/tempest/common/waiters.py
+++ b/tempest/common/waiters.py
@@ -15,6 +15,7 @@
from oslo_log import log as logging
from tempest_lib.common.utils import misc as misc_utils
+from tempest_lib import exceptions as lib_exc
from tempest import config
from tempest import exceptions
@@ -96,6 +97,25 @@
old_task_state = task_state
+def wait_for_server_termination(client, server_id, ignore_error=False):
+ """Waits for server to reach termination."""
+ start_time = int(time.time())
+ while True:
+ try:
+ body = client.show_server(server_id)
+ except lib_exc.NotFound:
+ return
+
+ server_status = body['status']
+ if server_status == 'ERROR' and not ignore_error:
+ raise exceptions.BuildErrorException(server_id=server_id)
+
+ if int(time.time()) - start_time >= client.build_timeout:
+ raise exceptions.TimeoutException
+
+ time.sleep(client.build_interval)
+
+
def wait_for_image_status(client, image_id, status):
"""Waits for an image to reach a given status.
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index da4ebbe..f7e9560 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -96,10 +96,11 @@
def addCleanup_with_wait(self, waiter_callable, thing_id, thing_id_param,
cleanup_callable, cleanup_args=None,
- cleanup_kwargs=None):
+ cleanup_kwargs=None, waiter_client=None):
"""Adds wait for async resource deletion at the end of cleanups
@param waiter_callable: callable to wait for the resource to delete
+ with the following waiter_client if specified.
@param thing_id: the id of the resource to be cleaned-up
@param thing_id_param: the name of the id param in the waiter
@param cleanup_callable: method to load pass to self.addCleanup with
@@ -115,6 +116,8 @@
'waiter_callable': waiter_callable,
thing_id_param: thing_id
}
+ if waiter_client:
+ wait_dict['client'] = waiter_client
self.cleanup_waits.append(wait_dict)
def _wait_for_cleanups(self):
@@ -172,13 +175,15 @@
server = self.servers_client.create_server(name, image, flavor,
**create_kwargs)
if wait_on_delete:
- self.addCleanup(self.servers_client.wait_for_server_termination,
+ self.addCleanup(waiters.wait_for_server_termination,
+ self.servers_client,
server['id'])
self.addCleanup_with_wait(
- waiter_callable=self.servers_client.wait_for_server_termination,
+ waiter_callable=waiters.wait_for_server_termination,
thing_id=server['id'], thing_id_param='server_id',
cleanup_callable=self.delete_wrapper,
- cleanup_args=[self.servers_client.delete_server, server['id']])
+ cleanup_args=[self.servers_client.delete_server, server['id']],
+ waiter_client=self.servers_client)
if wait_on_boot:
waiters.wait_for_server_status(self.servers_client,
server_id=server['id'],
diff --git a/tempest/scenario/test_large_ops.py b/tempest/scenario/test_large_ops.py
index c44557e..4e6358e 100644
--- a/tempest/scenario/test_large_ops.py
+++ b/tempest/scenario/test_large_ops.py
@@ -109,8 +109,8 @@
for server in self.servers:
# after deleting all servers - wait for all servers to clear
# before cleanup continues
- self.addCleanupClass(self.servers_client.
- wait_for_server_termination,
+ self.addCleanupClass(waiters.wait_for_server_termination,
+ self.servers_client,
server['id'])
for server in self.servers:
self.addCleanupClass(self.servers_client.delete_server,
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index e676063..d2a44c6 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -20,6 +20,7 @@
import testtools
from tempest.common.utils import data_utils
+from tempest.common import waiters
from tempest import config
from tempest import exceptions
from tempest.scenario import manager
@@ -643,7 +644,7 @@
self.assertEqual(self.port_id, port_list[0]['id'])
# Delete the server.
self.servers_client.delete_server(server['id'])
- self.servers_client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.servers_client, server['id'])
# Assert the port still exists on the network but is unbound from
# the deleted server.
port = self.network_client.show_port(self.port_id)['port']
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index 3809831..03f80d5 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -122,7 +122,7 @@
def _delete_server(self, server):
self.servers_client.delete_server(server['id'])
- self.servers_client.wait_for_server_termination(server['id'])
+ waiters.wait_for_server_termination(self.servers_client, server['id'])
def _check_content_of_written_file(self, ssh_client, expected):
actual = self._get_content(ssh_client)
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index 1159a58..00d24dd 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -14,15 +14,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-import time
-
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib
-from tempest_lib import exceptions as lib_exc
from tempest.api_schema.response.compute.v2_1 import servers as schema
from tempest.common import service_client
-from tempest import exceptions
class ServersClient(service_client.ServiceClient):
@@ -165,24 +161,6 @@
self.validate_response(_schema, resp, body)
return service_client.ResponseBody(resp, body)
- def wait_for_server_termination(self, server_id, ignore_error=False):
- """Waits for server to reach termination."""
- start_time = int(time.time())
- while True:
- try:
- body = self.show_server(server_id)
- except lib_exc.NotFound:
- return
-
- server_status = body['status']
- if server_status == 'ERROR' and not ignore_error:
- raise exceptions.BuildErrorException(server_id=server_id)
-
- if int(time.time()) - start_time >= self.build_timeout:
- raise exceptions.TimeoutException
-
- time.sleep(self.build_interval)
-
def list_addresses(self, server_id):
"""Lists all addresses for a server."""
resp, body = self.get("servers/%s/ips" % server_id)
diff --git a/tempest/stress/actions/server_create_destroy.py b/tempest/stress/actions/server_create_destroy.py
index 9f41526..17f4bc9 100644
--- a/tempest/stress/actions/server_create_destroy.py
+++ b/tempest/stress/actions/server_create_destroy.py
@@ -37,5 +37,6 @@
self.logger.info("created %s" % server_id)
self.logger.info("deleting %s" % name)
self.manager.servers_client.delete_server(server_id)
- self.manager.servers_client.wait_for_server_termination(server_id)
+ waiters.wait_for_server_termination(self.manager.servers_client,
+ server_id)
self.logger.info("deleted %s" % server_id)
diff --git a/tempest/stress/actions/ssh_floating.py b/tempest/stress/actions/ssh_floating.py
index 09e6d88..2a7a85c 100644
--- a/tempest/stress/actions/ssh_floating.py
+++ b/tempest/stress/actions/ssh_floating.py
@@ -86,7 +86,8 @@
def _destroy_vm(self):
self.logger.info("deleting %s" % self.server_id)
self.manager.servers_client.delete_server(self.server_id)
- self.manager.servers_client.wait_for_server_termination(self.server_id)
+ waiters.wait_for_server_termination(self.manager.servers_client,
+ self.server_id)
self.logger.info("deleted %s" % self.server_id)
def _create_sec_group(self):
diff --git a/tempest/stress/actions/volume_attach_delete.py b/tempest/stress/actions/volume_attach_delete.py
index d6965c7..5f2d891 100644
--- a/tempest/stress/actions/volume_attach_delete.py
+++ b/tempest/stress/actions/volume_attach_delete.py
@@ -59,7 +59,8 @@
# Step 4: delete vm
self.logger.info("deleting vm: %s" % vm_name)
self.manager.servers_client.delete_server(server_id)
- self.manager.servers_client.wait_for_server_termination(server_id)
+ waiters.wait_for_server_termination(self.manager.servers_client,
+ server_id)
self.logger.info("deleted vm: %s" % server_id)
# Step 5: delete volume
diff --git a/tempest/stress/actions/volume_attach_verify.py b/tempest/stress/actions/volume_attach_verify.py
index c89985c..5dd06a9 100644
--- a/tempest/stress/actions/volume_attach_verify.py
+++ b/tempest/stress/actions/volume_attach_verify.py
@@ -48,7 +48,8 @@
def _destroy_vm(self):
self.logger.info("deleting server: %s" % self.server_id)
self.manager.servers_client.delete_server(self.server_id)
- self.manager.servers_client.wait_for_server_termination(self.server_id)
+ waiters.wait_for_server_termination(self.manager.servers_client,
+ self.server_id)
self.logger.info("deleted server: %s" % self.server_id)
def _create_sec_group(self):
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index b785156..2675a1c 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -17,6 +17,7 @@
from oslo_log import log as logging
from tempest import clients
+from tempest.common import waiters
LOG = logging.getLogger(__name__)
@@ -34,7 +35,8 @@
for s in body['servers']:
try:
- admin_manager.servers_client.wait_for_server_termination(s['id'])
+ waiters.wait_for_server_termination(admin_manager.servers_client,
+ s['id'])
except Exception:
pass