From 0ea2c01d757375d54aa9a9de34c2c9995bb48d13 Mon Sep 17 00:00:00 2001 From: zhufl Date: Mon, 3 Jun 2019 15:37:13 +0800 Subject: [PATCH] Break wait_for_volume_resource_status when error_extending When extending volume reaches status error_extending, we should return from wait_for_volume_resource_status immediately instead of waiting for the TimeoutException. Change-Id: I3db0325c23ebb8d42fe77f4c28552fe9cf5ed807 --- tempest/common/waiters.py | 2 ++ tempest/exceptions.py | 5 +++++ tempest/tests/common/test_waiters.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) mode change 100644 => 100755 tempest/common/waiters.py mode change 100644 => 100755 tempest/exceptions.py mode change 100644 => 100755 tempest/tests/common/test_waiters.py diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py old mode 100644 new mode 100755 index 77ec0f8da2..e1b8cf5e17 --- a/tempest/common/waiters.py +++ b/tempest/common/waiters.py @@ -202,6 +202,8 @@ def wait_for_volume_resource_status(client, resource_id, status): resource_name=resource_name, resource_id=resource_id) if resource_name == 'volume' and resource_status == 'error_restoring': raise exceptions.VolumeRestoreErrorException(volume_id=resource_id) + if resource_status == 'error_extending' and resource_status != status: + raise exceptions.VolumeExtendErrorException(volume_id=resource_id) if int(time.time()) - start >= client.build_timeout: message = ('%s %s failed to reach %s status (current %s) ' diff --git a/tempest/exceptions.py b/tempest/exceptions.py old mode 100644 new mode 100755 index a430d5d76e..c05e7a6b96 --- a/tempest/exceptions.py +++ b/tempest/exceptions.py @@ -42,6 +42,11 @@ class VolumeRestoreErrorException(exceptions.TempestException): message = "Volume %(volume_id)s failed to restore and is in ERROR status" +class VolumeExtendErrorException(exceptions.TempestException): + message = ("Volume %(volume_id)s failed to extend and " + "is in error_extending status") + + class StackBuildErrorException(exceptions.TempestException): message = ("Stack %(stack_identifier)s is in %(stack_status)s status " "due to '%(stack_status_reason)s'") diff --git a/tempest/tests/common/test_waiters.py b/tempest/tests/common/test_waiters.py old mode 100644 new mode 100755 index d56e8a43dd..02e1c99437 --- a/tempest/tests/common/test_waiters.py +++ b/tempest/tests/common/test_waiters.py @@ -73,6 +73,25 @@ class TestImageWaiters(base.TestCase): mock.call(volume_id)]) mock_sleep.assert_called_once_with(1) + @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'. + client = mock.Mock(spec=volumes_client.VolumesClient, + resource_type="volume", + build_interval=1) + volume1 = {'volume': {'status': 'extending'}} + volume2 = {'volume': {'status': 'error_extending'}} + mock_show = mock.Mock(side_effect=(volume1, volume2)) + client.show_volume = mock_show + volume_id = '7532b91e-aa0a-4e06-b3e5-20c0c5ee1caa' + self.assertRaises(exceptions.VolumeExtendErrorException, + waiters.wait_for_volume_resource_status, + client, volume_id, 'available') + mock_show.assert_has_calls([mock.call(volume_id), + mock.call(volume_id)]) + mock_sleep.assert_called_once_with(1) + class TestInterfaceWaiters(base.TestCase):