Cleanup: Add common "create volume" method
In scenario tests, there are some "create volume" methods and their
behaviors are almost the same. They create a volume with random name,
size 1GB and wait for volume status "available".
So this patch adds a common "create_volume" method and uses the method
instead of each implementation for code-cleanup.
Change-Id: I06f29a77116fd617f47b0ae6916de933ebb7fdc3
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 277eae4..ccfba83 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -317,6 +317,22 @@
LOG.debug("Created server: %s", server)
return server
+ def create_volume(self, client=None, size=1, name=None,
+ snapshot_id=None, imageRef=None):
+ if client is None:
+ client = self.volume_client
+ if name is None:
+ name = rand_name('scenario-volume-')
+ LOG.debug("Creating a volume (size :%s, name: %s)", size, name)
+ volume = client.volumes.create(size=size, display_name=name,
+ snapshot_id=snapshot_id,
+ imageRef=imageRef)
+ self.set_resource(name, volume)
+ self.assertEqual(name, volume.display_name)
+ self.status_timeout(client.volumes, volume.id, 'available')
+ LOG.debug("Created volume: %s", volume)
+ return volume
+
def create_keypair(self, client=None, name=None):
if client is None:
client = self.compute_client
diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py
index 277adba..25735e9 100644
--- a/tempest/scenario/test_minimum_basic.py
+++ b/tempest/scenario/test_minimum_basic.py
@@ -102,15 +102,7 @@
self.assertEqual(self.server, got_server)
def cinder_create(self):
- name = rand_name('scenario-volume-')
- LOG.debug("volume display-name:%s" % name)
- self.volume = self.volume_client.volumes.create(size=1,
- display_name=name)
- LOG.debug("volume created:%s" % self.volume.display_name)
- self._wait_for_volume_status('available')
-
- self.addCleanup(self.volume_client.volumes.delete, self.volume)
- self.assertEqual(name, self.volume.display_name)
+ self.volume = self.create_volume()
def cinder_list(self):
volumes = self.volume_client.volumes.list()
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 0c58dea..8864b2f 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -132,20 +132,7 @@
self.volume_client.volumes, volume.id, status)
def _create_volume(self, snapshot_id=None):
- name = rand_name('scenario-volume-')
- LOG.debug("volume display-name:%s" % name)
- volume = self.volume_client.volumes.create(size=1,
- display_name=name,
- snapshot_id=snapshot_id)
- LOG.debug("volume created:%s" % volume.display_name)
-
- def cleaner():
- self._wait_for_volume_status(volume, 'available')
- self.volume_client.volumes.delete(volume)
- self.addCleanup(cleaner)
- self._wait_for_volume_status(volume, 'available')
- self.assertEqual(name, volume.display_name)
- return volume
+ return self.create_volume(snapshot_id=snapshot_id)
def _attach_volume(self, server, volume):
attach_volume_client = self.compute_client.volumes.create_server_volume
diff --git a/tempest/scenario/test_volume_snapshot_pattern.py b/tempest/scenario/test_volume_snapshot_pattern.py
index 95a30ed..8fa177e 100644
--- a/tempest/scenario/test_volume_snapshot_pattern.py
+++ b/tempest/scenario/test_volume_snapshot_pattern.py
@@ -34,14 +34,7 @@
def _create_volume_from_image(self):
img_uuid = self.config.compute.image_ref
vol_name = rand_name('volume-origin')
- vol = self.volume_client.volumes.create(size=1,
- display_name=vol_name,
- imageRef=img_uuid)
- self.set_resource(vol.id, vol)
- self.status_timeout(self.volume_client.volumes,
- vol.id,
- 'available')
- return vol
+ return self.create_volume(name=vol_name, imageRef=img_uuid)
def _boot_instance_from_volume(self, vol_id):
# NOTE(gfidente): the syntax for block_device_mapping is
@@ -71,14 +64,7 @@
def _create_volume_from_snapshot(self, snap_id):
vol_name = rand_name('volume')
- vol = self.volume_client.volumes.create(size=1,
- display_name=vol_name,
- snapshot_id=snap_id)
- self.set_resource(vol.id, vol)
- self.status_timeout(self.volume_client.volumes,
- vol.id,
- 'available')
- return vol
+ return self.create_volume(name=vol_name, snapshot_id=snap_id)
def _stop_instances(self, instances):
# NOTE(gfidente): two loops so we do not wait for the status twice