aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common/openstack_utils.py
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2017-08-23 02:15:13 +0000
committerJingLu5 <lvjing5@huawei.com>2017-08-23 03:02:08 +0000
commitb8f0aedae524539e9d0d069c07662e288046bc6f (patch)
tree4e785eb15a79d942e6f493db222e9b20e31cde12 /yardstick/common/openstack_utils.py
parentb39fe5457e846e734e980666bc209fb7c07a6bdc (diff)
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 <lvjing5@huawei.com>
Diffstat (limited to 'yardstick/common/openstack_utils.py')
-rw-r--r--yardstick/common/openstack_utils.py49
1 files changed, 49 insertions, 0 deletions
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