Move common _delete_volume cleanup method in base compute test class
The test_volumes_get and test_volumes_list v2 compute tests were doing
similar volume cleanup. This patch moves that code into the base class
so other tests that need to do volume cleanup, i.e. test_server_rescue,
can use it.
Related-Bug: #1254772
Change-Id: I59f4d638f8ab6e95736c78a384607ca89f1dcb67
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 5539894..5e42919 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -227,6 +227,18 @@
cls.password = server['adminPass']
return server['id']
+ @classmethod
+ def delete_volume(cls, volume_id):
+ """Deletes the given volume and waits for it to be gone."""
+ try:
+ resp, _ = cls.volumes_extensions_client.delete_volume(volume_id)
+ # TODO(mriedem): We should move the wait_for_resource_deletion
+ # into the delete_volume method as a convenience to the caller.
+ cls.volumes_extensions_client.wait_for_resource_deletion(volume_id)
+ except exceptions.NotFound:
+ LOG.warn("Unable to delete volume '%s' since it was not found. "
+ "Maybe it was already deleted?" % volume_id)
+
class BaseV2ComputeAdminTest(BaseV2ComputeTest):
"""Base test case class for Compute Admin V2 API tests."""
diff --git a/tempest/api/compute/volumes/test_volumes_get.py b/tempest/api/compute/volumes/test_volumes_get.py
index b5a4802..b30f2f4 100644
--- a/tempest/api/compute/volumes/test_volumes_get.py
+++ b/tempest/api/compute/volumes/test_volumes_get.py
@@ -41,7 +41,7 @@
resp, volume = self.client.create_volume(size=1,
display_name=v_name,
metadata=metadata)
- self.addCleanup(self._delete_volume, volume)
+ self.addCleanup(self.delete_volume, volume['id'])
self.assertEqual(200, resp.status)
self.assertIn('id', volume)
self.assertIn('displayName', volume)
@@ -69,16 +69,6 @@
'The fetched Volume metadata misses data '
'from the created Volume')
- def _delete_volume(self, volume):
- # Delete the Volume created in this method
- try:
- resp, _ = self.client.delete_volume(volume['id'])
- self.assertEqual(202, resp.status)
- # Checking if the deleted Volume still exists
- self.client.wait_for_resource_deletion(volume['id'])
- except KeyError:
- return
-
class VolumesGetTestXML(VolumesGetTestJSON):
_interface = "xml"
diff --git a/tempest/api/compute/volumes/test_volumes_list.py b/tempest/api/compute/volumes/test_volumes_list.py
index ac89f99..7ce6216 100644
--- a/tempest/api/compute/volumes/test_volumes_list.py
+++ b/tempest/api/compute/volumes/test_volumes_list.py
@@ -59,7 +59,7 @@
# too small. So, here, we clean up whatever we did manage
# to create and raise a SkipTest
for volume in cls.volume_list:
- cls.client.delete_volume(volume)
+ cls.delete_volume(volume['id'])
msg = ("Failed to create ALL necessary volumes to run "
"test. This typically means that the backing file "
"size of the nova-volumes group is too small to "
@@ -71,8 +71,7 @@
def tearDownClass(cls):
# Delete the created Volumes
for volume in cls.volume_list:
- resp, _ = cls.client.delete_volume(volume['id'])
- cls.client.wait_for_resource_deletion(volume['id'])
+ cls.delete_volume(volume['id'])
super(VolumesTestJSON, cls).tearDownClass()
@attr(type='gate')