Merge wait_for_volume_status to common method
Both volumes_extensions_client and volumes_client contain the method
wait_for_volume_status, and the code is the same.
So this patch merges them into a common method.
Partially implements blueprint consistent-service-method-names
Change-Id: I1b4871922de32fcba3aeee7270b2c727f2d0e98a
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py
index bdbd6bc..85a03cf 100644
--- a/tempest/common/waiters.py
+++ b/tempest/common/waiters.py
@@ -132,6 +132,27 @@
raise exceptions.TimeoutException(message)
+def wait_for_volume_status(client, volume_id, status):
+ """Waits for a Volume to reach a given status."""
+ body = client.show_volume(volume_id)
+ volume_status = body['status']
+ start = int(time.time())
+
+ while volume_status != status:
+ time.sleep(client.build_interval)
+ body = client.show_volume(volume_id)
+ volume_status = body['status']
+ if volume_status == 'error':
+ raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
+
+ if int(time.time()) - start >= client.build_timeout:
+ message = ('Volume %s failed to reach %s status (current %s) '
+ 'within the required time (%s s).' %
+ (volume_id, status, volume_status,
+ client.build_timeout))
+ raise exceptions.TimeoutException(message)
+
+
def wait_for_bm_node_status(client, node_id, attr, status):
"""Waits for a baremetal node attribute to reach given status.
diff --git a/tempest/services/compute/json/volumes_extensions_client.py b/tempest/services/compute/json/volumes_extensions_client.py
index 08bb4bc..985038d 100644
--- a/tempest/services/compute/json/volumes_extensions_client.py
+++ b/tempest/services/compute/json/volumes_extensions_client.py
@@ -14,14 +14,13 @@
# under the License.
import json
-import time
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 volumes as schema
from tempest.common import service_client
-from tempest import exceptions
+from tempest.common import waiters
class VolumesExtensionsClient(service_client.ServiceClient):
@@ -83,23 +82,7 @@
def wait_for_volume_status(self, volume_id, status):
"""Waits for a Volume to reach a given status."""
- body = self.show_volume(volume_id)
- volume_status = body['status']
- start = int(time.time())
-
- while volume_status != status:
- time.sleep(self.build_interval)
- body = self.show_volume(volume_id)
- volume_status = body['status']
- if volume_status == 'error':
- raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
-
- if int(time.time()) - start >= self.build_timeout:
- message = ('Volume %s failed to reach %s status (current %s) '
- 'within the required time (%s s).' %
- (volume_id, status, volume_status,
- self.build_timeout))
- raise exceptions.TimeoutException(message)
+ waiters.wait_for_volume_status(self, volume_id, status)
def is_resource_deleted(self, id):
try:
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index 1f8548e..466e225 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -14,13 +14,12 @@
# under the License.
import json
-import time
from six.moves.urllib import parse as urllib
from tempest_lib import exceptions as lib_exc
from tempest.common import service_client
-from tempest import exceptions
+from tempest.common import waiters
class BaseVolumesClient(service_client.ServiceClient):
@@ -161,25 +160,7 @@
def wait_for_volume_status(self, volume_id, status):
"""Waits for a Volume to reach a given status."""
- body = self.show_volume(volume_id)
- volume_status = body['status']
- start = int(time.time())
-
- while volume_status != status:
- time.sleep(self.build_interval)
- body = self.show_volume(volume_id)
- volume_status = body['status']
- if volume_status == 'error':
- raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
-
- if int(time.time()) - start >= self.build_timeout:
- message = ('Volume %s failed to reach %s status (current: %s) '
- 'within the required time '
- '(%s s).' % (volume_id,
- status,
- volume_status,
- self.build_timeout))
- raise exceptions.TimeoutException(message)
+ waiters.wait_for_volume_status(self, volume_id, status)
def is_resource_deleted(self, id):
try: