summaryrefslogtreecommitdiff
path: root/tempest
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-02-23 01:07:01 +0000
committerGerrit Code Review <review@openstack.org>2023-02-23 01:07:01 +0000
commitf72a8ae998fb1cdf472ac08a6231978e4e1df4e2 (patch)
treee21c01d3a9435e1cc692e616538cac70a5802500 /tempest
parent91697ff6203c21e8f5d249d2a682b16c58c816b4 (diff)
parentaeacd8c92a5d18775c3611908e5605f1e470ed4a (diff)
downloadtempest-f72a8ae998fb1cdf472ac08a6231978e4e1df4e2.tar.gz
Merge "Log console on failure to delete attachment"
Diffstat (limited to 'tempest')
-rw-r--r--tempest/api/volume/base.py3
-rw-r--r--tempest/common/waiters.py11
-rwxr-xr-xtempest/tests/common/test_waiters.py23
3 files changed, 35 insertions, 2 deletions
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index 49f9e2217..403d18e36 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -191,7 +191,8 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest,
waiters.wait_for_volume_resource_status(self.volumes_client,
volume_id, 'in-use')
self.addCleanup(waiters.wait_for_volume_resource_status,
- self.volumes_client, volume_id, 'available')
+ self.volumes_client, volume_id, 'available',
+ server_id, self.servers_client)
self.addCleanup(self.servers_client.detach_volume, server_id,
volume_id)
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py
index 45a7b8a59..c5da412d3 100644
--- a/tempest/common/waiters.py
+++ b/tempest/common/waiters.py
@@ -303,12 +303,16 @@ def wait_for_image_copied_to_stores(client, image_id):
raise lib_exc.TimeoutException(message)
-def wait_for_volume_resource_status(client, resource_id, status):
+def wait_for_volume_resource_status(client, resource_id, status,
+ server_id=None, servers_client=None):
"""Waits for a volume resource to reach a given status.
This function is a common function for volume, snapshot and backup
resources. The function extracts the name of the desired resource from
the client class name of the resource.
+
+ If server_id and servers_client are provided, dump the console for that
+ server on failure.
"""
resource_name = re.findall(
r'(volume|group-snapshot|snapshot|backup|group)',
@@ -330,6 +334,11 @@ def wait_for_volume_resource_status(client, resource_id, status):
raise exceptions.VolumeExtendErrorException(volume_id=resource_id)
if int(time.time()) - start >= client.build_timeout:
+ if server_id and servers_client:
+ console_output = servers_client.get_console_output(
+ server_id)['output']
+ LOG.debug('Console output for %s\nbody=\n%s',
+ server_id, console_output)
message = ('%s %s failed to reach %s status (current %s) '
'within the required time (%s s).' %
(resource_name, resource_id, status, resource_status,
diff --git a/tempest/tests/common/test_waiters.py b/tempest/tests/common/test_waiters.py
index 2695048b0..93c949e64 100755
--- a/tempest/tests/common/test_waiters.py
+++ b/tempest/tests/common/test_waiters.py
@@ -386,6 +386,29 @@ class TestVolumeWaiters(base.TestCase):
mock_sleep.assert_called_once_with(1)
@mock.patch.object(time, 'sleep')
+ def test_wait_for_volume_status_timeout_console(self, mock_sleep):
+ # Tests that the wait method gets the server console log if the
+ # timeout is hit.
+ client = mock.Mock(spec=volumes_client.VolumesClient,
+ resource_type="volume",
+ build_interval=1,
+ build_timeout=1)
+ servers_client = mock.Mock()
+ servers_client.get_console_output.return_value = {
+ 'output': 'console log'}
+ volume = {'volume': {'status': 'detaching'}}
+ mock_show = mock.Mock(return_value=volume)
+ client.show_volume = mock_show
+ volume_id = '7532b91e-aa0a-4e06-b3e5-20c0c5ee1caa'
+ self.assertRaises(lib_exc.TimeoutException,
+ waiters.wait_for_volume_resource_status,
+ client, volume_id, 'available',
+ server_id='someserver',
+ servers_client=servers_client)
+ servers_client.get_console_output.assert_called_once_with(
+ 'someserver')
+
+ @mock.patch.object(time, 'sleep')
def test_wait_for_volume_status_error_extending(self, mock_sleep):
# Tests that the wait method raises VolumeExtendErrorException if
# the volume status is 'error_extending'.