aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils')
-rwxr-xr-xfunctest/utils/openstack_clean.py28
-rwxr-xr-xfunctest/utils/openstack_snapshot.py22
-rw-r--r--functest/utils/openstack_utils.py24
3 files changed, 40 insertions, 34 deletions
diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py
index 0ce08798..b5167893 100755
--- a/functest/utils/openstack_clean.py
+++ b/functest/utils/openstack_clean.py
@@ -80,22 +80,25 @@ def remove_instances(nova_client, default_instances):
break
-def remove_images(nova_client, default_images):
+def remove_images(glance_client, default_images):
logger.debug("Removing Glance images...")
- images = os_utils.get_images(nova_client)
- if images is None or len(images) == 0:
+ images = os_utils.get_images(glance_client)
+ if images is None:
+ return -1
+ images = {image.id: image.name for image in images}
+ if len(images) == 0:
logger.debug("No images found.")
return
for image in images:
- image_name = getattr(image, 'name')
- image_id = getattr(image, 'id')
+ image_id = image
+ image_name = images.get(image_id)
logger.debug("'%s', ID=%s " % (image_name, image_id))
if (image_id not in default_images and
image_name not in default_images.values()):
logger.debug("Removing image '%s', ID=%s ..."
% (image_name, image_id))
- if os_utils.delete_glance_image(nova_client, image_id):
+ if os_utils.delete_glance_image(glance_client, image_id):
logger.debug(" > Done!")
else:
logger.error("There has been a problem removing the"
@@ -135,9 +138,9 @@ def remove_volumes(cinder_client, default_volumes):
"NOT be deleted.")
-def remove_floatingips(nova_client, default_floatingips):
+def remove_floatingips(neutron_client, default_floatingips):
logger.debug("Removing floating IPs...")
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == 0:
logger.debug("No floating IPs found.")
return
@@ -151,7 +154,7 @@ def remove_floatingips(nova_client, default_floatingips):
if (fip_id not in default_floatingips and
fip_ip not in default_floatingips.values()):
logger.debug("Removing floating IP %s ..." % fip_id)
- if os_utils.delete_floating_ip(nova_client, fip_id):
+ if os_utils.delete_floating_ip(neutron_client, fip_id):
logger.debug(" > Done!")
deleted += 1
else:
@@ -163,7 +166,7 @@ def remove_floatingips(nova_client, default_floatingips):
timeout = 50
while timeout > 0:
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == (init_len - deleted):
break
else:
@@ -385,6 +388,7 @@ def main():
neutron_client = os_utils.get_neutron_client()
keystone_client = os_utils.get_keystone_client()
cinder_client = os_utils.get_cinder_client()
+ glance_client = os_utils.get_glance_client()
try:
with open(OS_SNAPSHOT_FILE) as f:
@@ -411,11 +415,11 @@ def main():
remove_instances(nova_client, default_instances)
separator()
- remove_images(nova_client, default_images)
+ remove_images(glance_client, default_images)
separator()
remove_volumes(cinder_client, default_volumes)
separator()
- remove_floatingips(nova_client, default_floatingips)
+ remove_floatingips(neutron_client, default_floatingips)
separator()
remove_networks(neutron_client, default_networks, default_routers)
separator()
diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py
index 233c316a..f4ef751c 100755
--- a/functest/utils/openstack_snapshot.py
+++ b/functest/utils/openstack_snapshot.py
@@ -48,13 +48,13 @@ def get_instances(nova_client):
return {'instances': dic_instances}
-def get_images(nova_client):
+def get_images(glance_client):
logger.debug("Getting images...")
dic_images = {}
- images = os_utils.get_images(nova_client)
- if not (images is None or len(images) == 0):
- for image in images:
- dic_images.update({getattr(image, 'id'): getattr(image, 'name')})
+ images = os_utils.get_images(glance_client)
+ if images is None:
+ return -1
+ dic_images.update({image.id: image.name for image in images})
return {'images': dic_images}
@@ -98,13 +98,14 @@ def get_security_groups(neutron_client):
return {'secgroups': dic_secgroups}
-def get_floatinips(nova_client):
+def get_floatingips(neutron_client):
logger.debug("Getting Floating IPs...")
dic_floatingips = {}
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if not (floatingips is None or len(floatingips) == 0):
for floatingip in floatingips:
- dic_floatingips.update({floatingip.id: floatingip.ip})
+ dic_floatingips.update({floatingip['id']:
+ floatingip['floating_ip_address']})
return {'floatingips': dic_floatingips}
@@ -136,6 +137,7 @@ def main():
neutron_client = os_utils.get_neutron_client()
keystone_client = os_utils.get_keystone_client()
cinder_client = os_utils.get_cinder_client()
+ glance_client = os_utils.get_glance_client()
if not os_utils.check_credentials():
logger.error("Please source the openrc credentials and run the" +
@@ -144,12 +146,12 @@ def main():
snapshot = {}
snapshot.update(get_instances(nova_client))
- snapshot.update(get_images(nova_client))
+ snapshot.update(get_images(glance_client))
snapshot.update(get_volumes(cinder_client))
snapshot.update(get_networks(neutron_client))
snapshot.update(get_routers(neutron_client))
snapshot.update(get_security_groups(neutron_client))
- snapshot.update(get_floatinips(nova_client))
+ snapshot.update(get_floatingips(neutron_client))
snapshot.update(get_users(keystone_client))
snapshot.update(get_tenants(keystone_client))
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 0b9f8b8d..e7cdfc86 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -425,12 +425,12 @@ def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
return flavor_exists, flavor_id
-def get_floating_ips(nova_client):
+def get_floating_ips(neutron_client):
try:
- floating_ips = nova_client.floating_ips.list()
- return floating_ips
+ floating_ips = neutron_client.list_floatingips()
+ return floating_ips['floatingips']
except Exception as e:
- logger.error("Error [get_floating_ips(nova_client)]: %s" % e)
+ logger.error("Error [get_floating_ips(neutron_client)]: %s" % e)
return None
@@ -593,12 +593,12 @@ def delete_instance(nova_client, instance_id):
return False
-def delete_floating_ip(nova_client, floatingip_id):
+def delete_floating_ip(neutron_client, floatingip_id):
try:
- nova_client.floating_ips.delete(floatingip_id)
+ neutron_client.delete_floatingip(floatingip_id)
return True
except Exception as e:
- logger.error("Error [delete_floating_ip(nova_client, '%s')]: %s"
+ logger.error("Error [delete_floating_ip(neutron_client, '%s')]: %s"
% (floatingip_id, e))
return False
@@ -1191,9 +1191,9 @@ def delete_security_group(neutron_client, secgroup_id):
# *********************************************
# GLANCE
# *********************************************
-def get_images(nova_client):
+def get_images(glance_client):
try:
- images = nova_client.images.list()
+ images = glance_client.images.list()
return images
except Exception as e:
logger.error("Error [get_images]: %s" % e)
@@ -1257,12 +1257,12 @@ def get_or_create_image(name, path, format):
return image_exists, image_id
-def delete_glance_image(nova_client, image_id):
+def delete_glance_image(glance_client, image_id):
try:
- nova_client.images.delete(image_id)
+ glance_client.images.delete(image_id)
return True
except Exception as e:
- logger.error("Error [delete_glance_image(nova_client, '%s')]: %s"
+ logger.error("Error [delete_glance_image(glance_client, '%s')]: %s"
% (image_id, e))
return False