From b8f0aedae524539e9d0d069c07662e288046bc6f Mon Sep 17 00:00:00 2001 From: JingLu5 Date: Wed, 23 Aug 2017 02:15:13 +0000 Subject: Add common openstack opertation scenarios: volume & floating ip JIRA: YARDSTICK-781 This patch adds some common openstack opertation scenarios Change-Id: I1300a61b389202242f112b6d280ab47746379546 Signed-off-by: JingLu5 --- yardstick/common/openstack_utils.py | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'yardstick/common') diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 76acc9508..c862a6ba2 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -11,6 +11,7 @@ from __future__ import absolute_import import os import time +import sys import logging from keystoneauth1 import loading @@ -423,6 +424,15 @@ def delete_flavor(flavor_id): # pragma: no cover return True +def delete_keypair(nova_client, key): # pragma: no cover + try: + nova_client.keypairs.delete(key=key) + return True + except Exception: + log.exception("Error [delete_keypair(nova_client)]") + return False + + # ********************************************* # NEUTRON # ********************************************* @@ -479,6 +489,15 @@ def create_floating_ip(neutron_client, extnet_id): # pragma: no cover return {'fip_addr': fip_addr, 'fip_id': fip_id} +def delete_floating_ip(nova_client, floatingip_id): # pragma: no cover + try: + nova_client.floating_ips.delete(floatingip_id) + return True + except Exception: + log.error("Error [delete_floating_ip(nova_client, '%s')]" % floatingip_id) + return False + + def get_security_groups(neutron_client): # pragma: no cover try: security_groups = neutron_client.list_security_groups()[ @@ -667,3 +686,33 @@ def create_volume(cinder_client, volume_name, volume_size, log.exception("Error [create_volume(cinder_client, %s)]", (volume_name, volume_size)) return None + + +def delete_volume(cinder_client, volume_id, forced=False): # pragma: no cover + try: + if forced: + try: + cinder_client.volumes.detach(volume_id) + 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: + log.exception("Error [delete_volume(cinder_client, '%s')]" % volume_id) + return False + + +def detach_volume(server_id, volume_id): # pragma: no cover + try: + get_nova_client().volumes.delete_server_volume(server_id, volume_id) + return True + except Exception: + log.exception("Error [detach_server_volume(nova_client, '%s', '%s')]", + server_id, volume_id) + return False -- cgit 1.2.3-korg