aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorShobhi Jain <shobhi.jain@intel.com>2018-04-06 14:44:33 +0100
committerEmma Foley <emma.l.foley@intel.com>2018-06-27 17:19:16 +0100
commit952b7604129474fc080ef2fbbbe1150ffe7775c6 (patch)
treea2ebc79e11b994a401330e3b6b7cfea919f92628 /yardstick/common
parentcfccf4a09a8c692702f44763b7597d4c236116f3 (diff)
Replace cinder create volume with shade client.
Adds get_volume function. Function create volume now uses shade client. JIRA: YARDSTICK-891 Change-Id: I0b2fae5f2cf52eaf2e4a0062c858d49bc4ce9ccd Signed-off-by: Shobhi Jain <shobhi.jain@intel.com> (cherry picked from commit 2d33d0f289f3dd3864fe57289e953b876f362c06)
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/exceptions.py4
-rw-r--r--yardstick/common/openstack_utils.py45
2 files changed, 35 insertions, 14 deletions
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index fdf21468c..c6bae444e 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -246,6 +246,10 @@ class ScenarioGetFlavorError(YardstickException):
message = 'Nova Get Falvor Scenario failed'
+class ScenarioCreateVolumeError(YardstickException):
+ message = 'Cinder Create Volume Scenario failed'
+
+
class ApiServerError(YardstickException):
message = 'An unkown exception happened to Api Server!'
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index 14c34e2b4..1c4ad77e5 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -773,21 +773,38 @@ def get_volume_id(shade_client, volume_name):
return shade_client.get_volume_id(volume_name)
-def create_volume(cinder_client, volume_name, volume_size,
- volume_image=False): # pragma: no cover
+def get_volume(shade_client, name_or_id, filters=None):
+ """Get a volume by name or ID.
+
+ :param name_or_id: Name or ID of the volume.
+ :param filters: A dictionary of meta data to use for further filtering.
+
+ :returns: A volume ``munch.Munch`` or None if no matching volume is found.
+ """
+ return shade_client.get_volume(name_or_id, filters=filters)
+
+
+def create_volume(shade_client, size, wait=True, timeout=None,
+ image=None, **kwargs):
+ """Create a volume.
+
+ :param size: Size, in GB of the volume to create.
+ :param name: (optional) Name for the volume.
+ :param description: (optional) Name for the volume.
+ :param wait: If true, waits for volume to be created.
+ :param timeout: Seconds to wait for volume creation. None is forever.
+ :param image: (optional) Image name, ID or object from which to create
+ the volume.
+
+ :returns: The created volume object.
+
+ """
try:
- if volume_image:
- volume = cinder_client.volumes.create(name=volume_name,
- size=volume_size,
- imageRef=volume_image)
- else:
- volume = cinder_client.volumes.create(name=volume_name,
- size=volume_size)
- return volume
- except Exception: # pylint: disable=broad-except
- log.exception("Error [create_volume(cinder_client, %s)]",
- (volume_name, volume_size))
- return None
+ return shade_client.create_volume(size, wait=wait, timeout=timeout,
+ image=image, **kwargs)
+ except (exc.OpenStackCloudException, exc.OpenStackCloudTimeout) as op_exc:
+ log.error("Failed to create_volume(shade_client). "
+ "Exception message: %s", op_exc.orig_message)
def delete_volume(cinder_client, volume_id,