From 4c672aa7012a530806a2f8ff2d45a8badb7f7b21 Mon Sep 17 00:00:00 2001 From: Shobhi Jain Date: Tue, 10 Apr 2018 14:13:50 +0100 Subject: Replace cinder delete volume with shade client. Function delete volume now uses shade client. JIRA: YARDSTICK-891 Change-Id: I016e1d3bf5972879cad176b56c7282e35413945e Signed-off-by: Shobhi Jain --- yardstick/common/openstack_utils.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'yardstick/common/openstack_utils.py') diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 026ec620f..3909bcb2e 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -10,7 +10,6 @@ import copy import logging import os -import sys from cinderclient import client as cinderclient from novaclient import client as novaclient @@ -822,24 +821,21 @@ def create_volume(shade_client, size, wait=True, timeout=None, "Exception message: %s", op_exc.orig_message) -def delete_volume(cinder_client, volume_id, - forced=False): # pragma: no cover +def delete_volume(shade_client, name_or_id=None, wait=True, timeout=None): + """Delete a volume. + + :param name_or_id:(string) Name or unique ID of the volume. + :param wait:(bool) If true, waits for volume to be deleted. + :param timeout:(string) Seconds to wait for volume deletion. None is forever. + + :return: True on success, False otherwise. + """ try: - if forced: - try: - cinder_client.volumes.detach(volume_id) - except Exception: # pylint: disable=broad-except - log.error(sys.exc_info()[0]) - cinder_client.volumes.force_delete(volume_id) - else: - while True: - volume = get_cinder_client().volumes.get(volume_id) - if volume.status.lower() == 'available': - break - cinder_client.volumes.delete(volume_id) - return True - except Exception: # pylint: disable=broad-except - log.exception("Error [delete_volume(cinder_client, '%s')]", volume_id) + return shade_client.delete_volume(name_or_id=name_or_id, + wait=wait, timeout=timeout) + except (exc.OpenStackCloudException, exc.OpenStackCloudTimeout) as o_exc: + log.error("Error [delete_volume(shade_client,'%s')]. " + "Exception message: %s", name_or_id, o_exc.orig_message) return False -- cgit 1.2.3-korg