Fix volume_create to use shared function with a cleanup
delete volume is taken care by self.create_volume
Change-Id: Ic4cb5dae7a7165d28df3cab97019c1756a70dfbf
diff --git a/tempest/api/volume/admin/test_volume_types.py b/tempest/api/volume/admin/test_volume_types.py
index 99f0a6b..dfb74b9 100644
--- a/tempest/api/volume/admin/test_volume_types.py
+++ b/tempest/api/volume/admin/test_volume_types.py
@@ -51,8 +51,7 @@
'size': CONF.volume.volume_size}
# Create volume
- volume = self.volumes_client.create_volume(**params)['volume']
- self.addCleanup(self.delete_volume, self.volumes_client, volume['id'])
+ volume = self.create_volume(**params)
self.assertEqual(volume_types[0]['name'], volume["volume_type"])
self.assertEqual(volume[self.name_field], vol_name,
"The created volume name is not equal "
diff --git a/tempest/api/volume/admin/v2/test_volume_type_access.py b/tempest/api/volume/admin/v2/test_volume_type_access.py
index 91ff5af..80dbf12 100644
--- a/tempest/api/volume/admin/v2/test_volume_type_access.py
+++ b/tempest/api/volume/admin/v2/test_volume_type_access.py
@@ -16,7 +16,6 @@
import operator
from tempest.api.volume import base
-from tempest.common import waiters
from tempest import config
from tempest.lib import exceptions as lib_exc
from tempest import test
@@ -52,13 +51,7 @@
project=self.volumes_client.tenant_id)
# Creating a volume from primary tenant
- volume = self.volumes_client.create_volume(
- volume_type=volume_type['id'],
- size=CONF.volume.volume_size)['volume']
- self.addCleanup(self.delete_volume, self.volumes_client, volume['id'])
- waiters.wait_for_volume_status(self.volumes_client, volume['id'],
- 'available')
-
+ volume = self.create_volume(volume_type=volume_type['id'])
# Validating the created volume is based on the volume type
self.assertEqual(volume_type['name'], volume['volume_type'])
diff --git a/tempest/api/volume/admin/v3/test_user_messages.py b/tempest/api/volume/admin/v3/test_user_messages.py
index 39a5dfa..257a434 100755
--- a/tempest/api/volume/admin/v3/test_user_messages.py
+++ b/tempest/api/volume/admin/v3/test_user_messages.py
@@ -15,9 +15,7 @@
from tempest.api.volume.v3 import base
from tempest.common.utils import data_utils
-from tempest.common import waiters
from tempest import config
-from tempest import exceptions
from tempest import test
CONF = config.CONF
@@ -47,21 +45,11 @@
'vendor_name': bad_vendor}
vol_type_name = data_utils.rand_name(
self.__class__.__name__ + '-volume-type')
- bogus_type = self.admin_volume_types_client.create_volume_type(
- name=vol_type_name,
- extra_specs=extra_specs)['volume_type']
- self.addCleanup(self.admin_volume_types_client.delete_volume_type,
- bogus_type['id'])
+ bogus_type = self.create_volume_type(
+ name=vol_type_name, extra_specs=extra_specs)
params = {'volume_type': bogus_type['id'],
'size': CONF.volume.volume_size}
- volume = self.volumes_client.create_volume(**params)['volume']
- self.addCleanup(self.delete_volume, self.volumes_client, volume['id'])
- try:
- waiters.wait_for_volume_status(self.volumes_client, volume['id'],
- 'error')
- except exceptions.VolumeBuildErrorException:
- # Error state is expected and desired
- pass
+ volume = self.create_volume(wait_until="error", **params)
messages = self.messages_client.list_messages()['messages']
message_id = None
for message in messages:
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index b9aeb99..6db3807 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -108,8 +108,11 @@
super(BaseVolumeTest, cls).resource_cleanup()
@classmethod
- def create_volume(cls, **kwargs):
- """Wrapper utility that returns a test volume."""
+ def create_volume(cls, wait_until='available', **kwargs):
+ """Wrapper utility that returns a test volume.
+
+ :param wait_until: wait till volume status.
+ """
if 'size' not in kwargs:
kwargs['size'] = CONF.volume.volume_size
@@ -120,8 +123,8 @@
volume = cls.volumes_client.create_volume(**kwargs)['volume']
cls.volumes.append(volume)
- waiters.wait_for_volume_status(cls.volumes_client,
- volume['id'], 'available')
+ waiters.wait_for_volume_status(cls.volumes_client, volume['id'],
+ wait_until)
return volume
@classmethod
diff --git a/tempest/api/volume/v3/base.py b/tempest/api/volume/v3/base.py
index e38f947..31fc1eb 100644
--- a/tempest/api/volume/v3/base.py
+++ b/tempest/api/volume/v3/base.py
@@ -52,7 +52,8 @@
self.request_microversion))
-class VolumesV3AdminTest(VolumesV3Test):
+class VolumesV3AdminTest(VolumesV3Test,
+ base.BaseVolumeAdminTest):
"""Base test case class for all v3 Volume Admin API tests."""
credentials = ['primary', 'admin']
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py
index 92bce5f..0cf8154 100644
--- a/tempest/common/waiters.py
+++ b/tempest/common/waiters.py
@@ -176,7 +176,7 @@
time.sleep(client.build_interval)
body = client.show_volume(volume_id)['volume']
volume_status = body['status']
- if volume_status == 'error':
+ if volume_status == 'error' and status != 'error':
raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
if volume_status == 'error_restoring':
raise exceptions.VolumeRestoreErrorException(volume_id=volume_id)